Permissions

ManagerJosh

Well-known member
Is there developer documentation or tutorials that explains how to leverage the existing permission system inside XF and build upon it in order to create/add/manage permissions for a potential addon?
 
Just use the interface for creating new permissions, and use something along the lines of:

Code:
$visitor = XenForo_Visitor::getInstance();
if ($visitor->hasPermission('permission_group_id', 'permission_id')
{
    // Do something if they have permission
}

That will work in most cases, otherwise you'll want to use
Code:
$userModel = $this->getModelFromCache('XenForo_Model_User');
$user = $userModel->getUserById($userId);
$user['permission'] = @unserialize($user['global_permission_cache']);
if (XenForo_Permission::hasPermission($user['permissions'], 'permission_group_id', 'permission_id'))
{
    // Do something if they have permission
}
 
Just use the interface for creating new permissions, and use something along the lines of:

Code:
$visitor = XenForo_Visitor::getInstance();
if ($visitor->hasPermission('permission_group_id', 'permission_id')
{
    // Do something if they have permission
}

That will work in most cases, otherwise you'll want to use
Code:
$userModel = $this->getModelFromCache('XenForo_Model_User');
$user = $userModel->getUserById($userId);
$user['permission'] = @unserialize($user['global_permission_cache']);
if (XenForo_Permission::hasPermission($user['permissions'], 'permission_group_id', 'permission_id'))
{
    // Do something if they have permission
}

What about adding our own category and permission sets inside the permission area in the AdminCP?
 
Old thread, but what @ManagerJosh probably meant was how to add a new permissiongroup. I wonder about the same.
Enable debug mode, go over to the Development tab and click Permission Definitions on the sidebar.

From there, click Create Permission Group at the top and give it an ID, title and associate to your add-on. Roughly, this is the broad area of what your permissions are for, i.e. Conversation Permissions, Thread Permissions, etc.

Next, create an Interface Group. This is how your permissions will be grouped when assigning / revoking user group permissions.

Finally, create your permission(s) and assign them to your chosen permission and interface groups.

Depending on what you're doing, you can optionally skip creating a permission + interface group and just assign your permission(s) to one of the stock groups.

On the permissions definitions list, you'll also notice some text next to the individual permission titles. That's your permission group ID and permission ID. Drop those in to the relevant places in Jake's code above and you're on your merry way.
 
Last edited:
Back
Top Bottom