Determine if the given ability should be granted for the current user.

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

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

        if ($result instanceof Response) {
            return $result;
        }

        return $result ? $this->allow() : $this->deny();
    }
353655
public function authorize($ability, $arguments = [])
    {
        [$ability, $arguments] = $this->parseAbilityAndArguments($ability, $arguments);

        return app(Gate::class)->authorize($ability, $arguments);
    }
262183
public function findByAbilitiesAndStatus(User $user, array $abilities, $status)
    {
        return $this->createQueryBuilder('ap')
            ->select('ap')
            ->where('ap.user = :user')
            ->andWhere('ap.ability IN (:abilities)')
            ->andWhere('ap.status = :status')
            ->orderBy('ap.id')
            ->setParameters([
                ':user' => $user,
                ':abilities' => $abilities,
                ':status' => $status,
            ])
            ->getQuery()
            ->getResult();
    }
909799
public function check($abilities, $arguments = [])
    {
        return collect($abilities)->every(function ($ability) use ($arguments) {
            try {
                return (bool) $this->raw($ability, $arguments);
            } catch (AuthorizationException $e) {
                return false;
            }
        });
    }
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));
    }
812064
public function user_can( $capability ) {
		if ( ! ( $this->_post_type_obj instanceof \WP_Post_Type ) ) {
			return false;
		}

		return ! empty( $this->_post_type_obj->cap->$capability );
	}
111728
def user_has(ability, get_user=import_user):
    
    def wrapper(func):
        @wraps(func)
        def inner(*args, **kwargs):
            from .models import Ability
            desired_ability = Ability.query.filter_by(
                name=ability).first()
            user_abilities = []
            current_user = get_user()
            for role in current_user._roles:
                user_abilities += role.abilities
            if desired_ability in user_abilities:
                return func(*args, **kwargs)
            else:
                raise Forbidden("You do not have access")
        return inner
    return wrapper
1150493
protected function hasRequiredAbility($user, $ability = null, $model = null)
    {
        if (!$user) {
            return false;
        }

        if (is_null($ability)) {
            return true;
        }

        /*
         * Some gates may check on number of arguments given. If model
         * is null, don't pass it as an argument.
         */
        if (is_null($model)) {
            return $user->can($ability);
        }

        return $user->can($ability, $model);
    }
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;
	}
1279192
protected function resolvePolicyCallback($user, $ability, array $arguments)
    {
        return function () use ($user, $ability, $arguments) {
            $instance = $this->getPolicyFor($arguments[0]);

            if (method_exists($instance, 'before')) {
                // We will prepend the user and ability onto the arguments so that the before
                // callback can determine which ability is being called. Then we will call
                // into the policy before methods with the arguments and get the result.
                $beforeArguments = array_merge([$user, $ability], $arguments);

                $result = call_user_func_array([$instance, 'before'], $beforeArguments);

                // If we received a non-null result from the before method, we will return it
                // as the result of a check. This allows developers to override the checks
                // in the policy and return a result for all rules defined in the class.
                if (! is_null($result)) {
                    return $result;
                }
            }

            if (! is_callable([$instance, $ability])) {
                return false;
            }

            return call_user_func_array([$instance, $ability], array_merge([$user], $arguments));
        };
    }
809324
public function recordGateCheck(?Authenticatable $user, $ability, $result, $arguments)
    {
        if (! Telescope::isRecording() || $this->shouldIgnore($ability)) {
            return;
        }

        $caller = $this->getCallerFromStackTrace();

        Telescope::recordGate(IncomingEntry::make([
            'ability' => $ability,
            'result' => $result ? 'allowed' : 'denied',
            'arguments' => $this->formatArguments($arguments),
            'file' => $caller['file'],
            'line' => $caller['line'],
        ]));

        return $result;
    }
256196
public function can($ability, $arguments = [])
    {
        foreach ($this->abilities as $check) {
            if (fnmatch($check, $ability)) {
                return true;
            }
        }

        return false;
    }
450424
protected function runBeforeCallback($authority, $ability, $arguments = [], $additional = null)
    {
        if ($this->slot != 'before') {
            return;
        }

        list($model, $additional) = $this->parseGateBeforeArguments(
            $arguments, $additional
        );

        if (! is_null($additional)) {
            return;
        }

        return $this->checkAtClipboard($authority, $ability, $model);
    }
523865
def ensure(user, action, subject):
    
    ability = Ability(user, get_authorization_method())
    if ability.cannot(action, subject):
        raise AccessDenied()
505374
public function user_can( $capability = null ) {
		if ( ! isset( $capability ) ) {
			$capability = $this->app->get_config( 'capability', 'default_user', 'manage_options' );
		}
		if ( false === $capability ) {
			return true;
		}
		if ( '' === $capability ) {
			return false;
		}

		return $this->has_cap( $capability ) || in_array( $capability, $this->user_roles );
	}
621658
public function can($ability, $arguments = []) : bool
    {
        if ($this->isAdministrator()) {
            return true;
        }

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

        return $this->roles->pluck('permissions')->flatten()->pluck('slug')->contains($ability);
    }
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];
    }