Authorize a given action for the current user.

@param  mixed  $ability
@param  mixed|array  $arguments
@return \Illuminate\Auth\Access\Response

@throws \Illuminate\Auth\Access\AuthorizationException
353655
public function authorize($ability, $arguments = [])
    {
        [$ability, $arguments] = $this->parseAbilityAndArguments($ability, $arguments);

        return app(Gate::class)->authorize($ability, $arguments);
    }
999025
protected function callAfterCallbacks($user, $ability, array $arguments, $result)
    {
        foreach ($this->afterCallbacks as $after) {
            if (! $this->canBeCalledWithUser($user, $after)) {
                continue;
            }

            $afterResult = $after($user, $ability, $result, $arguments);

            $result = $result ?? $afterResult;
        }

        return $result;
    }
82243
protected function callAuthCallback(User $user, $ability, array $arguments)
    {
        $callback = $this->resolveAuthCallback($user, $ability, $arguments);

        return call_user_func_array($callback, array_merge(array($user), $arguments));
    }
92116
protected function callPolicyBefore($policy, $user, $ability, $arguments)
    {
        if (! method_exists($policy, 'before')) {
            return;
        }

        if ($this->canBeCalledWithUser($user, $policy, 'before')) {
            return $policy->before($user, $ability, ...$arguments);
        }
    }
298284
protected function callBeforeCallbacks($user, $ability, array $arguments)
    {
        $arguments = array_merge([$user, $ability], $arguments);

        foreach ($this->beforeCallbacks as $before) {
            if (! is_null($result = call_user_func_array($before, $arguments))) {
                return $result;
            }
        }
    }
279073
public static function gatekeeper($ability = null) {
    if (!isset(self::$currentUser)) {
      return false;
    }
    return self::$currentUser->gatekeeper($ability);
  }
353424
public function checkPermission($user, $ability, $arguments)
	{
		if ($user->role === 'admin') {
			return true;
		}

		// У пользователя роль, которой нет в списке
		$roles = $this->getRoles();
		if (!isset($roles[$user->role])) {
			return null;
		}

		// Ищем разрешение для данной роли среди наследников текущего разрешения
		$role = $roles[$user->role];
		$permissions = $this->getPermissions();
		$current = $ability;
		// Если для разрешения указана замена - элемент 'equal', то проверяется замена
		// (только при наличии оригинального разрешения в роли).
		// Callback оригинального не вызывается.
		if (in_array($current, $role) and isset($permissions[$current]['equal'])) {
			$current = $permissions[$current]['equal'];
		}

		$i = 0;
		$suitable = false;
		while (true) {
			if ($i++ > 100) {
				throw new \Exception("Seems like permission '{$ability}' is in infinite loop");
			}

			if (in_array($current, $role)) {
				$suitable = $suitable || $this->testUsingUserMethod($user, $ability, $current, $arguments);
			}
			if (isset($permissions[$current]['next']) and !$suitable) {
				$current = $permissions[$current]['next'];
			} else {
				return $suitable ? true : null;
			}
		}
		return null;
	}
443667
public static function forAuthority(Model $authority, $allowed = true)
    {
        return Models::ability()->where(function ($query) use ($authority, $allowed) {
            $query->whereExists(static::getRoleConstraint($authority, $allowed));
            $query->orWhereExists(static::getAuthorityConstraint($authority, $allowed));
            $query->orWhereExists(static::getEveryoneConstraint($allowed));
        });
    }
997820
protected function createGateUnauthorizedException($ability, $arguments, $message = null, $previousException = null)
    {
        $message = $message ?: __d('nova', 'This action is unauthorized.');

        return new HttpException(403, $message, $previousException);
    }
1001730
public static function makeIfCan($permission, $options, Authorizable $user = null)
    {
        if (is_null($user)) {
            $user = auth()->user();
        }

        if ($user->can($permission)) {
            return static::make($options);
        }

        return static::make()->authorized(false);
    }
970254
protected function callAuthCallback($user, $ability, array $arguments)
    {
        $callback = $this->resolveAuthCallback($user, $ability, $arguments);

        return $callback($user, ...$arguments);
    }
344964
public function getAbilities(Model $authority, $allowed = true)
    {
        return Abilities::forAuthority($authority, $allowed)->get();
    }
781672
public function authorize($ability, $arguments = [])
    {
        $result = $this->allows($ability, $arguments);
        return $result ? $this->allow() : $this->deny();
    }
561481
public function can($capability, $args = null)
	{
		if (!$this->user())
		{
			return false;
		}

		$userCan = false;

		if (is_array($capability))
		{
			foreach ($capability as $cap)
			{
				// if only one capability is accepted
				if (current_user_can($cap, $args) === true)
				{
					$userCan = true;
					break;
				}
			}
		}
		else
		{
			$userCan = current_user_can($capability, $args);
		}

		return $userCan;
	}
899695
protected static function getAuthorityConstraint(Model $authority, $allowed)
    {
        return function ($query) use ($authority, $allowed) {
            $permissions = Models::table('permissions');
            $abilities   = Models::table('abilities');
            $table       = $authority->getTable();
            $prefix      = Models::prefix();

            $query->from($table)
                  ->join($permissions, "{$table}.{$authority->getKeyName()}", '=', $permissions.'.entity_id')
                  ->whereRaw("{$prefix}{$permissions}.ability_id = {$prefix}{$abilities}.id")
                  ->where("{$permissions}.forbidden", ! $allowed)
                  ->where("{$permissions}.entity_type", $authority->getMorphClass())
                  ->where("{$table}.{$authority->getKeyName()}", $authority->getKey());

            Models::scope()->applyToModelQuery($query, $abilities);
            Models::scope()->applyToRelationQuery($query, $permissions);
        };
    }
334783
public function actionIfCan($authorization, $action, string $text, array $parameters = [], bool $absolute = true)
    {
        return $this->addIfCan($authorization, Link::toAction($action, $text, $parameters, $absolute));
    }
143920
protected function parseAbilityAndArguments($ability, $arguments)
    {
        if (is_string($ability) && strpos($ability, '\\') === false) {
            return [$ability, $arguments];
        }

        $method = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3)[2]['function'];

        return [$this->normalizeGuessedAbilityName($method), $ability];
    }