Check if user has an associated permission.

@param User   $user
@param object $model
@param string $action

@return bool
484989
protected function checkPermission(User $user, $model, $action)
    {
        $regex = str_replace('/', '\/', preg_quote(route('admin.dashboard')));
        $slug = preg_replace('/'.$regex.'/', '', $model->link(true));
        $slug = str_replace('/', '', explode('/', ltrim($slug, '/'))[0]);

        if (!isset(self::$datatypes[$slug])) {
            self::$datatypes[$slug] = DataType::where('slug', $slug)->first();
        }

        if ($str = self::$datatypes[$slug]) {
            $slug = $str->slug;
        }

        if ($slug == '') {
            $slug = 'admin';
        }

        // If permission doesn't exist, we can't check it!
        if (!Admin::model('Permission')->where('key', 'browse_'.$slug)->exists()) {
            return true;
        }

        return $user->hasPermission('browse_'.$slug);
    }
473699
final public function isOwner(CM_Model_User $user = null) {
        try {
            return $this->getUser()->equals($user);
        } catch (CM_Exception_Nonexistent $ex) {
            return false;
        }
    }
346237
def filer_has_permission(context, item, action):
    
    permission_method_name = 'has_{action}_permission'.format(action=action)
    permission_method = getattr(item, permission_method_name, None)
    request = context.get('request')

    if not permission_method or not request:
        return False
    # Call the permission method.
    # This amounts to calling `item.has_X_permission(request)`
    return permission_method(request)
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);
    }
194601
protected function rules(User $user, Model $model = null)
    {
        $rules = [];

        foreach ($this->getRules() as $rule) {
            $rules[] = new $rule($user, $model);
        }

        return $rules;
    }
953849
public function hasAccess(User $user, $controller, $action, $requestParameters) {
        $required = array();
        try {
            // $rights = ServiceManager::getServiceManager()->get(RouteAnnotationService::SERVICE_ID)->getRights($controller, $action);
            // todo use $rights when PHPDoc Annotations will be moved to the Doctrines annotations
            $requiredRights = ControllerHelper::getRequiredRights($controller, $action);
            $uris = $this->extractAndGroupUriFromParameters($requestParameters, array_keys($requiredRights));

            foreach($uris as $name => $urisValue) {
                $required[] = array_fill_keys($urisValue, $requiredRights[$name]);
            }
        } catch (ActionNotFoundException $e) {
            // action not found, no access
            return false;
        }
        
        return empty($required)
            ? true
            : $this->hasPrivileges($user, array_merge(...$required));
    }
1200185
public function hasAccess($model, $action, $session = 'Admin.crud', $exit = false) {
        return Admin::hasAccess($model, $action, $session, $exit);
    }
233361
public function canIf(string $action): bool
    {
        $roles = $this->getUserRoles();
        $action = Keyword::make($action);

        if (\is_null($this->actions->search($action))) {
            return false;
        }

        return $this->checkAuthorization($roles, $action);
    }
386289
public function authorized(User $user, Model $model = null)
    {
        return $this->filter(function ($action) use ($user, $model) {
            // authorize action only if action allows it.
            if (method_exists($action, 'authorize')) {
                return $action->authorize($user, $model);
            }

            return true;
        });
    }
756217
public function hasAccess(User $user, Application $app)
    {
        if ($this->getCollection($app) instanceof collection) {
            return $app->getAclForUser($user)->has_access_to_base($this->collection->get_base_id());
        }

        return true;
    }
666522
protected function hasAccess($controllerClass, $action, $parameters = [])
    {
        $user = $this->getSession()->getUser();
        return AclProxy::hasAccess($user, $controllerClass, $action, $parameters);
    }
499077
public function hasPermission(string $permission, ?Model $model = null, string $userForeignKey = 'user_id'): bool
    {
        // Check model's ownership
        if ($model && $model->{$userForeignKey} == $this->id) {
            return true;
        }

        // Check user's own permissions
        if ($this->permissions->pluck('code')->contains($permission)) {
            return true;
        }

        // Check user's groups permissions
        return $this->groups()->with('permissions')->get()->map->permissions->flatten()
                                                                            ->pluck('code')
                                                                            ->contains($permission);
    }
525879
def has_permission(self, request, view):
        
        if request.method == 'POST':
            user = Profile.objects.only('id', 'username').get(username=view.kwargs['username'])
            return request.user.id == user.id

        return True
540980
def has_permission(self, request, view):
        
        user_filter = self._get_user_filter(request)
        if not user_filter:
            # no user filters are present in the token to limit access
            return True

        username_param = get_username_param(request)
        allowed = user_filter == username_param
        if not allowed:
            log.warning(
                u"Permission JwtHasUserFilterForRequestedUser: user_filter %s doesn't match username %s.",
                user_filter,
                username_param,
            )
        return allowed
298712
public function isSatisfiedBy(User $user)
    {
        return $this->email === $user->email && password_verify($this->password, $user->password);
    }
102040
public function revokeUserAccess($resource, string $action)
    {
        $resourceRule = $this->getUserPermission($resource);

        if (!$resourceRule) {
            return;
        }

        // make sure we can work with this
        if ($resourceRule && !($resourceRule instanceof UserPermissionInterface)) {
            throw new PermissionExpectedException(UserPermissionInterface::class, \get_class($resourceRule));
        }

        if ($resourceRule) {
            if (!\in_array($action, $resourceRule->getActions(), true)) {
                return;
            }
            $resourceRule->removeAction($action);
            $this->userPermissions->update($resourceRule);
        }
    }
325203
public function hasPermissionTo($action)
    {
        return $this->allPermissions->has(
            function($permission) use ($action) {
                return $permission->action == $action;
            }
        );
    }