cumulate group-preferences of all memberships of a user, not just his primary group

This commit is contained in:
Ralf Becker 2012-10-30 10:22:05 +00:00
parent 71cebbf12e
commit 7cd606e529

View File

@ -18,7 +18,7 @@
* the prefs are read into 5 arrays: * the prefs are read into 5 arrays:
* $data the effective prefs used everywhere in phpgw, they are merged from the other 3 arrays * $data the effective prefs used everywhere in phpgw, they are merged from the other 3 arrays
* $user the stored user prefs, only used for manipulating and storeing the user prefs * $user the stored user prefs, only used for manipulating and storeing the user prefs
* $group the stored prefs of users primary groupd, only used for manipulating and storeing the user prefs * $group the stored prefs of all group-memberships of current user, can NOT be deleted or stored directly!
* $default the default preferences, always used when the user has no own preference set * $default the default preferences, always used when the user has no own preference set
* $forced forced preferences set by the admin, they take precedence over user or default prefs * $forced forced preferences set by the admin, they take precedence over user or default prefs
* *
@ -155,12 +155,11 @@ class preferences
*/ */
function cache_read($ids) function cache_read($ids)
{ {
$prefs = $db_read = array(); $prefs = egw_cache::getInstance(__CLASS__, $ids);
$db_read = array();
foreach((array)$ids as $id) foreach((array)$ids as $id)
{ {
$prefs[$id] = egw_cache::getInstance(__CLASS__, $id); // if prefs are not returned, null or not an array, read them from db
// if prefs are not returned (null) or not an array, read them from db
if (!isset($prefs[$id]) && !is_array($prefs[$id])) $db_read[] = $id; if (!isset($prefs[$id]) && !is_array($prefs[$id])) $db_read[] = $id;
} }
if ($db_read) if ($db_read)
@ -345,13 +344,17 @@ class preferences
$this->session = array(); $this->session = array();
} }
$this->forced = $this->default = $this->user = $this->group = array(); $this->forced = $this->default = $this->user = $this->group = array();
$primary_group = accounts::id2name($this->account_id, 'account_primary_group'); $to_read = array(self::DEFAULT_ID,self::FORCED_ID,$this->account_id);
foreach($this->cache_read(array( if ($this->account_id > 0)
self::DEFAULT_ID, {
self::FORCED_ID, $primary_group = accounts::id2name($this->account_id, 'account_primary_group');
$this->account_id, foreach($GLOBALS['egw']->accounts->memberships($this->account_id, true) as $gid)
$primary_group+self::DEFAULT_ID, // need to offset it with DEFAULT_ID = -2! {
)) as $id => $values) if ($gid != $primary_group) $to_read[] = $gid + self::DEFAULT_ID; // need to offset it with DEFAULT_ID = -2!
}
$to_read[] = $primary_group + self::DEFAULT_ID;
}
foreach($this->cache_read($to_read) as $id => $values)
{ {
switch($id) switch($id)
{ {
@ -365,7 +368,10 @@ class preferences
$this->user = $values; $this->user = $values;
break; break;
default: default:
$this->group = $values; foreach($values as $app => $vals)
{
$this->group[$app] = $vals + (array)$this->group[$app];
}
break; break;
} }
} }
@ -750,8 +756,7 @@ class preferences
$prefs = &$this->default; $prefs = &$this->default;
break; break;
case 'group': case 'group':
$account_id = $GLOBALS['egw']->accounts->id2name($this->account_id,'account_primary_group')+self::DEFAULT_ID; throw new egw_exception_wrong_parameter("Can NOT save group preferences, as they are from multiple groups!");
$prefs = &$this->group;
break; break;
default: default:
$account_id = (int)$this->account_id; $account_id = (int)$this->account_id;