Get a list of the authority's abilities.

@param  \Illuminate\Database\Eloquent\Model  $authority
@param  bool  $allowed
@return \Illuminate\Database\Eloquent\Collection
344964
public function getAbilities(Model $authority, $allowed = true)
    {
        return Abilities::forAuthority($authority, $allowed)->get();
    }
460311
protected function getAbilityIdsAssociatedWithEveryone(array $abilityIds, $forbidden)
    {
        $query = Models::query('permissions')
            ->whereNull('entity_id')
            ->whereIn('ability_id', $abilityIds)
            ->where('forbidden', '=', $forbidden);

        Models::scope()->applyToRelationQuery($query, $query->from);

        return Arr::pluck($query->get(['ability_id']), 'ability_id');
    }
865670
public function can($ability, $arguments = array())
    {
        $gate = App::make('Nova\Auth\Access\GateInterface')->forUser($this);

        return $gate->check($ability, $arguments);
    }
457025
protected function getAssociatedAbilityIds($authority, array $abilityIds, $forbidden)
    {
        if (is_null($authority)) {
            return $this->getAbilityIdsAssociatedWithEveryone($abilityIds, $forbidden);
        }

        $relation = $authority->abilities();

        $table = Models::table('abilities');

        $relation->whereIn("{$table}.id", $abilityIds)
                 ->wherePivot('forbidden', '=', $forbidden);

        Models::scope()->applyToRelation($relation);

        return $relation->get(["{$table}.id"])->pluck('id')->all();
    }
979892
protected function getAuthority()
    {
        if (is_null($this->authority)) {
            return null;
        }

        if ($this->authority instanceof Model) {
            return $this->authority;
        }

        return Models::role()->where('name', $this->authority)->firstOrFail();
    }
17469
protected function getAbilityIds($abilities, $model = null, array $attributes = [])
    {
        if ($abilities instanceof Model) {
            return [$abilities->getKey()];
        }

        if ( ! is_null($model)) {
            return $this->getModelAbilityKeys($abilities, $model, $attributes);
        }

        if (Helpers::isAssociativeArray($abilities)) {
            return $this->getAbilityIdsFromMap($abilities, $attributes);
        }

        if (! is_array($abilities) && ! $abilities instanceof Collection) {
            $abilities = [$abilities];
        }

        return $this->getAbilityIdsFromArray($abilities, $attributes);
    }
353655
public function authorize($ability, $arguments = [])
    {
        [$ability, $arguments] = $this->parseAbilityAndArguments($ability, $arguments);

        return app(Gate::class)->authorize($ability, $arguments);
    }
712850
protected static function getAuthorityRoleConstraint(Model $authority)
    {
        return function ($query) use ($authority) {
            $pivot  = Models::table('assigned_roles');
            $roles  = Models::table('roles');
            $table  = $authority->getTable();
            $prefix = Models::prefix();

            $query->from($table)
                  ->join($pivot, "{$table}.{$authority->getKeyName()}", '=', $pivot.'.entity_id')
                  ->whereRaw("{$prefix}{$pivot}.role_id = {$prefix}{$roles}.id")
                  ->where($pivot.'.entity_type', $authority->getMorphClass())
                  ->where("{$table}.{$authority->getKeyName()}", $authority->getKey());

            Models::scope()->applyToModelQuery($query, $roles);
            Models::scope()->applyToRelationQuery($query, $pivot);
        };
    }
603363
public function getAuthority()
    {
        $authority = $this->getHost();
        if ($authority === null) {
            return '';
        }

        if ($this->getUserInfo() !== '') {
            $authority = $this->getUserInfo() . '@' . $authority;
        }

        if ($this->port !== null && self::isStandardPort($this->port, $this->scheme, $this->host) === false) {
            $authority .= ':' . $this->port;
        }

        return $authority;
    }
373698
public function authority()
    {
        $userInfo = $this->username;
        if ($this->password) {
            $userInfo .= ':' . $this->password;
        }
        $port      = $this->port();
        $authority = $this->host;
        if ($authority && $userInfo) {
            $authority = $userInfo . '@' . $authority;
        }
        if ($authority && $port) {
            $authority .= ':' . $port;
        }

        return $authority;
    }
454321
protected static function getRoleConstraint(Model $authority, $allowed)
    {
        return function ($query) use ($authority, $allowed) {
            $permissions = Models::table('permissions');
            $abilities   = Models::table('abilities');
            $roles       = Models::table('roles');
            $prefix      = Models::prefix();

            $query->from($roles)
                  ->join($permissions, $roles.'.id', '=', $permissions.'.entity_id')
                  ->whereRaw("{$prefix}{$permissions}.ability_id = {$prefix}{$abilities}.id")
                  ->where($permissions.".forbidden", ! $allowed)
                  ->where($permissions.".entity_type", Models::role()->getMorphClass());

            Models::scope()->applyToModelQuery($query, $roles);
            Models::scope()->applyToRelationQuery($query, $permissions);

            $query->where(function ($query) use ($roles, $authority, $allowed) {
                $query->whereExists(static::getAuthorityRoleConstraint($authority));

                if ($allowed) {
                    static::addRoleInheritCondition($query, $authority, $roles);
                }
            });
        };
    }
648271
public function authorize($ability, $arguments = array())
    {
        list($ability, $arguments) = $this->parseAbilityAndArguments($ability, $arguments);

        $gate = App::make('Nova\Auth\Access\GateInterface');

        return $this->authorizeAtGate($gate, $ability, $arguments);
    }
996918
public function to($authority)
    {
        $authorities = is_array($authority) ? $authority : [$authority];

        $roles = Models::role()->findOrCreateRoles($this->roles);

        foreach (Helpers::mapAuthorityByClass($authorities) as $class => $ids) {
            $this->assignRoles($roles, $class, new Collection($ids));
        }

        return true;
    }
1162780
public function any($abilities, $arguments = [])
    {
        return collect($abilities)->contains(function ($ability) use ($arguments) {
            return $this->check($ability, $arguments);
        });
    }
87386
public function getManagedAbilities(): Collection
    {
        $abilities = $this->isA('superadmin') ? app('cortex.auth.ability')->all() : $this->getAbilities();

        return $abilities->groupBy('entity_type')->map->pluck('title', 'id')->sortKeys();
    }
1319285
public function can($permission, $allowAny = false)
    {
        if ($allowAny) {
            return $this->hasAnyAccess(
                is_array($permission) ? $permission : [ $permission ]
            );
        }

        return $this->hasAccess(
            is_array($permission) ? $permission : [ $permission ]
        );
    }
290973
public static function can($permissionName, $params = [], $allowCaching = true)
    {
        if (Podium::getInstance()->userComponent === true) {
            return Podium::getInstance()->user->can($permissionName, $params, $allowCaching);
        }
        if (!Podium::getInstance()->user->isGuest) {
            $user = static::findMe();
            if (empty($user)) {
                return false;
            }
            if ($allowCaching && empty($params) && isset($user->_access[$permissionName])) {
                return $user->_access[$permissionName];
            }
            $access = Podium::getInstance()->rbac->checkAccess($user->id, $permissionName, $params);
            if ($allowCaching && empty($params)) {
                $user->_access[$permissionName] = $access;
            }
            return $access;
        }
        return false;
    }