Permalink
Browse files

Fixes #15 , Now this allows correct update of Acl if already exist, …

…create if Acl do not exist and do nothing if there is no change in Acl
  • Loading branch information...
mailaneel committed Feb 25, 2012
1 parent 1f0b9b4 commit edb335224694438ab882070d26dd6a77b0fa8d12
Showing with 14 additions and 9 deletions.
  1. +14 −9 Domain/AbstractAclManager.php
@@ -141,30 +141,35 @@ protected function doCreateSecurityIdentity($identity)
*/
protected function doApplyPermission(MutableAclInterface $acl, PermissionContextInterface $context, $replace_existing = false)
{
- $insertAce = true;
$type = $context->getPermissionType();
-
- $aceCollection = $this->getAceCollection($acl, $context->getPermissionType());
+ $aceCollection = $this->getAceCollection($acl,
+ $context->getPermissionType());
$size = count($aceCollection) - 1;
reset($aceCollection);
for ($i = $size; $i >= 0; $i--) {
- if($replace_existing){
+ if ($replace_existing) {
// Replace all existing permissions with the new one
if ($context->hasDifferentPermission($aceCollection[$i])) {
// The ACE was found but with a different permission. Update it.
$acl->{"update{$type}Ace"}($i, $context->getMask());
+ //No need to proceed further because the acl is updated
+ return;
+ } else {
+ if ($context->equals($aceCollection[$i])) {
+ // The exact same ACE was found. Nothing to do.
+ return;
+ }
}
- $insertAce = false;
} else {
- if($context->equals($aceCollection[$i])){
+ if ($context->equals($aceCollection[$i])) {
// The exact same ACE was found. Nothing to do.
return;
}
}
}
- if($insertAce){
- $acl->{"insert{$type}Ace"}($context->getSecurityIdentity(), $context->getMask(), 0, $context->isGranting());
- }
+ //If we come this far means we have to insert ace
+ $acl->{"insert{$type}Ace"}($context->getSecurityIdentity(),
+ $context->getMask(), 0, $context->isGranting());
}
protected function doRevokePermission(MutableAclInterface $acl, PermissionContextInterface $context)

0 comments on commit edb3352

Please sign in to comment.