1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Setting Permission from Addon

Discussion in 'XenForo Development Discussions' started by Deek, Sep 9, 2014.

  1. Deek

    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

    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?
  2. Snog

    Snog Well-Known Member

    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.
  3. Deek

    Deek Member

    I looked in the code for updateContentPermissionsForUserCollection and at one point it calls both

    In XenForo_Model_Permission
    updateUserPermissionCombination($userId, false)
    But when I run the same function again the permission isn't set.
  4. Snog

    Snog Well-Known Member

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

    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.
  5. Deek

    Deek Member

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

    XenForo_Model_Permission->updateGlobalPermissionsForUserCollection(array('developer' => array('canDownload' = 'allow')), 0, $userId);
    Snog likes this.

Share This Page