Fix finding an event which is in delegator's folder, on itip reply (T1264)

Summary: Fixes T1264

Reviewers: #roundcube_kolab_plugins_developers

Maniphest Tasks: T1264

Differential Revision: https://git.kolab.org/D157
This commit is contained in:
Aleksander Machniak 2016-06-20 10:09:24 +02:00 committed by Jeroen van Meeuwen (Kolab Systems)
parent 7eaf7ad1af
commit 98b6513dce
3 changed files with 74 additions and 4 deletions

View file

@ -2505,6 +2505,26 @@ class calendar extends rcube_plugin
/**** Event invitation plugin hooks ****/
/**
* Find an event in user calendars
*/
protected function find_event($event)
{
$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'];
}
/**
* Handler for calendar/itip-status requests
*/
@ -2512,11 +2532,11 @@ class calendar extends rcube_plugin
{
$data = rcube_utils::get_input_value('data', rcube_utils::INPUT_POST, true);
// find local copy of the referenced event
$this->load_driver();
$existing = $this->driver->get_event($data, calendar_driver::FILTER_WRITEABLE | calendar_driver::FILTER_PERSONAL);
$itip = $this->load_itip();
// find local copy of the referenced event
$existing = $this->find_event($data);
$itip = $this->load_itip();
$response = $itip->get_itip_status($data, $existing);
// get a list of writeable calendars to save new events to
@ -2915,7 +2935,7 @@ class calendar extends rcube_plugin
// save to calendar
if ($calendar && $calendar['editable']) {
// check for existing event with the same UID
$existing = $this->driver->get_event($event, calendar_driver::FILTER_WRITEABLE | calendar_driver::FILTER_PERSONAL);
$existing = $this->find_event($event);
if ($existing) {
// forward savemode for correct updates of recurring events

View file

@ -54,6 +54,7 @@ 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'));
@ -259,6 +260,22 @@ 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
*/

View file

@ -863,6 +863,39 @@ 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)
*