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 ..
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!