diff --git a/calendar/inc/class.calendar_bo.inc.php b/calendar/inc/class.calendar_bo.inc.php index e289685a1d..cfe6626d28 100644 --- a/calendar/inc/class.calendar_bo.inc.php +++ b/calendar/inc/class.calendar_bo.inc.php @@ -731,15 +731,16 @@ class calendar_bo * * @param string $app * @param string $part + * @param boole $try_load=false true: load if not yet loaded * @return array */ - static function integration_get_data($app,$part=null) + static function integration_get_data($app, $part=null, $try_load=false) { static $integration_data=null; if (!isset($integration_data)) { - $integration_data = calendar_so::get_integration_data(); + $integration_data = calendar_so::get_integration_data($try_load); } if (!isset($integration_data[$app])) return null; @@ -747,6 +748,25 @@ class calendar_bo return $part ? $integration_data[$app][$part] : $integration_data[$app]; } + /** + * Check if an integration event is deletable + * + * @param string $app + * @param array $event + * @return bool + */ + static function integration_deletable($app, array $event) + { + $app_data = self::integration_get_data($app,'deletable'); + + if (empty($app_data) || is_bool($app_data)) + { + return (bool)$app_data; + } + + return (bool)(is_callable($app_data) ? $app_data($event) : ExecMethod2($app_data, $event)); + } + /** * Get private attribute for an integration event * diff --git a/calendar/inc/class.calendar_so.inc.php b/calendar/inc/class.calendar_so.inc.php index ded116502b..787d2d2824 100644 --- a/calendar/inc/class.calendar_so.inc.php +++ b/calendar/inc/class.calendar_so.inc.php @@ -1244,10 +1244,16 @@ class calendar_so /** * Get data from last 'calendar_search_union' hook call * - * @return array + * @param boole $try_load=false true: load if not yet loaded + * @return ?array */ - public static function get_integration_data() + public static function get_integration_data($try_load=false) { + if (!isset(self::$integration_data) && $try_load) + { + $selects = []; + self::get_union_selects($selects, 0, 0, [$GLOBALS['egw_info']['user']['account_id']], 0, [], '', [$GLOBALS['egw_info']['user']['account_id']]); + } return self::$integration_data; } diff --git a/calendar/inc/class.calendar_ui.inc.php b/calendar/inc/class.calendar_ui.inc.php index 44ed9d7552..a545d8a247 100644 --- a/calendar/inc/class.calendar_ui.inc.php +++ b/calendar/inc/class.calendar_ui.inc.php @@ -731,13 +731,12 @@ class calendar_ui static $sent_groups = array(); - if (!$this->bo->check_perms(Acl::EDIT,$event)) + if (!is_numeric($event['id']) || !$this->bo->check_perms(Acl::EDIT,$event)) { $event['class'] .= 'rowNoEdit '; } - // Delete disabled for other applications - if (!$this->bo->check_perms(Acl::DELETE,$event) || !is_numeric($event['id'])) + if (is_numeric($event['id']) && !$this->bo->check_perms(Acl::DELETE, $event)) { $event['class'] .= 'rowNoDelete '; } @@ -772,6 +771,11 @@ class calendar_ui } $event['app'] = $app; $event['app_id'] = $app_id; + // check if integration-app allows/supports delete + if (!calendar_bo::integration_deletable($app, $event)) + { + $event['class'] .= 'rowNoDelete'; + } } else { diff --git a/calendar/inc/class.calendar_uiforms.inc.php b/calendar/inc/class.calendar_uiforms.inc.php index bb7544195d..6d186cbe93 100644 --- a/calendar/inc/class.calendar_uiforms.inc.php +++ b/calendar/inc/class.calendar_uiforms.inc.php @@ -3261,9 +3261,22 @@ class calendar_uiforms extends calendar_ui */ public function ajax_delete($eventId) { - list($id, $date) = explode(':',$eventId); - $event=$this->bo->read($id); $response = Api\Json\Response::get(); + list($id, $date) = explode(':',$eventId); + // let integration take care of delete for integration-events + if (!is_numeric($id) && preg_match('/^([^\d]+)(\d+)$/', $id, $matches) && + !empty($app_data = calendar_bo::integration_get_data($matches[1], 'delete', true))) + { + try { + $msg = is_callable($app_data) ? $app_data($matches[2]) : ExecMethod2($app_data, $matches[2]); + $response->call('egw.refresh', $msg, 'calendar', $eventId, 'delete'); + } + catch (\Exception $e) { + $response->apply('egw.message', $e->getMessage(), 'error'); + } + return; + } + $event=$this->bo->read($id); if ($this->bo->delete($event['id'], (int)$date)) {