Fetches all nested allowed permission IDs from a nested permission set

@param string $permissionName

@return array|bool
173089
public static function getNestedPermissionIds(string $permissionName)
    {
        if (self::isAdmin()) {
            return true;
        }

        $user           = \Craft::$app->getUser();
        $permissionName = strtolower($permissionName);
        $idList         = [];

        if (self::permissionsEnabled()) {
            if (!$user->getId()) {
                return [];
            }

            $permissionList = \Craft::$app->userPermissions->getPermissionsByUserId($user->getId());
            foreach ($permissionList as $permission) {
                if (strpos($permission, $permissionName) === 0) {
                    if (strpos($permission, ':') === false) {
                        continue;
                    }

                    list($name, $id) = explode(':', $permission);

                    $idList[] = $id;
                }
            }

            return $idList;
        }

        return self::isAdmin();
    }
379937
public static function username($username, $permission)
    {
        try {
            $response = static::client()->request('GET', '/eeyes/permission/username', [
                'query' => [
                    'username' => $username,
                    'permission' => $permission,
                ],
            ]);
        } catch (GuzzleException $e) {
            return [
                'can' => false,
                'msg' => $e->getMessage(),
            ];
        }
        if ($response->getStatusCode() !== 200) {
            return [
                'can' => false,
                'msg' => $response->getReasonPhrase(),
            ];
        }
        $result = json_decode($response->getBody(), true);
        if ($result['code'] !== 200) {
            return [
                'can' => false,
                'msg' => isset($result['msg']) ? $result['msg'] : 'Unknown error',
            ];
        } else {
            return $result['data'];
        }
    }
1279931
private function checkRoleHierarchyPermission($roleName, $permissionName, $role)
    {
        // Can current user manipulate role?
        if (is_string($role)) {
            $permissions = $this->app['config']->get("permissions/roles-hierarchy/$permissionName/$role", []);

            return in_array($roleName, $permissions);
        }

        // Can current user manipulate user?
        $user = $role;
        foreach ($user['roles'] as $role) {
            $permissions = $this->app['config']->get("permissions/roles-hierarchy/$permissionName/$role", []);
            if (in_array($roleName, $permissions)) {
                return true;
            }
        }

        return false;
    }
824984
public function GetByPermission($Permission) {
      if (!is_array($Permission))
         $Permission = array($Permission);
         
      $this->SQL->Select('r.*')
         ->From('Role r')
         ->Join('Permission per', "per.RoleID = r.RoleID")
         ->Where('per.JunctionTable is null');
         
      $this->SQL->BeginWhereGroup();
      $PermissionCount = count($Permission);
      for ($i = 0; $i < $PermissionCount; ++$i) {
         $this->SQL->Where('per.`'.$Permission[$i].'`', 1);
      }
      $this->SQL->EndWhereGroup();
      return $this->SQL->Get();
   }
1295760
public function getPermissionTable($userId)
    {
        if ($this->_permissionTable === null) {
            $this->_permissionTable = (new Query())
                ->select(['*'])
                ->from('{{%admin_user_group}}')
                ->innerJoin('{{%admin_group_auth}}', '{{%admin_user_group}}.group_id={{%admin_group_auth}}.group_id')
                ->innerJoin('{{%admin_auth}}', '{{%admin_group_auth}}.auth_id = {{%admin_auth}}.id')
                ->where(['{{%admin_user_group}}.user_id' => $userId])
                ->all();
        }
        
        return $this->_permissionTable;
    }
20030
private function checkRoleContentTypePermission($roleName, $permissionName, $contenttype)
    {
        // Actions on non-existing contenttypes are not allowed.
        if (!$this->app['storage.metadata']->createContentType($contenttype)) {
            return false;
        }

        $roles = $this->getRolesByContentTypePermission($permissionName, $contenttype);

        return in_array($roleName, $roles);
    }
1132607
public function getPermissionsAttribute()
    {
        return $this->active_roles
            ->pluck('permissions')
            ->flatten()
            ->unique(function (PermissionContract $permission) {
                return $permission->getKey();
            });
    }
1023093
public function revoke($permissions, $resourceName = null, $resourceId = null)
    {
        return $this->lock()->deny($permissions, $resourceName, $resourceId);
    }
161243
public function getPermissions()
    {
        // return permissions if they have already been requested
        if(Session::get("usersPermission")) {
            self::$permissions = Session::get("usersPermission");
            return Session::get("usersPermission");
        }
        // return permissions if they have already been requested
        if(self::$permissions) {
            return self::$permissions;
        }

        $groupIDs = [];
        foreach (Auth::user()->roles as $group) {
            if ($group->isDefault) {
                self::$permissions["global"]["isDefault"] = true;
            }
            $groupIDs[] = $group->groupID;
        }

        $permissions = Permission::whereIn("groupID", $groupIDs)->get();

        // save values in keys & values for easy access
        foreach ($permissions as $permission) {
            self::$permissions[$permission->app][$permission->key] = [
              'value' => ($permission->ids !== null) ? array_values(json_decode($permission->ids, true)) : $permission->value,
              'hasAll' => $permission['hasAll']
            ];
        }
        Session::put("usersPermission", self::$permissions);
        return self::$permissions;
    }
142020
public static function checkAccess($permissionName, $user = false, $params = [])
    {
        if (is_array($permissionName)) {
            $permissionName = self::createPermissionName($permissionName);
        }
        if (!$user) {
            $user = Yii::$app->user;
        }

        if (!$user->isGuest && !isset(self::$userRoles[$user->id])) {
            self::$userRoles[$user->id] = Yii::$app->authManager->getRolesByUser($user->id);
        }

        if (isset(self::$userRoles[$user->id][self::ROLE_ROOT])) {
            return true;
        }

        if (!self::$defaultRoles) {
            self::setDefaultRoles($user->id);
        }
        if (in_array($permissionName, self::$defaultRoles)) {
            return true;
        }

        return $user->can($permissionName, $params);
    }
661373
public function can($permission)
  {
    if (is_array($permission)) {
      return (!! (count($permission) == count(array_intersect($this->permissions()->pluck('name')->toarray(), $permission))));
    } else {
      return in_array($permission, $this->permissions()->pluck('name')->toarray());
    }
  }
948352
public function listPermissions()
    {
        if ($this->permissionCache !== false) {
            return $this->permissionCache;
        }

        /*
         * Load module items
         */
        foreach ($this->callbacks as $callback) {
            $callback($this);
        }

        /*
         * Load plugin items
         */
        $plugins = PluginManager::instance()->getPlugins();

        foreach ($plugins as $id => $plugin) {
            $items = $plugin->registerPermissions();
            if (!is_array($items)) {
                continue;
            }

            $this->registerPermissions($id, $items);
        }

        /*
         * Sort permission items
         */
        usort($this->permissions, function ($a, $b) {
            if ($a->order == $b->order) {
                return 0;
            }

            return $a->order > $b->order ? 1 : -1;
        });

        return $this->permissionCache = $this->permissions;
    }
1204582
public function hasPermission($permissionName, Subject $subject, Resource $resource = null, array $params = [])
    {
        return in_array($permissionName, $this->getPermissions($subject, $resource, $params));
    }
200719
public function permissions()
    {
        if (is_array($this->permissions)) {
            return $this->permissions;
        }

        if ($this->permissions) {
            return [ $this->permissions ];
        }

        return false;
    }
1278557
public function getAll(): iterable
    {
        if ($this->permissions === null) {

            /** @var array $list */
            $list = app()->getCollector()->collect('permissions')->get();

            $key = 0;
            $names = [];
            $permissions = [];

            foreach ($list as $name => $description) {
                $permissions[] = new Permission($name, $description);
                $names[$name] = $key;
                $key++;
            }

            $this->permissions = $permissions;
            $this->names = $names;
        }

        return $this->permissions;
    }
1119790
public function getPermissions()
    {
        if(!$this->permissions){
            $rolePermissions = $this->rolePermissions();
            $userPermissions = $this->grantedPermissions()->get();

            $permissions = $rolePermissions->merge($userPermissions);
            $deniedPermissions =$this->deniedPermissions()->get();

            $this->permissions = $permissions->filter(function($permission) use ($deniedPermissions)
            {
                return !$deniedPermissions->contains($permission);
            });
        }
        return $this->permissions;
    }
1284364
public function findAllWithAccess($permissions)
	{
		return array_filter($this->findAll(), function($user) use ($permissions)
		{
			return $user->hasAccess($permissions);
		});
	}