Control access to the route
@param string $permission
436024
protected function controlAccess($permission)
    {
        if (isset($this->uid) && !$this->user->access($permission, $this->uid)) {
            $this->errorAndExit($this->text('No access'));
        }
    }
196638
public function matchesPermission(Permission $permission)
    {
        return (
            $this instanceof $permission &&
            $this->action === $permission->getAction() && // Not using matchesAction to avoid the wildcard
            $this->matchesResource($permission->getResource())
        );
    }
740318
protected function authorize(string $permission, array $context = []): bool
    {
        if (!$this->allows($permission, $context)) {
            $name = $this->resolvePermission($permission);

            throw new ControllerException(
                "Unauthorized permission '{$name}'",
                ControllerException::FORBIDDEN
            );
        }

        return true;
    }
1360998
public function addPermission($permission)
    {
        if (!$this->hasPermission($permission)) {
            return PermissionRole::create(['role_id' => $this->id, 'permission_id' => $permission->id]);
        }

        return false;
    }
803462
public function preparePermission($permission)
    {
        if ($permission instanceof Permission) {
            return $permission;
        }

        if (is_numeric($permission)) {
            return Permission::whereId($permission)->first();
        }

        return Permission::whereName($permission)->first();
    }
626157
public function detachPermission($permission)
    {
        $permission = Helper::getIdFor($permission, 'permission');

        $this->permissions()->detach($permission);
        $this->flushCache();
        $this->fireLaratrustEvent("permission.detached", [$this, $permission]);

        return $this;
    }
360923
public function can(string $permission): bool
    {
        if ($this->isAdministrator()) {
            return true;
        }

        if ($this->permissions->pluck('slug')->contains($permission)) {
            return true;
        }

        return $this->roles->pluck('permissions')->flatten()->pluck('slug')->contains($permission);
    }
186763
public function hasPermission($permission)
    {
        foreach ($this->permissions()->get() as $p) {
            if ($p->name == $permission) {
                return true;
            }
        }
        return false;
    }
1350993
private function checkIfUserHasPermission($permission)
    {
        if (!$this->isGranted($permission, $this->entityClass)) {
            throw $this->createAccessDeniedException(
                sprintf('You do not have "%s" permission on "%s" class objects.', $permission, $this->entityClass)
            );
        }
    }
870263
protected function setPermissions($permissions)
    {
        foreach ($permissions as $action => $permission) {
            $this->setPermission($action, $permission);
        }
    }
1316554
public function can($permission, array $params = [], $caching = true)
    {
        return $this->canAccess($permission, $params, $caching);
    }
394441
protected function storePermission(Permission $permission)
    {
        // Don't re-store the permission if it already exists.
        if (! $this->hasPermission($permission)) {
            $this->getDriver()->storeRolePermission($this->role, $permission);
        }
    }
1030248
private function removeDeletedPermissions(array $permission): void
    {
        $configActions = collect($permission['actions']);

        $actions = $this->permissionRepository->makeQuery()->where('name', $permission['name'])->pluck('action');

        $removedActions = $actions->diff($configActions);

        if ($removedActions->isNotEmpty()) {
            foreach ($removedActions as $action) {
                $this->permissionRepository->deletePermission($action);
            }
        }
    }
1137479
public function canAccess($member = null, $permission = 'ADMIN')
    {
        if (!$member) {
            $member = Security::getCurrentUser();
        }

        // We allow access to this controller regardless of live-status or ADMIN permission only
        // if on CLI.  Access to this controller is always allowed in "dev-mode", or of the user is ADMIN.
        if (Director::isDev()
            || Director::is_cli()
            || empty($permission)
            || Permission::checkMember($member, $permission)
        ) {
            return true;
        }

        // Extended access checks.
        // "Veto" style, return NULL to abstain vote.
        $canExtended = null;
        $results = $this->extend('canAccess', $member);
        if ($results && is_array($results)) {
            if (!min($results)) {
                return false;
            }
            return true;
        }

        return false;
    }
887776
public function inferControllerAction($permission)
    {
        $area = null;
        if ($permission[0] === '/') {
            if ($areas = $this->router->getAreas()) {
                $pos = strpos($permission, '/', 1);
                $area = Text::camelize($pos === false ? substr($permission, 1) : substr($permission, 1, $pos - 1));
                if (in_array($area, $areas, true)) {
                    $permission = $pos === false || $pos === strlen($permission) - 1 ? '' : (string)substr($permission, $pos + 1);
                } else {
                    $area = null;
                    $permission = $permission === '/' ? '' : (string)substr($permission, 1);
                }
            } else {
                $permission = $permission === '/' ? '' : (string)substr($permission, 1);
            }
        } else {
            $area = $this->dispatcher->getArea();
        }

        if ($permission === '') {
            $controller = 'Index';
            $action = 'index';
        } elseif ($pos = strpos($permission, '/')) {
            if ($pos === false || $pos === strlen($permission) - 1) {
                $controller = Text::camelize($pos === false ? $permission : substr($permission, 0, -1));
                $action = 'index';
            } else {
                $controller = Text::camelize(substr($permission, 0, $pos));
                $action = lcfirst(Text::camelize(substr($permission, $pos + 1)));
            }
        } else {
            $controller = Text::camelize($permission);
            $action = 'index';
        }

        if ($area) {
            return ["@ns.app\\Areas\\$area\\Controllers\\{$controller}Controller", $action];
        } else {
            return ["@ns.app\\Controllers\\{$controller}Controller", $action];
        }
    }
270856
public function checkPermission($permission)
    {
        $roleAttribute = "can_{$permission}";
        return isset($this->$roleAttribute) ? (bool)$this->$roleAttribute : false;
    }
71104
public function can($permission)
    {
        $permissions = $this->getPermissions();

        if (is_array($permission)) {
            $permissionCount   = count($permission);
            $intersection      = array_intersect($permissions, $permission);
            $intersectionCount = count($intersection);

            return ($permissionCount == $intersectionCount) ? true : false;
        } else {
            return in_array($permission, $permissions);
        }
    }