Assigns role to user with given limitation.

@param mixed $contentId
@param mixed $roleId
@param array $limitation
14009
public function assignRole($contentId, $roleId, array $limitation)
    {
        try {
            return $this->innerGateway->assignRole($contentId, $roleId, $limitation);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
1098915
public function updateRole($roleId, Request $request)
    {
        $createStruct = $this->inputDispatcher->parse(
            new Message(
                array('Content-Type' => $request->headers->get('Content-Type')),
                $request->getContent()
            )
        );

        return $this->roleService->updateRole(
            $this->roleService->loadRole($roleId),
            $this->mapToUpdateStruct($createStruct)
        );
    }
1181522
public function publishRoleDraft($roleDraftId)
    {
        $roleDraft = $this->loadRole($roleDraftId, Role::STATUS_DRAFT);

        try {
            $originalRoleId = $roleDraft->originalId;
            $role = $this->loadRole($originalRoleId);
            $roleAssignments = $this->loadRoleAssignmentsByRoleId($role->id);
            $this->deleteRole($role->id);

            foreach ($roleAssignments as $roleAssignment) {
                if (empty($roleAssignment->limitationIdentifier)) {
                    $this->assignRole($roleAssignment->contentId, $originalRoleId);
                } else {
                    $this->assignRole(
                        $roleAssignment->contentId,
                        $originalRoleId,
                        [$roleAssignment->limitationIdentifier => $roleAssignment->values]
                    );
                }
            }
            $this->roleGateway->publishRoleDraft($roleDraft->id, $role->id);
        } catch (NotFound $e) {
            // If no published role is found, only publishing is needed, without specifying original role ID as there is none.
            $this->roleGateway->publishRoleDraft($roleDraft->id);
        }
    }
900381
public function updatePolicyByRoleDraft($roleId, $policyId, Request $request)
    {
        $updateStruct = $this->inputDispatcher->parse(
            new Message(
                array('Content-Type' => $request->headers->get('Content-Type')),
                $request->getContent()
            )
        );

        $role = $this->roleService->loadRoleDraft($roleId);
        foreach ($role->getPolicies() as $policy) {
            if ($policy->id == $policyId) {
                try {
                    return $this->roleService->updatePolicy(
                        $policy,
                        $updateStruct
                    );
                } catch (LimitationValidationException $e) {
                    throw new BadRequestException($e->getMessage());
                }
            }
        }

        throw new Exceptions\NotFoundException("Policy not found: '{$request->getPathInfo()}'.");
    }
448843
protected function attachRoleToUser($role, $userId)
    {
        // Check if user exists
        if ($user = $this->userRepository->findById($userId)) {
            $user->attachRole($role);
            $this->info('Role attached successfully to user');
        } else {
            $this->error('Not possible to attach role. User not found');
        }
    }
895348
public function GetPermissions($RoleID, $LimitToSuffix = '') {
      //$Namespaces = $this->GetAllowedPermissionNamespaces();
      //$NamespaceCount = count($Namespaces);
      
      $Result = array();
      
      $GlobalPermissions = $this->GetGlobalPermissions($RoleID, $LimitToSuffix);
      $Result[] = $GlobalPermissions;
      
      $JunctionPermissions = $this->GetJunctionPermissions(array('RoleID' => $RoleID), NULL, $LimitToSuffix);
      $Result = array_merge($Result, $JunctionPermissions);
      
      return $Result;
   }
687427
public function loadPolicies($roleId, Request $request)
    {
        $loadedRole = $this->roleService->loadRole($roleId);

        return new Values\PolicyList($loadedRole->getPolicies(), $request->getPathInfo());
    }
1182230
public function assignSectionToContent($sectionId, $contentId)
    {
        $query = $this->dbHandler->createUpdateQuery();
        $query->update(
            $this->dbHandler->quoteTable('ezcontentobject')
        )->set(
            $this->dbHandler->quoteColumn('section_id'),
            $query->bindValue($sectionId, null, \PDO::PARAM_INT)
        )->where(
            $query->expr->eq(
                $this->dbHandler->quoteColumn('id'),
                $query->bindValue($contentId, null, \PDO::PARAM_INT)
            )
        );

        $query->prepare()->execute();
    }
1261446
public function removeRole($contentId, $roleId)
    {
        try {
            return $this->innerGateway->removeRole($contentId, $roleId);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
906653
function copy( $roleID )
    {
        $params = array();
        $params['ModuleName'] = $this->attribute( 'module_name' );
        $params['FunctionName'] = $this->attribute( 'function_name' );

        $db = eZDB::instance();
        $db->begin();
        $newPolicy = eZPolicy::createNew( $roleID, $params  );
        foreach ( $this->attribute( 'limitations' ) as $limitation )
        {
            $limitation->copy( $newPolicy->attribute( 'id' ) );
        }
        $db->commit();

        return $newPolicy;
    }
47331
public function loadLocationsByContent($contentId, $rootLocationId = null)
    {
        $rows = $this->locationGateway->loadLocationDataByContent($contentId, $rootLocationId);

        return $this->locationMapper->createLocationsFromRows($rows);
    }
871154
public function updatePolicy($roleId, $policyId, Request $request)
    {
        $updateStruct = $this->inputDispatcher->parse(
            new Message(
                array('Content-Type' => $request->headers->get('Content-Type')),
                $request->getContent()
            )
        );

        try {
            // First try to treat $roleId as a role draft ID.
            $role = $this->roleService->loadRoleDraft($roleId);
            foreach ($role->getPolicies() as $policy) {
                if ($policy->id == $policyId) {
                    try {
                        return $this->roleService->updatePolicy(
                            $policy,
                            $updateStruct
                        );
                    } catch (LimitationValidationException $e) {
                        throw new BadRequestException($e->getMessage());
                    }
                }
            }
        } catch (NotFoundException $e) {
            // Then try to treat $roleId as a role ID.
            $role = $this->roleService->loadRole($roleId);
            foreach ($role->getPolicies() as $policy) {
                if ($policy->id == $policyId) {
                    try {
                        return $this->roleService->updatePolicy(
                            $policy,
                            $updateStruct
                        );
                    } catch (LimitationValidationException $e) {
                        throw new BadRequestException($e->getMessage());
                    }
                }
            }
        }

        throw new Exceptions\NotFoundException("Policy not found: '{$request->getPathInfo()}'.");
    }
411484
public function putAction(Request $request, $roleId, $key)
    {
        /** @var EntityManagerInterface $entityManager */
        $entityManager = $this->get('doctrine.orm.entity_manager');
        /** @var RoleSettingRepository $repository */
        $repository = $this->get('sulu.repository.role_setting');

        $setting = $repository->findSetting($roleId, $key);
        if (!$setting) {
            $setting = $repository->createNew();
        }

        $setting->setKey($key);
        $setting->setValue($request->get('value', []));
        $setting->setRole($entityManager->getReference(Role::class, $roleId));

        $entityManager->persist($setting);
        $entityManager->flush();

        return $this->handleView($this->view($setting->getValue()));
    }
302451
function assignUserToRole( $params )
    {
        $location = $params['location'];
        $roleName = $params['role_name'];

        $node = $this->nodeByUrl( $params );
        if( is_object( $node ) )
        {
            $role = eZRole::fetchByName( $roleName );
            if( is_object( $role ) )
                $role->assignToUser( $node->attribute( 'contentobject_id' ) );
        }
    }
342667
protected function setUserRole($role_id)
    {
        $this->data_role = array();

        if (is_numeric($role_id)) {

            $this->data_role = $this->role->get($role_id);

            if (empty($this->data_role)) {
                $this->outputHttpStatus(404);
            }
        }
    }
1089213
public function restore_role_assignment($instance, $roleid, $userid, $contextid) {
        global $DB;

        if ($this->get_config('unenrolaction') == ENROL_EXT_REMOVED_UNENROL or $this->get_config('unenrolaction') == ENROL_EXT_REMOVED_SUSPENDNOROLES) {
            // Skip any roles restore, they should be already synced automatically.
            return;
        }

        // Just restore every role.
        if ($DB->record_exists('user_enrolments', array('enrolid'=>$instance->id, 'userid'=>$userid))) {
            role_assign($roleid, $userid, $contextid, 'enrol_'.$instance->enrol, $instance->id);
        }
    }
771387
public function updateRole($roleUuid, array $permissions)
    {
        $options = [
            'form_params' => [
                'permissions' => $permissions,
            ],
        ];

        return new OperationResponse(
            $this->connector->request('put', "/roles/${roleUuid}", $this->query, $options)
        );
    }