From e187d0880be4d444064eda83cde10c87de9dbbe5 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Thu, 12 Mar 2015 14:55:04 +0100 Subject: [PATCH] Subscribe to ACL plugin hooks and adjust the permission items for groupware folders (#4839) --- plugins/kolab_folders/kolab_folders.php | 66 +++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/plugins/kolab_folders/kolab_folders.php b/plugins/kolab_folders/kolab_folders.php index b3c2e8ef..6a01b249 100644 --- a/plugins/kolab_folders/kolab_folders.php +++ b/plugins/kolab_folders/kolab_folders.php @@ -68,6 +68,10 @@ class kolab_folders extends rcube_plugin // Special folders setting $this->add_hook('preferences_save', array($this, 'prefs_save')); + + // ACL plugin hooks + $this->add_hook('acl_rights_simple', array($this, 'acl_rights_simple')); + $this->add_hook('acl_rights_supported', array($this, 'acl_rights_supported')); } /** @@ -442,6 +446,68 @@ class kolab_folders extends rcube_plugin return $args; } + /** + * Handler for ACL permissions listing (acl_rights_simple hook) + * + * This shall combine the write and delete permissions into one item for + * groupware folders as updating groupware objects is an insert + delete operation. + * + * @param array $args Hash array with hook parameters + * + * @return array Hash array with modified hook parameters + */ + public function acl_rights_simple($args) + { + if ($args['folder']) { + list($type,) = $this->get_folder_type($args['folder']); + + // we're dealing with a groupware folder here... + if ($type && $type !== 'mail') { + if ($args['rights']['write'] && $args['rights']['delete']) { + $writeperms = $args['rights']['write'] . $args['rights']['delete']; + $items = array( + 'read' => 'lr', + 'write' => $writeperms, + 'other' => preg_replace('/[lr'.$writeperms.']/', '', $args['rights']['other']), + ); + $args['rights'] = $items; + + // add localized labels and titles for the altered items + $args['labels'] = array( + 'other' => $this->rc->gettext('shortacla','acl'), + ); + $args['titles'] = array( + 'other' => $this->rc->gettext('longaclother','acl'), + ); + } + } + } + + return $args; + } + + /** + * Handler for ACL permissions listing (acl_rights_supported hook) + * + * @param array $args Hash array with hook parameters + * + * @return array Hash array with modified hook parameters + */ + public function acl_rights_supported($args) + { + if ($args['folder']) { + list($type,) = $this->get_folder_type($args['folder']); + + // we're dealing with a groupware folder here... + if ($type && $type !== 'mail') { + // remove some irrelevant (for groupware objects) rights + $args['rights'] = str_split(preg_replace('/[sp]/', '', join('', $args['rights']))); + } + } + + return $args; + } + /** * Checks if IMAP server supports any of METADATA, ANNOTATEMORE, ANNOTATEMORE2 *