forked from extern/egroupware
show addressbooks for user whos preferences are displayed, for "default" and "forced" only show acl independent settings
This commit is contained in:
parent
358ab236e1
commit
25579d428c
@ -803,33 +803,37 @@ class addressbook_activesync implements activesync_plugin_write, activesync_plug
|
|||||||
{
|
{
|
||||||
$addressbooks = array();
|
$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();
|
$addressbook_bo = new addressbook_bo();
|
||||||
$addressbooks = $addressbook_bo->get_addressbooks(EGW_ACL_READ);
|
$addressbooks = $addressbook_bo->get_addressbooks(EGW_ACL_READ, null, $user);
|
||||||
unset($addressbooks[$user]); // personal addressbook is allways synced
|
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
|
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();
|
$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(
|
$addressbooks += array(
|
||||||
'G' => lang('Primary Group'),
|
'G' => lang('Primary Group'),
|
||||||
'U' => lang('Accounts'),
|
'U' => lang('Accounts'),
|
||||||
'A' => lang('All'),
|
'A' => lang('All'),
|
||||||
);
|
);
|
||||||
// allow to force "none", to not show the prefs to the users
|
// 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');
|
$addressbooks['N'] = lang('None');
|
||||||
}
|
}
|
||||||
|
|
||||||
// rewriting owner=0 to 'U', as 0 get's always selected by prefs
|
// 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']);
|
unset($addressbooks['U']);
|
||||||
}
|
}
|
||||||
|
@ -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->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(
|
$this->contact_fields = array(
|
||||||
'id' => lang('Contact ID'),
|
'id' => lang('Contact ID'),
|
||||||
@ -311,23 +311,51 @@ class addressbook_bo extends addressbook_so
|
|||||||
$this->delete_history = $GLOBALS['egw_info']['server']['history'];
|
$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
|
* Get the availible addressbooks of the user
|
||||||
*
|
*
|
||||||
* @param int $required=EGW_ACL_READ required rights on the addressbook or multiple rights or'ed together,
|
* @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
|
* to return only addressbooks fullfilling all the given rights
|
||||||
* @param string $extra_label first label if given (already translated)
|
* @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
|
* @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);
|
//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();
|
$addressbooks = $to_sort = array();
|
||||||
if ($extra_label) $addressbooks[''] = $extra_label;
|
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
|
// 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')
|
if (($rights & $required) == $required && $GLOBALS['egw']->accounts->get_type($uid) == 'g')
|
||||||
{
|
{
|
||||||
@ -339,20 +367,20 @@ class addressbook_bo extends addressbook_so
|
|||||||
asort($to_sort);
|
asort($to_sort);
|
||||||
$addressbooks += $to_sort;
|
$addressbooks += $to_sort;
|
||||||
}
|
}
|
||||||
if (!$GLOBALS['egw_info']['user']['preferences']['addressbook']['hide_accounts'] && (
|
if (!$preferences['addressbook']['hide_accounts'] && (
|
||||||
($this->grants[0] & $required) == $required ||
|
($grants[0] & $required) == $required ||
|
||||||
$GLOBALS['egw_info']['user']['preferences']['common']['account_selection'] == 'groupmembers' &&
|
$preferences['common']['account_selection'] == 'groupmembers' &&
|
||||||
$this->account_repository != 'ldap' && ($required & EGW_ACL_READ)))
|
$this->account_repository != 'ldap' && ($required & EGW_ACL_READ)))
|
||||||
{
|
{
|
||||||
$addressbooks[0] = lang('Accounts');
|
$addressbooks[0] = lang('Accounts');
|
||||||
}
|
}
|
||||||
// add all other user addressbooks the user has the necessary rights too
|
// add all other user addressbooks the user has the necessary rights too
|
||||||
$to_sort = array();
|
$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)
|
if ($to_sort)
|
||||||
@ -360,9 +388,9 @@ class addressbook_bo extends addressbook_so
|
|||||||
asort($to_sort);
|
asort($to_sort);
|
||||||
$addressbooks += $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 "<p>".__METHOD__."($required,'$extra_label')"; _debug_array($addressbooks);
|
//echo "<p>".__METHOD__."($required,'$extra_label')"; _debug_array($addressbooks);
|
||||||
return $addressbooks;
|
return $addressbooks;
|
||||||
|
@ -1067,36 +1067,37 @@ class addressbook_groupdav extends groupdav_handler
|
|||||||
/**
|
/**
|
||||||
* Return appliction specific settings
|
* 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
|
* @return array of array with settings
|
||||||
*/
|
*/
|
||||||
static function get_settings($hook_data)
|
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(
|
$addressbooks = array(
|
||||||
'A' => lang('All'),
|
'A' => lang('All'),
|
||||||
'G' => lang('Primary Group'),
|
'G' => lang('Primary Group'),
|
||||||
'U' => lang('Accounts'),
|
'U' => lang('Accounts'),
|
||||||
'O' => lang('Sync all selected into one'),
|
'O' => lang('Sync all selected into one'),
|
||||||
'D' => lang('Distribution lists as groups')
|
'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
|
// allow to force no other addressbooks
|
||||||
if ($GLOBALS['type'] === 'forced')
|
if ($hook_data['type'] === 'forced')
|
||||||
{
|
{
|
||||||
$addressbooks['N'] = lang('None');
|
$addressbooks['N'] = lang('None');
|
||||||
}
|
}
|
||||||
|
|
||||||
// rewriting owner=0 to 'U', as 0 get's always selected by prefs
|
// 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']);
|
unset($addressbooks['U']);
|
||||||
}
|
}
|
||||||
|
@ -313,8 +313,10 @@ class addressbook_so
|
|||||||
* @param string $contact_app='addressbook'
|
* @param string $contact_app='addressbook'
|
||||||
* @return array
|
* @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)
|
if ($user)
|
||||||
{
|
{
|
||||||
// contacts backend (contacts in LDAP require accounts in LDAP!)
|
// 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,
|
// add grants for accounts: if account_selection not in ('none','groupmembers'): everyone has read access,
|
||||||
// if he has not set the hide_accounts preference
|
// if he has not set the hide_accounts preference
|
||||||
// ToDo: be more specific for 'groupmembers', they should be able to see the groupmembers
|
// 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;
|
$grants[0] = EGW_ACL_READ;
|
||||||
}
|
}
|
||||||
// add account grants for admins
|
// add account grants for admins (only for current user!)
|
||||||
if ($this->is_admin()) // admin rights can be limited by ACL!
|
if ($user == $this->user && $this->is_admin()) // admin rights can be limited by ACL!
|
||||||
{
|
{
|
||||||
$grants[0] = EGW_ACL_READ; // admins always have read-access
|
$grants[0] = EGW_ACL_READ; // admins always have read-access
|
||||||
if (!$GLOBALS['egw']->acl->check('account_access',16,'admin')) $grants[0] |= EGW_ACL_EDIT;
|
if (!$GLOBALS['egw']->acl->check('account_access',16,'admin')) $grants[0] |= EGW_ACL_EDIT;
|
||||||
|
Loading…
Reference in New Issue
Block a user