Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Getting user's rights with OrmAuth
  • Is there a way to get the given user ID's rights? When a user is member of a group, has a role and some rights on itself..

    I'm looking for a array with ALL the rights the user has..


    $user = \Model\Auth_User::find($find_user_id);
    var_dump($user->permissions); #seems to return all possible permissions..
    var_dump($user->userpermissions); #seems to return only the user permissions, without including the group and role permissions
  • HarroHarro
    Accepted Answer
    Define "all" rights?

    The Ormacl driver compiles a list of effective rights, which contains the permissions assigned directly, and the permissions inherited from group and/or role membership. It also takes removed or admin rights into account.

    When you're talking about assigned rights, it's not that simple. You have:

    $user->userpermissions, permissions directly assigned to the user
    $user->group->grouppermissions, permissions assigned to the group this user is a member of
    $user->roles[]->rolepermissions, permissions assigned to roles which are assigned to this user

    So there is a lot to walk through and check, which is what OrmAcl does.

    If you're interested in the effective rights, you can just read the cache file created for that user. If that does not exist, you can force creation of it by calling Auth::has_access() with a third parameter, which is an array containing login driver name and user id.
  • Alright, I've looped through all permissions (userpermissions, grouppermissions and rolepermissions) to get all the permissions the user has, this so we can allow those users to assign their rights to other users.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion