From d42db71fa48948408070edfe9c24eecc43f11eac Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Wed, 7 Sep 2016 09:51:08 -0400 Subject: [PATCH] T1479: Fix delegation context selection on delegator's invitation handling --- plugins/calendar/calendar.php | 27 ++++++-------- plugins/kolab_delegation/kolab_delegation.js | 2 ++ plugins/kolab_delegation/kolab_delegation.php | 17 --------- .../kolab_delegation_engine.php | 35 +------------------ plugins/libkolab/lib/kolab_storage.php | 2 ++ 5 files changed, 16 insertions(+), 67 deletions(-) diff --git a/plugins/calendar/calendar.php b/plugins/calendar/calendar.php index 9a7230ce..87a4ebeb 100644 --- a/plugins/calendar/calendar.php +++ b/plugins/calendar/calendar.php @@ -269,11 +269,15 @@ class calendar extends rcube_plugin /** * Get properties of the calendar this user has specified as default */ - public function get_default_calendar($sensitivity = null) + public function get_default_calendar($sensitivity = null, $calendars = null) { + if ($calendars === null) { + $calendars = $this->driver->list_calendars(calendar_driver::FILTER_PERSONAL | calendar_driver::FILTER_WRITEABLE); + } + $default_id = $this->rc->config->get('calendar_default_calendar'); - $calendars = $this->driver->list_calendars(calendar_driver::FILTER_PERSONAL | calendar_driver::FILTER_WRITEABLE); - $calendar = $calendars[$default_id] ?: null; + $calendar = $calendars[$default_id] ?: null; + if (!$calendar || $sensitivity) { foreach ($calendars as $cal) { if ($sensitivity && $cal['subtype'] == $sensitivity) { @@ -2522,16 +2526,7 @@ class calendar extends rcube_plugin $this->load_driver(); // We search for writeable calendars in personal namespace by default - $result = $this->driver->get_event($event, calendar_driver::FILTER_WRITEABLE | calendar_driver::FILTER_PERSONAL); - - // Some plugins may search in other users calendars, e.g. where delegation is involved - $plugin = $this->rc->plugins->exec_hook('calendar_event_find', array( - 'search' => $event, - 'result' => $result, - 'calendar' => $this, - )); - - return $plugin['result']; + return $this->driver->get_event($event, calendar_driver::FILTER_WRITEABLE | calendar_driver::FILTER_PERSONAL); } /** @@ -2550,7 +2545,7 @@ class calendar extends rcube_plugin // get a list of writeable calendars to save new events to if (!$existing && !$data['nosave'] && $response['action'] == 'rsvp' || $response['action'] == 'import') { - $calendars = $this->driver->list_calendars(calendar_driver::FILTER_PERSONAL); + $calendars = $this->driver->list_calendars(calendar_driver::FILTER_WRITEABLE | calendar_driver::FILTER_PERSONAL); $calendar_select = new html_select(array('name' => 'calendar', 'id' => 'itip-saveto', 'is_escaped' => true)); $calendar_select->add('--', ''); $numcals = 0; @@ -2560,12 +2555,12 @@ class calendar extends rcube_plugin $numcals++; } } - if ($numcals <= 1) + if ($numcals < 1) $calendar_select = null; } if ($calendar_select) { - $default_calendar = $this->get_default_calendar($data['sensitivity']); + $default_calendar = $this->get_default_calendar($data['sensitivity'], $calendars); $response['select'] = html::span('folder-select', $this->gettext('saveincalendar') . ' ' . $calendar_select->show($default_calendar['id'])); } diff --git a/plugins/kolab_delegation/kolab_delegation.js b/plugins/kolab_delegation/kolab_delegation.js index c1bbe9b6..88406d97 100644 --- a/plugins/kolab_delegation/kolab_delegation.js +++ b/plugins/kolab_delegation/kolab_delegation.js @@ -31,6 +31,8 @@ window.rcmail && rcmail.addEventListener('init', function(evt) { // set delegator context for calendar requests on invitation message rcmail.addEventListener('requestcalendar/event', function(o) { rcmail.event_delegator_request(o); }); rcmail.addEventListener('requestcalendar/mailimportevent', function(o) { rcmail.event_delegator_request(o); }); + rcmail.addEventListener('requestcalendar/mailimportitip', function(o) { rcmail.event_delegator_request(o); }); + rcmail.addEventListener('requestcalendar/itip-status', function(o) { rcmail.event_delegator_request(o); }); if (rcmail.env.delegators && window.rcube_calendar_ui) { rcmail.calendar_identity_init(); diff --git a/plugins/kolab_delegation/kolab_delegation.php b/plugins/kolab_delegation/kolab_delegation.php index 6f7b48a8..41c6af70 100644 --- a/plugins/kolab_delegation/kolab_delegation.php +++ b/plugins/kolab_delegation/kolab_delegation.php @@ -54,7 +54,6 @@ class kolab_delegation extends rcube_plugin $this->add_hook('calendar_user_emails', array($this, 'calendar_user_emails')); $this->add_hook('calendar_list_filter', array($this, 'calendar_list_filter')); $this->add_hook('calendar_load_itip', array($this, 'calendar_load_itip')); - $this->add_hook('calendar_event_find', array($this, 'calendar_event_find')); // delegation support in kolab_auth plugin $this->add_hook('kolab_auth_emails', array($this, 'kolab_auth_emails')); @@ -260,22 +259,6 @@ class kolab_delegation extends rcube_plugin return $args; } - /** - * calendar::find_event() handler - */ - public function calendar_event_find($args) - { - // If the event can't be found in user personal folders, we'll - // look in delegators' folders (T1264) - - if (!empty($_SESSION['delegators']) && empty($args['result'])) { - $engine = $this->engine(); - $engine->delegator_find_event($args); - } - - return $args; - } - /** * Delegation support in Calendar plugin UI */ diff --git a/plugins/kolab_delegation/kolab_delegation_engine.php b/plugins/kolab_delegation/kolab_delegation_engine.php index a84bc07d..68e9085e 100644 --- a/plugins/kolab_delegation/kolab_delegation_engine.php +++ b/plugins/kolab_delegation/kolab_delegation_engine.php @@ -801,7 +801,7 @@ class kolab_delegation_engine continue; } if ($args['personal']) { - $ns = $cal->get_namespace(); + $ns = $cal->get_namespace(); if (empty($context)) { if ($ns != 'personal') { @@ -863,39 +863,6 @@ class kolab_delegation_engine } } - /** - * Finds an event in delegators' folders. Calendar looks only in - * personal namespace, we "extend" this to delegators' folders. - * - * @param array $args Reference to plugin hook arguments - */ - public function delegator_find_event(&$args) - { - // The event wasn't found and current user has delegators - if (!empty($_SESSION['delegators']) && empty($args['result'])) { - $event = $args['search']; - $ns_root = kolab_storage::namespace_root('other'); - $storage = $this->rc->get_storage(); - $delimiter = $storage->get_hierarchy_delimiter(); - $folders = $storage->list_folders_subscribed($ns_root, '*', 'event', 'w'); - - // search in all delegators' calendars - foreach ($folders as $folder) { - list($uid, $path) = explode($delimiter, substr($folder, strlen($ns_root)), 2); - - if (!empty($_SESSION['delegators'][$uid])) { - $event['calendar'] = kolab_storage::folder_id($folder, true); - $result = $args['calendar']->driver->get_event($event, calendar_driver::FILTER_WRITEABLE); - - if ($result) { - $args['result'] = $result; - return; - } - } - } - } - } - /** * Compares two ACLs (according to supported rights) * diff --git a/plugins/libkolab/lib/kolab_storage.php b/plugins/libkolab/lib/kolab_storage.php index 2855b1c8..7fefcedb 100644 --- a/plugins/libkolab/lib/kolab_storage.php +++ b/plugins/libkolab/lib/kolab_storage.php @@ -344,6 +344,8 @@ class kolab_storage */ public static function namespace_root($name) { + self::setup(); + foreach ((array)self::$imap->get_namespace($name) as $paths) { if (strlen($paths[0]) > 1) { return $paths[0];