fix : status mask of user where not changed when applying a user template

nb:
because a new user has all mask checked (all rights), a template will only UNCHECK boxes (remove rights):
- unchecked boxes on template will be unchecked on user
- checked boxes on template does nothing (left unchanged on user)
This commit is contained in:
jygaulier
2012-01-10 11:57:23 +01:00
parent cd28906c6b
commit a9346df384

View File

@@ -298,6 +298,13 @@ class ACL implements cache_cacheableInterface
$bas_to_acces = array();
$rights_to_give = array();
$sbmap = array( // map masks (and+xor) of template to masks to apply to user on base (and_and, and_or, xor_and, xor_or)
'00'=>array('aa'=>'1', 'ao'=>'0', 'xa'=>'1', 'xo'=>'0'),
'01'=>array('aa'=>'1', 'ao'=>'0', 'xa'=>'1', 'xo'=>'0'),
'10'=>array('aa'=>'1', 'ao'=>'1', 'xa'=>'0', 'xo'=>'0'),
'11'=>array('aa'=>'1', 'ao'=>'1', 'xa'=>'1', 'xo'=>'1')
);
foreach ($template_user->ACL()->get_granted_base() as $collection)
{
$base_id = $collection->get_base_id();
@@ -317,6 +324,20 @@ class ACL implements cache_cacheableInterface
$rights_to_give[$base_id][$right] = '1';
}
}
// apply sb : unchecked boxes on template will be unchecked on user
// checked boxes on template does nothing (left unchanged on user)
// get masks from 64 bits int AS DECIMAL STRING to BINARY STRING
$mand = substr(str_repeat('0', 64) . databox_status::dec2bin($template_user->ACL()->get_mask_and($base_id)), -64);
$mxor = substr(str_repeat('0', 64) . databox_status::dec2bin($template_user->ACL()->get_mask_xor($base_id)), -64);
$m = array('aa'=>'', 'ao'=>'', 'xa'=>'', 'xo'=>'');
for($i=0; $i<64; $i++)
{
$ax = $mand[$i].$mxor[$i];
foreach($m as $k=>$v)
$m[$k] .= $sbmap[$ax][$k];
}
$this->set_masks_on_base($base_id, $m['aa'], $m['ao'], $m['xa'], $m['xo']);
}
$this->give_access_to_base($bas_to_acces);
@@ -325,7 +346,7 @@ class ACL implements cache_cacheableInterface
{
$this->update_rights_to_base($base_id, $rights);
}
$this->user->set_last_template($template_user);
return $this;
@@ -1401,7 +1422,6 @@ class ACL implements cache_cacheableInterface
public function set_masks_on_base($base_id, $and_and, $and_or, $xor_and, $xor_or)
{
$vhex = array();
$datas = array(
'and_and' => $and_and,
'and_or' => $and_or,
@@ -1424,6 +1444,7 @@ class ACL implements cache_cacheableInterface
$vhex[$name] .= dechex(bindec($valtmp));
}
}
$sql = "UPDATE basusr
SET mask_and=((mask_and & " . $vhex['and_and'] . ") | " . $vhex['and_or'] . ")
,mask_xor=((mask_xor & " . $vhex['xor_and'] . ") | " . $vhex['xor_or'] . ")