Question

I am working on activecollab custom module, facing problem in permissions; I have added permissions with the help of "on_system_permissions.php" handler. But the thing is how can I check this on code that either the logged in user have permission of specific action or not ..

I got below code from activecollab other module:

class Role extends FwRole implements IHomescreen {

..
..

    function isPeopleManager(){

       $this->getPermissionValue('can_manage_people');

    }
...
...

}

Is that to check permission of any action? or it just return a value of that action?

In above class they are using $this-> and extending a class by FwRole .. When i using FwRole::getPermissionValue('can_manage_people'); to get return it gives me error of $this and object ..

So my question is how we can check permission of specific action in code and how i can use getPermissionValue() function to retrieve permission either yes or not ..

Was it helpful?

Solution

When you have a user instance, you can check whether that user has particular permission set to Yes by executing getSystemPermission method:

$user = Users::findById(12);

if($user instanceof User) {
  if($user->getSystemPermission('my_permission')) {
    print 'My permission set to Yes';
  } else {
    print 'My permission set to No';
  } // if
} // if

Note that activeCollab permissions cascade (can depend one on another). If you have dependent permission, system also checks whether you have parent permissions set to Yes, not just that (for example, system will return false for manage_projects permission if you don't have system_access permission, because it depends on it).

Update

Permission cascading has been introduced in activeCollab 3!

OTHER TIPS

The error is saying that You call $this but You are not in object context - that is because You call method getPermissionValue in a static context...

In Your code where You call FwRole::getPermissionValue('can_manage_people'); You have to do this:

$role = new FwRole; // if it needs a parameter in constructor, call it like new FwRole($param);
$permission_value = $role->getPermissionValue('permission');

By creating an instance of class FwRole You create the FwRole object thus You are in object context and the error (You provided) is gone.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top