Gdn_Session::checkRankedPermission PHP Method

checkRankedPermission() public method

Check the given permission, but also return true if the user has a higher permission.
public checkRankedPermission ( boolean | string $permission ) : boolean
$permission boolean | string The permission to check. Bool to force true/false.
return boolean True on valid authorization, false on failure to authorize
    public function checkRankedPermission($permission)
    {
        $permissionsRanked = array('Garden.Settings.Manage', 'Garden.Community.Manage', 'Garden.Moderation.Manage', 'Garden.SignIn.Allow');
        if ($permission === true) {
            return true;
        } elseif ($permission === false) {
            return false;
        } elseif (in_array($permission, $permissionsRanked)) {
            // Ordered rank of some permissions, highest to lowest
            $currentPermissionRank = array_search($permission, $permissionsRanked);
            /**
             * If the current permission is in our ranked list, iterate through the list, starting from the highest
             * ranked permission down to our target permission, and determine if any are applicable to the current
             * user.  This is done so that a user with a permission like Garden.Settings.Manage can still validate
             * permissions against a Garden.Moderation.Manage permission check, without explicitly having it
             * assigned to their role.
             */
            for ($i = 0; $i <= $currentPermissionRank; $i++) {
                if ($this->permissions->has($permissionsRanked[$i])) {
                    return true;
                }
            }
            return false;
        }
        // Check to see if the user has at least the given permission.
        return $this->permissions->has($permission);
    }