OneupAclBundle icon indicating copy to clipboard operation
OneupAclBundle copied to clipboard

Is there some options to check the permission of an other user than the logged one

Open GreGosPhaTos opened this issue 8 years ago • 4 comments

Is not an issue it's more a question : But is there a way to check the permission for an other user than the user connected in my application through the AclManager ?

Let's say I want to check if a user has the EDIT permission on the field A on a class B.

I have tried to extends the AclManager to create a isUserGranted method and tried to use the ACL's isGranted method instead of the securityContext one, but it seems doesn't work.

The other option would be to inject an other SecurityContext instance into the manager ? Any advises will be accepted thanks

GreGosPhaTos avatar Mar 15 '16 20:03 GreGosPhaTos

Ok actually I found a way it's a bite dirty but it's works fine ;) :

class AclCustomManager extends AclManager
{    
    public function isUserGranted($attributes, $user, $object, $field = null)
    {
        $token = new UsernamePasswordToken($user, null, 'your_firewall_name', $user->getRoles());
        $oldToken = $this->getSecurityContext()->getToken();
        $this->getSecurityContext()->setToken($token);
        $isGranted = $this->isGranted($attributes, $object, $field);
        $this->getSecurityContext()->setToken($oldToken);
        return $isGranted;
    }
}

GreGosPhaTos avatar Mar 15 '16 21:03 GreGosPhaTos

PR #29 solves your exact issue probably, doesn't it?

bytehead avatar Mar 16 '16 14:03 bytehead

@bytehead Cool didn't see that, well it seems to solve my problem, but does it works with the class field permission for example ?

Thanks

GreGosPhaTos avatar Mar 16 '16 17:03 GreGosPhaTos

@GreGosPhaTos I don't know. But @badaz should probably know it ;-)

bytehead avatar Mar 17 '16 08:03 bytehead