Setting Permission from Addon

Deek

Member
I created a new permission in group 'developer' with the permission 'canDownload' in the admin panel. I'm able to check the permission easily in my addon. I'm trying to enable this permission in my addon using

PHP:
XenForo_Model_Permission->updateGlobalPermissionsForUserCollection(array('developer' => array('canDownload' = true)), 0, $userId);

This isn't working when I go to check the permission again. How do I set a permission from within an addon?
 
If the permission is properly set in XF but your application isn't receiving the new permission setting when you check it, you most likely need to rebuild the permission cache.
 
If the permission is properly set in XF but your application isn't receiving the new permission setting when you check it, you most likely need to rebuild the permission cache.
I looked in the code for updateContentPermissionsForUserCollection and at one point it calls both

Code:
In XenForo_Model_Permission
updateUserPermissionCombination($userId, false)
rebuildPermissionCacheForUserId($userId)

But when I run the same function again the permission isn't set.
 
Without knowing the full story for what you're doing, I'm going to guess that the permission is actually set in XF and shows properly in the Admin screen but your add-on isn't receiving the new permissions when you check them.

Trust me, I went through the same thing and pulled my hair out for a while...
https://xenforo.com/community/threads/node-permission-changes-not-being-applied.76970/

The updateContentPermissionsForUserCollection uses the same routine you quoted above.

If the permissions ARE NOT set in XF and do NOT show properly in the Admin screen, then I have no clue.
 
Without knowing the full story for what you're doing, I'm going to guess that the permission is actually set in XF and shows properly in the Admin screen but your add-on isn't receiving the new permissions when you check them.

Trust me, I went through the same thing and pulled my hair out for a while...
https://xenforo.com/community/threads/node-permission-changes-not-being-applied.76970/

The updateContentPermissionsForUserCollection uses the same routine you quoted above.

If the permissions ARE NOT set in XF and do NOT show properly in the Admin screen, then I have no clue.

I figured it out. I was setting the permission using 1 or true when it needed to be 'allow'. Silly mistake on my end.

Code:
XenForo_Model_Permission->updateGlobalPermissionsForUserCollection(array('developer' => array('canDownload' = 'allow')), 0, $userId);
 
Back
Top Bottom