Filter the specified request by the given permissions.

@param string|array $permissions
510393
public function filterByPermission($permissions)
    {
        $permissions = is_array($permissions) ? $permissions : func_get_args();

        foreach ($permissions as $permission) {
            if (!$this->auth->user()->can($permission)) {
                throw new PermissionDeniedException("You don't have permission to \"{$permission}\".");
            }
        }
    }
734177
public static function getPermissionHandles($permissions)
    {
        foreach ($permissions as &$permission) {
            //determine if permission references element, get handle if it does
            if (preg_match('/(:\w)/', $permission)) {
                $permissionParts = explode(":", $permission);
                $element = null;
                $hasUids = MigrationManagerHelper::isVersion('3.1');
                
                if (preg_match('/entries|entrydrafts/', $permissionParts[0])) {
                    $element = $hasUids ? Craft::$app->sections->getSectionByUid($permissionParts[1]) : Craft::$app->sections->getSectionById($permissionParts[1]);
                } elseif (preg_match('/volume/', $permissionParts[0])) {
                    $element = $hasUids ? Craft::$app->volumes->getVolumeByUid($permissionParts[1]) : Craft::$app->volumes->getVolumeById($permissionParts[1]);
                } elseif (preg_match('/categories/', $permissionParts[0])) {
                    $element = $hasUids ? Craft::$app->categories->getGroupByUid($permissionParts[1]) : Craft::$app->categories->getGroupById($permissionParts[1]);
                } elseif (preg_match('/globalset/', $permissionParts[0])) {
                    $element = $hasUids ? MigrationManagerHelper::getGlobalSetByUid($permissionParts[1]) : Craft::$app->globals->getSetByid($permissionParts[1]);
                }           

                if ($element != null) {
                    $permission = $permissionParts[0].':'.$element->handle;
                }
            }
        }

        return $permissions;
    }
849827
protected function toDotPermissions(array $permissions)
    {
        $data = [];
        //$permissions = $this->permissions->lists('slug', 'name');
        foreach ($permissions as $alias => $perm) {
            if ( ! is_array($perm) ) continue;
            foreach ($perm as $key => $value) {
                //if ( (bool) $value == false ) continue;
                $slug = $key . '.' . $alias;
                $data[$slug] = $value;
                //$data[] = $slug;
            }
        }

        return $data;
    }
562422
public function updatePermissions($permissions)
    {
        if ($this->isLink()) return;
        
        self::getDbConnection()->executeQuery('DELETE FROM users_groups_allow_cat WHERE catalog_id='.$this->id);
        if (is_array($permissions)) 
            foreach ($permissions as $pid => $groups)
                foreach($groups as $gid) if ($gid && $gid != GROUP_ADMIN)
                    self::getDbConnection()->executeQuery('INSERT INTO users_groups_allow_cat SET permission='.(int)$pid.', group_id='.(int)$gid.', catalog_id='.(int)$this->id);

    }
16199
public static function addPermissions(array $permissions)
    {
        $rows = [];

        foreach ($permissions as $permission => $groups) {
            foreach ((array) $groups as $group) {
                $rows[] = [
                    'group_id' => $group,
                    'permission' => $permission,
                ];
            }
        }

        return [
            'up' => function (Builder $schema) use ($rows) {
                $db = $schema->getConnection();

                foreach ($rows as $row) {
                    if ($db->table('group_permission')->where($row)->exists()) {
                        continue;
                    }

                    if ($db->table('groups')->where('id', $row['group_id'])->doesntExist()) {
                        continue;
                    }

                    $db->table('group_permission')->insert($row);
                }
            },

            'down' => function (Builder $schema) use ($rows) {
                $db = $schema->getConnection();

                foreach ($rows as $row) {
                    $db->table('group_permission')->where($row)->delete();
                }
            }
        ];
    }
258916
public function givePermissionTo(...$permissions)
    {
        $permissions = collect($permissions)
            ->flatten()
            ->map(function ($permission) {
                return $this->getStoredPermission($permission);
            })
            ->each(function ($permission) {
                $this->ensureModelSharesGuard($permission);
            })
            ->all();

        $this->permissions()->saveMany($permissions);

        $this->forgetCachedPermissions();

        return $this;
    }
278352
public function syncPermissions(array $permissions)
    {
        foreach ($this->permissions as $current)
        {
            /** @var Permission $current */
            if ($current->isAllowed() && ! in_array($current->getName(), $permissions))
            {
                $this->removePermission($current);
            }
        }

        $this->allow($permissions);
    }
767386
public function addPermissions($permissions) {
		foreach ($permissions as $permission) {
			$per                                 = new permission($permission);
			$this->role->sharedPermissionList [] = $per->get();
		}
		R::store($this->role);
	}
516195
protected function getStoredPermission($permissions)
    {
        if (is_string($permissions)) {
            return PermissionProxy::findByName($permissions, $this->getDefaultGuardName());
        }

        if (is_array($permissions)) {
            return PermissionProxy::whereIn('name', $permissions)
                ->whereIn('guard_name', $this->getGuardNames())
                ->get();
        }

        return $permissions;
    }
215045
public function syncPermissions($permissions)
    {
        $mappedPermissions = [];

        foreach ($permissions as $permission) {
            $mappedPermissions[] = Helper::getIdFor($permission, 'permission');
        }

        $changes = $this->permissions()->sync($mappedPermissions);
        $this->flushCache();
        $this->fireLaratrustEvent("permission.synced", [$this, $changes]);

        return $this;
    }
710393
public function filterByRole($roles)
    {
        $roles = is_array($roles) ? $roles : func_get_args();

        foreach ($roles as $role) {
            if (!$this->auth->user()->is($role)) {
                throw new PermissionDeniedException("You aren't a \"{$role}\".");
            }
        }
    }
897314
public function syncPermissions($permissions)
    {
        $sync = [];
        $this->mapArray($permissions, function ($permission) use (&$sync) {

            $sync[] = $this->parsePermissionId($permission);

            return $sync;
        });

        return $this->permissions()->sync($sync);
    }
870424
private function assignPermissions(Collection $permissions) {
        $roles = Role::whereIn('id', $this->role_ids)->get();

        if ($roles && $permissions) {
            $permission_ids = $permissions->lists('id')->all();

            foreach ($roles as $role) {
                $role->permissions()->attach($permission_ids);
            }
        }
    }
734083
public function flattenPermissions($permissions)
    {
        $flattened = array();
        foreach ($permissions as $itemName => $itemPermissions) {
            $flattened[$itemName] = $itemPermissions;

            if (isset($itemPermissions['children'])) {
                $children = $itemPermissions['children'];
                unset($itemPermissions['children']); // not needed in a flat tree
                $flattened = array_merge($flattened, $this->flattenPermissions($children));
            }

            if (isset($itemPermissions['parents'])) {
                $parents = $itemPermissions['parents'];
                unset($itemPermissions['parents']);
                $flattened = array_merge($flattened, $this->flattenPermissions($parents));
            }
        }
        return $flattened;
    }
1341081
protected function addPermissions(Collection $permissions)
    {
        foreach ($permissions as $permission) {
            $this->permissions[] = $permission->token;
        }
    }
1223042
public static function register(array $permissions): void
    {
        $permissions = self::format($permissions);

        self::$permissions = array_merge(self::$permissions, $permissions);
    }
822101
protected function userHasAllPermissions(array $permissions)
    {
        if ( ! count($permissions)) {
            return true;
        }

        return ! count(
            array_filter($permissions, function ($permission) {
                return ! array_get($this->userPermissions, $permission);
            })
        );
    }