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

Admin Permissions

Discussion in 'XenForo Development Discussions' started by Mythotical, Aug 12, 2013.

  1. Mythotical

    Mythotical Well-Known Member

    I'll come right out and ask specifically about Admin Permissions.

    I'm having a huge issue with getting mine to work. I'm sure it is due to me being a Super Admin but I'm trying to figure out why the following codes won't work.

    PHP:
    $canManage $visitor->hasAdminPermission('xfpoints_manage_points');
    PHP:
    $canManage $visitor->hasAdminPermission('xfPoints''xfpoints_manage_points');
    I have double checked the permission group ID and permission ID.

    Trying to use it in admin templates and I really hope it is because I'm a Super Admin, which I'm going to test now.
     
  2. xf_phantom

    xf_phantom Well-Known Member

    1. your second code can't work, look at the arguments....
    2. why not just open the method to see what it's doing.....

    PHP:
      /**
        * Determines if the current user has the specified admin permission.
        *
        * @param string $permissionId
        *
        * @return boolean
        */
       
    public function hasAdminPermission($permissionId)
       {
         if (empty(
    $this->_user['user_id']) || empty($this->_user['is_admin']))
         {
           return 
    false;
         }

         if (
    $this->isSuperAdmin())
         {
           return 
    true;
         }

         if (!
    is_array($this->_adminPermissions))
         {
           
    $this->_adminPermissions XenForo_Model::create('XenForo_Model_Admin')->getAdminPermissionCacheForUser(
             
    $this->_user['user_id']
           );
         }
         return !empty(
    $this->_adminPermissions[$permissionId]);
       }
     
  3. Mythotical

    Mythotical Well-Known Member

    Because I have been down that road. The problem is neither are working and I added these options but no method to keep users from bypassing by just entering the address directly.
     
  4. Bob

    Bob Well-Known Member

    There is no permission group for ADMIN permissions.
     
  5. Mythotical

    Mythotical Well-Known Member

    Even so @bobster65 without the group ID it still does not function.
     
  6. Jeremy

    Jeremy XenForo Moderator Staff Member

    Are you running your permission checks in preDispatch or in the template?
     
  7. Bob

    Bob Well-Known Member

    I just add preDispatch checks in my Admin Controllers.

    PHP:
        protected function _preDispatch($action)
        {
            
    $this->assertAdminPermission('manageAddonName');
        }
     
    BamaStangGuy likes this.
  8. Mythotical

    Mythotical Well-Known Member

    I have the preDispatch but never understood it but I think I do.

    Can I do this?
    PHP:
    protected function _preDispatch($action)
    {
      
    $this->assertAdminPermission('xfpoints_manage_points');
      
    $this->assertAdminPermission('xfpoints_gift_points');
    }
     

Share This Page