From fbf05c95f458d092cb0e70d01d144b7e0c2e2f9b Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Wed, 23 Jul 2014 14:00:20 +0000 Subject: [PATCH] show addressbooks for user whos preferences are displayed, for "default" and "forced" only show acl independent settings --- .../inc/class.addressbook_activesync.inc.php | 26 ++++++---- addressbook/inc/class.addressbook_bo.inc.php | 52 ++++++++++++++----- .../inc/class.addressbook_groupdav.inc.php | 27 +++++----- addressbook/inc/class.addressbook_so.inc.php | 10 ++-- 4 files changed, 75 insertions(+), 40 deletions(-) diff --git a/addressbook/inc/class.addressbook_activesync.inc.php b/addressbook/inc/class.addressbook_activesync.inc.php index 3dd9cb68e7..115442961a 100644 --- a/addressbook/inc/class.addressbook_activesync.inc.php +++ b/addressbook/inc/class.addressbook_activesync.inc.php @@ -803,33 +803,37 @@ class addressbook_activesync implements activesync_plugin_write, activesync_plug { $addressbooks = array(); - if (!isset($hook_data['setup'])) + if (!isset($hook_data['setup']) && in_array($hook_data['type'], array('user', 'group'))) { - $user = $GLOBALS['egw_info']['user']['account_id']; + $user = $hook_data['account_id']; $addressbook_bo = new addressbook_bo(); - $addressbooks = $addressbook_bo->get_addressbooks(EGW_ACL_READ); - unset($addressbooks[$user]); // personal addressbook is allways synced + $addressbooks = $addressbook_bo->get_addressbooks(EGW_ACL_READ, null, $user); + if ($user > 0) + { + unset($addressbooks[$user]); // personal addressbook is allways synced + if (isset($addressbooks[$user.'p'])) + { + $addressbooks[self::PRIVATE_AB] = lang('Private'); + } + } unset($addressbooks[$user.'p']);// private addressbook uses ID self::PRIVATE_AB - $fileas_options = array('0' => lang('use addressbooks "own sorting" attribute'))+$addressbook_bo->fileas_options(); } - if ($GLOBALS['egw_info']['user']['preferences']['addressbook']['private_addressbook']) - { - $addressbooks[self::PRIVATE_AB] = lang('Private'); - } $addressbooks += array( 'G' => lang('Primary Group'), 'U' => lang('Accounts'), 'A' => lang('All'), ); // allow to force "none", to not show the prefs to the users - if ($GLOBALS['type'] == 'forced') + if ($hook_data['type'] == 'forced') { $addressbooks['N'] = lang('None'); } // rewriting owner=0 to 'U', as 0 get's always selected by prefs - if (!isset($addressbooks[0])) + // not removing it for default or forced prefs based on current users pref + if (!isset($addressbooks[0]) && (in_array($hook_data['type'], array('user', 'group')) || + $GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'])) { unset($addressbooks['U']); } diff --git a/addressbook/inc/class.addressbook_bo.inc.php b/addressbook/inc/class.addressbook_bo.inc.php index 9a55d20c92..8bb590ffd2 100755 --- a/addressbook/inc/class.addressbook_bo.inc.php +++ b/addressbook/inc/class.addressbook_bo.inc.php @@ -183,7 +183,7 @@ class addressbook_bo extends addressbook_so { $this->default_addressbook = $this->user; // admin set a default or forced pref for personal addressbook } - $this->private_addressbook = $this->contact_repository == 'sql' && $this->prefs['private_addressbook']; + $this->private_addressbook = self::private_addressbook($this->contact_repository == 'sql', $this->prefs); $this->contact_fields = array( 'id' => lang('Contact ID'), @@ -311,23 +311,51 @@ class addressbook_bo extends addressbook_so $this->delete_history = $GLOBALS['egw_info']['server']['history']; } + /** + * Do we use a private addressbook (in comparison to a personal one) + * + * Used to set $this->private_addressbook for current user. + * + * @param string $contact_repository + * @param array $prefs addressbook preferences + * @return boolean + */ + public static function private_addressbook($contact_repository, array $prefs) + { + return $contact_repository == 'sql' && $prefs['private_addressbook']; + } + /** * Get the availible addressbooks of the user * * @param int $required=EGW_ACL_READ required rights on the addressbook or multiple rights or'ed together, * to return only addressbooks fullfilling all the given rights * @param string $extra_label first label if given (already translated) + * @param int $user=null account_id or null for current user * @return array with owner => label pairs */ - function get_addressbooks($required=EGW_ACL_READ,$extra_label=null) + function get_addressbooks($required=EGW_ACL_READ,$extra_label=null,$user=null) { //echo "uicontacts::get_addressbooks($required,$include_all) grants="; _debug_array($this->grants); + if (is_null($user)) + { + $user = $this->user; + $preferences = $GLOBALS['egw_info']['user']['preferences']; + $grants = $this->grants; + } + else + { + $prefs_obj = new preferences($user); + $preferences = $prefs_obj->read_repository(); + $grants = $this->get_grants($user, 'addressbook', $preferences); + } + $addressbooks = $to_sort = array(); if ($extra_label) $addressbooks[''] = $extra_label; - $addressbooks[$this->user] = lang('Personal'); + $addressbooks[$user] = lang('Personal'); // add all group addressbooks the user has the necessary rights too - foreach($this->grants as $uid => $rights) + foreach($grants as $uid => $rights) { if (($rights & $required) == $required && $GLOBALS['egw']->accounts->get_type($uid) == 'g') { @@ -339,20 +367,20 @@ class addressbook_bo extends addressbook_so asort($to_sort); $addressbooks += $to_sort; } - if (!$GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] && ( - ($this->grants[0] & $required) == $required || - $GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] == 'groupmembers' && + if (!$preferences['addressbook']['hide_accounts'] && ( + ($grants[0] & $required) == $required || + $preferences['common']['account_selection'] == 'groupmembers' && $this->account_repository != 'ldap' && ($required & EGW_ACL_READ))) { $addressbooks[0] = lang('Accounts'); } // add all other user addressbooks the user has the necessary rights too $to_sort = array(); - foreach($this->grants as $uid => $rights) + foreach($grants as $uid => $rights) { - if ($uid != $this->user && ($rights & $required) == $required && $GLOBALS['egw']->accounts->get_type($uid) == 'u') + if ($uid != $user && ($rights & $required) == $required && $GLOBALS['egw']->accounts->get_type($uid) == 'u') { - $to_sort[$uid] = $GLOBALS['egw']->common->grab_owner_name($uid); + $to_sort[$uid] = common::grab_owner_name($uid); } } if ($to_sort) @@ -360,9 +388,9 @@ class addressbook_bo extends addressbook_so asort($to_sort); $addressbooks += $to_sort; } - if ($this->private_addressbook) + if ($user > 0 && self::private_addressbook($this->contact_repository, $preferences['addressbook'])) { - $addressbooks[$this->user.'p'] = lang('Private'); + $addressbooks[$user.'p'] = lang('Private'); } //echo "

".__METHOD__."($required,'$extra_label')"; _debug_array($addressbooks); return $addressbooks; diff --git a/addressbook/inc/class.addressbook_groupdav.inc.php b/addressbook/inc/class.addressbook_groupdav.inc.php index 61a052b5bc..cfe67eecae 100644 --- a/addressbook/inc/class.addressbook_groupdav.inc.php +++ b/addressbook/inc/class.addressbook_groupdav.inc.php @@ -1067,36 +1067,37 @@ class addressbook_groupdav extends groupdav_handler /** * Return appliction specific settings * - * @param array $hook_data + * @param array $hook_data values for keys 'location', 'type' and 'account_id' * @return array of array with settings */ static function get_settings($hook_data) { - $addressbooks = array(); - if (!isset($hook_data['setup'])) - { - $user = $GLOBALS['egw_info']['user']['account_id']; - $addressbook_bo = new addressbook_bo(); - $addressbooks = $addressbook_bo->get_addressbooks(EGW_ACL_READ); - unset($addressbooks[$user]); // allways synced - unset($addressbooks[$user.'p']);// ignore (optional) private addressbook for now - } $addressbooks = array( 'A' => lang('All'), 'G' => lang('Primary Group'), 'U' => lang('Accounts'), 'O' => lang('Sync all selected into one'), 'D' => lang('Distribution lists as groups') - ) + $addressbooks; + ); + if (!isset($hook_data['setup']) && in_array($hook_data['type'], array('user', 'group'))) + { + $user = $hook_data['account_id']; + $addressbook_bo = new addressbook_bo(); + $addressbooks = $addressbook_bo->get_addressbooks(EGW_ACL_READ, null, $user); + if ($user > 0) unset($addressbooks[$user]); // allways synced + unset($addressbooks[$user.'p']);// ignore (optional) private addressbook for now + } // allow to force no other addressbooks - if ($GLOBALS['type'] === 'forced') + if ($hook_data['type'] === 'forced') { $addressbooks['N'] = lang('None'); } // rewriting owner=0 to 'U', as 0 get's always selected by prefs - if (!isset($addressbooks[0])) + // not removing it for default or forced prefs based on current users pref + if (!isset($addressbooks[0]) && (in_array($hook_data['type'], array('user', 'group')) || + $GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'])) { unset($addressbooks['U']); } diff --git a/addressbook/inc/class.addressbook_so.inc.php b/addressbook/inc/class.addressbook_so.inc.php index e73c60ce48..7d24286934 100755 --- a/addressbook/inc/class.addressbook_so.inc.php +++ b/addressbook/inc/class.addressbook_so.inc.php @@ -313,8 +313,10 @@ class addressbook_so * @param string $contact_app='addressbook' * @return array */ - function get_grants($user,$contact_app='addressbook') + function get_grants($user, $contact_app='addressbook', $preferences=null) { + if (!isset($preferences)) $preferences = $GLOBALS['egw_info']['user']['preferences']; + if ($user) { // contacts backend (contacts in LDAP require accounts in LDAP!) @@ -336,12 +338,12 @@ class addressbook_so // add grants for accounts: if account_selection not in ('none','groupmembers'): everyone has read access, // if he has not set the hide_accounts preference // ToDo: be more specific for 'groupmembers', they should be able to see the groupmembers - if (!in_array($GLOBALS['egw_info']['user']['preferences']['common']['account_selection'], array('none','groupmembers'))) + if (!in_array($preferences['common']['account_selection'], array('none','groupmembers'))) { $grants[0] = EGW_ACL_READ; } - // add account grants for admins - if ($this->is_admin()) // admin rights can be limited by ACL! + // add account grants for admins (only for current user!) + if ($user == $this->user && $this->is_admin()) // admin rights can be limited by ACL! { $grants[0] = EGW_ACL_READ; // admins always have read-access if (!$GLOBALS['egw']->acl->check('account_access',16,'admin')) $grants[0] |= EGW_ACL_EDIT;