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

Add-On Permissions

Discussion in 'XenForo Development Discussions' started by Daniel 'RTRD', Jan 1, 2013.

  1. Daniel 'RTRD'

    Daniel 'RTRD' Well-Known Member

    Is there a easy way to check if the user has permissions to view the specific content?

    Is this correct?
    PHP:
            if ($hasPermission)
            {
                
    /* User does have permission */
            
    }
            else
            {
                
    /* User does NOT have permission */
            
    }
     
  2. Onimua

    Onimua Well-Known Member

    It depends on how you want to tell the user. Usually it's done by:
    PHP:
    if (!$this->_getItemModel()->canSeeItem($item$errorPhraseKey))
    {
        throw 
    $this->getErrorOrNoPermissionResponseException($errorPhraseKey);
    }
    You skip the "else" portion if they can view it and just proceed with the rest of your code.

    The check can be done with the visitor model ($visitor->hasPermission('group', 'permissionName') or through the permission class (XenForo_Permission::hasPermission($viewingUser['permissions'], 'group', 'permissionName')).
     
    Daniel 'RTRD', bousaid and Chris D like this.
  3. Daniel 'RTRD'

    Daniel 'RTRD' Well-Known Member

    So something like this?:
    PHP:
    if ($visitor->hasPermission('group''permissionName')
    {
        
    /* User does have permission */
    }
    else
    {
        
    /* User does NOT have permission */
    }
     
  4. Onimua

    Onimua Well-Known Member

    Pretty much, especially if you're intending on doing different things depending if the user has permission or not.
     
    Daniel 'RTRD' likes this.

Share This Page