Create a user permission, not persisted, and return it.

@param UserInterface $user
@param               $resourceClass
@param               $resourceId
@param array         $actions

@return UserPermissionInterface
435459
public function create(UserInterface $user, $resourceClass, $resourceId, array $actions) : UserPermissionInterface
    {
        return new UserPermission($user, $resourceClass, $resourceId, $actions);
    }
1207915
private function getUserObjectPermission(SecurityCondition $securityCondition, UserInterface $user)
    {
        $permissions = $this->getPermissions($securityCondition->getObjectType(), $securityCondition->getObjectId());

        return $this->getUserObjectPermissionByArray($permissions, $user);
    }
1016259
public function check($user, $permissions, $resourceName = null, $resourceId = null)
    {
        return $this->manager->caller($user)->can($permissions, $resourceName, (int)$resourceId);
    }
192139
public function add_user_permission($user, $action)
	{
		$db =  \App::get('db');

		if ($user == 'anonymous')
		{
			$user = '0';
		}

		if (!is_numeric($user))
		{
			$query = "SELECT id FROM `#__users` WHERE username=" . $db->quote($user) . ";";
			$db->setQuery($query);
			$user_id = $db->loadResult();

			if ($user_id === false)
			{
				$this->_error("Unknown user $user");
				return false;
			}
		}
		else
		{
			$user_id = $user;
		}

		$quoted_project_id = $db->quote($this->id);
		$quoted_user_id = $db->quote($user_id);
		$values = '';

		foreach ((array) $action as $a)
		{
			if (!empty($values))
			{
				$values .= ',';
			}
			$values .= "($quoted_project_id,$quoted_user_id," . $db->quote($a) .")";
		}

		$query = "INSERT IGNORE INTO `#__trac_user_permission` (trac_project_id,user_id,action) VALUES " .  $values . ";";

		$db->setQuery($query);
		$db->query();
	}
1304548
public function cannot($action, $resource = null, $resourceId = null)
    {
        $this->assertLockInstanceIsSet();

        return $this->lock->cannot($action, $resource, $resourceId);
    }
559528
public function createFavourite(User $user, ResourceNode $resourceNode)
    {
        $favourite = $this->repo->findOneBy(['user' => $user, 'resourceNode' => $resourceNode]);

        if (empty($favourite)) {
            $favourite = new Favourite();
            $favourite->setUser($user);
            $favourite->setResourceNode($resourceNode);
            $this->om->persist($favourite);
            $this->om->flush();
        }
    }
595405
public function allowed($action, $resourceType)
    {
        $this->assertLockInstanceIsSet();

        return $this->lock->allowed($action, $resourceType);
    }
1164445
public function create(UserInterface $user)
    {
        $entity = static::ENTITY_CLASSNAME;

        $activation = new $entity($user);

        $this->save($activation);

        return $activation;
    }
731250
protected function permissionDenied($user, $uri, &$response)
    {
        $_SESSION['GlobalMessage']['error'] = 'You do not have permission to access: ' . $uri;

        $log = Log::create(Log::TYPE_PERMISSION, 'user', 'Unauthorised access attempt.');
        $log->setUser($user);
        $log->setLink($uri);
        $log->save();

        $response = new RedirectResponse($response);
        $response->setHeader('Location', $this->config->get('site.full_admin_url'));
        $response->flush();
    }
666522
protected function hasAccess($controllerClass, $action, $parameters = [])
    {
        $user = $this->getSession()->getUser();
        return AclProxy::hasAccess($user, $controllerClass, $action, $parameters);
    }
351065
public function removeUser( core_kernel_classes_Resource $user)
    {
        $returnValue = (bool) false;

        $returnValue = $user->delete();

        return (bool) $returnValue;
    }
204842
private function checkEdit(TokenInterface $token, User $user)
    {
        //the user can edit himself too.
        //He just can add roles and stuff and this should be checked later
        if ($token->getUser() === $user) {
            return true;
        }

        return $this->isOrganizationManager($token, $user) ?
            VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_DENIED;
    }
664238
public function authorizeForUser($user, $ability, $arguments = [])
    {
        [$ability, $arguments] = $this->parseAbilityAndArguments($ability, $arguments);

        return app(Gate::class)->forUser($user)->authorize($ability, $arguments);
    }
511843
public function canIfAs(Authorizable $user, string $action): bool
    {
        $this->setUser($user);

        $permission = $this->canIf($action);

        $this->revokeUser();

        return $permission;
    }
1350022
protected function resolvePermissions($action, Resource $resource)
    {
        $permissions = $this->getInheritedRolePermissions($this->role);

        // Search for restrictions in the permissions. We'll do this first
        // because restrictions should override any privileges.
        if (! $this->resolveRestrictions($permissions, $action, $resource)) {
            return false;
        }

        // If there are restrictions on the roles but caller specific privileges are set, allow this to pass.
        return $this->resolvePrivileges($permissions, $action, $resource);
    }
1255095
public static function require_can_create_data_request_for_user($user, $requester = null) {
        $usercontext = \context_user::instance($user);

        require_capability('tool/dataprivacy:makedatarequestsforchildren', $usercontext, $requester);

        return true;
    }
999629
public function can($action, $resource = null, $resourceId = null)
    {
        $actions = (array) $action;
        $resource = $this->convertResourceToObject($resource, $resourceId);
        $permissions = $this->getPermissions();

        foreach ($actions as $action) {
            if ($aliases = $this->getAliasesForAction($action)) {
                if ($this->can($aliases, $resource) && $this->resolveRestrictions($permissions, $action, $resource)) {
                    return true;
                }
            }

            if (! $this->resolvePermissions($action, $resource)) {
                return false;
            }
        }

        return true;
    }