@param AbstractRoleSubject[] $subjects
@param \Claroline\CoreBundle\Entity\Workspace\Workspace $workspace
@param \Claroline\CoreBundle\Entity\Role[] $roles

@throws Exception\LastManagerDeleteException
543501
public function checkWorkspaceRoleEditionIsValid(array $subjects, Workspace $workspace, array $roles)
    {
        $managerRole = $this->getManagerRole($workspace);
        $groupsManagers = $this->groupRepo->findByRoles(array($managerRole));
        $usersManagers = $this->userRepo->findByRoles(array($managerRole));

        $removedGroupsManager = 0;
        $removedUsersManager = 0;

        foreach ($subjects as $subject) {
            if ($subject->hasRole($managerRole->getName()) && in_array($managerRole, $roles)) {
                $subject instanceof \Claroline\CoreBundle\Entity\Group ?
                    $removedGroupsManager++:
                    $removedUsersManager++;
            }
        }

        if ($removedGroupsManager >= count($groupsManagers) && $removedUsersManager >= count($usersManagers)) {
            throw new LastManagerDeleteException("You can't remove every managers");
        }
    }
1112696
public function deleteClientAuthorization($clientId, $subject)
    {
        ValidationUtility::ensureStringOrInteger('$clientId', $clientId);
        ValidationUtility::ensureString('$subject', $subject);

        $request = new ClientAuthorizationDeleteRequest();
        $request->setSubject($subject);

        return $this->callServicePostApi(
            '\Authlete\Dto\ApiResponse::fromJson',
            self::$CLIENT_AUTHORIZATION_DELETE_API_PATH . $clientId,
            null, $request);
    }
710393
public function filterByRole($roles)
    {
        $roles = is_array($roles) ? $roles : func_get_args();

        foreach ($roles as $role) {
            if (!$this->auth->user()->is($role)) {
                throw new PermissionDeniedException("You aren't a \"{$role}\".");
            }
        }
    }
892956
public function deleteRole(Role $role)
    {
        $url = self::makeUrl($role->tenantId, $role->name);
        $this->service->prepAndSend($url, array(204), 'DELETE', null, false);
	}
1078568
public function assignRoles(...$roles): self
    {
        $roles = array_flatten($roles);
        $roles = $this->getRoles($roles);

        if (! $roles) {
            return $this;
        }

        $this->roles()->syncWithoutDetaching($roles);

        return $this;
    }
1343193
public static function drop($subjects, $fields)
	{
		$up = <<<UP
		\DBUtil::drop_table('{$subjects[1]}');
UP;
		$field_str = '';
		$column_list = \DB::list_columns($subjects[1]);

		foreach ($column_list as $column)
		{
			switch ($column['type'])
			{
				case 'float':
					$constraint = '\''.$column['numeric_precision'].', '.$column['numeric_scale'].'\'';
				break;
				case 'int':
					$constraint = $column['display'];
				break;
				case 'string':
					switch ($column['data_type'])
					{
						case 'binary':
						case 'varbinary':
						case 'char':
						case 'varchar':
							$constraint = $column['character_maximum_length'];
						break;

						case 'enum':
						case 'set':
							$constraint = '"\''.implode('\',\'',$column['options']).'\'"';
						break;
					}
				break;
			}

			$constraint_str = isset($constraint) ? ", 'constraint' => $constraint" : '';
			$auto_increment = $column['extra'] == 'auto_increment' ? ", 'auto_increment' => true" : '';
			$default_str = $column['default'] != null ? ", 'default' => '{$column['default']}'" : ", 'null' => true";

			if ($column['key'] == 'PRI')
			{
			  $primary_keys[] = "'{$column['name']}'";
			}
			else if ($column['key'] == 'MUL')
			{
			  $indexes[] = $column['name'];
			}

			$field_str .= "\t\t\t'{$column['name']}' => array('type' => '{$column['data_type']}'{$default_str}{$constraint_str}{$auto_increment}),".PHP_EOL;
			unset($constraint);
		}

		$primary_keys = implode(',', $primary_keys);
		$down = <<<DOWN
		\DBUtil::create_table('{$subjects[1]}', array(
$field_str
		), array($primary_keys));
DOWN;
		$down .= PHP_EOL;

		$active_db = \Config::get('db.active');
		$table_prefix = \Config::get('db.'.$active_db.'.table_prefix');

		if (isset($indexes))
		{
			foreach ($indexes as $field)
			{
				$down .= "\t\t\\DB::query(\"CREATE INDEX {$field}_idx ON {$table_prefix}{$subjects[1]} (`{$field}`)\")->execute();".PHP_EOL;
			}
		}

		return array($up, $down);
	}
254692
public function associateRole(AbstractRoleSubject $ars, Role $role, $sendMail = false, $dispatch = true)
    {
        if (!$this->validateRoleInsert($ars, $role)) {
            throw new Exception\AddRoleException('Role cannot be added');
        }

        if (get_class($ars) === 'Claroline\CoreBundle\Entity\Group' && $role->getName() === 'ROLE_USER') {
            throw new Exception\AddRoleException('ROLE_USER cannot be added to groups');
        }

        if (!$ars->hasRole($role->getName())) {

            $ars->addRole($role);
            $this->om->startFlushSuite();

            if ($dispatch) {
                $this->dispatcher->dispatch(
                    'log',
                    'Log\LogRoleSubscribe',
                    array($role, $ars)
                );
            }
            $this->om->persist($ars);
            $this->om->endFlushSuite();

            $withMail = $this->configHandler->getParameter('send_mail_at_workspace_registration');

            if ($sendMail) {
                $this->sendInscriptionMessage($ars, $role, $withMail);
            }
        }
    }
371227
protected final function createRbacRole(array $permissions, array $roles = [])
    {
        if (!$this->_rbacRoleFactory) {
            throw new RequiredDependencyException(sprintf(
                'Rbac role factory is not injected in class "%s".',
                get_class($this)
            ));
        }

        return $this->_rbacRoleFactory->createRole($permissions, $roles);
    }
422987
public function detachRole($role)
    {
        if (is_object($role)) {
            $role = $role->getKey();
        }

        if (is_array($role)) {
            $role = $role['id'];
        }

        $this->roles()->detach($role);

        self::clearCache();
    }
1320013
public function roles($roles)
    {
        $this->sync(
            Models::role()->getRoleKeys($roles),
            $this->authority->roles()
        );
    }
769082
protected function addRoles(Collection $roles)
    {
        foreach ($roles as $role) {
            $this->roles[] = $role->token;
            $this->addPermissions($role->permissions);
        }
    }
1009072
private function doLoadSharingPermissions(array $idSubjects, array $roles): void
    {
        /** @var RoleInterface[] $mapRoles */
        $mapRoles = [];
        $cRoles = $this->provider->getPermissionRoles($roles);

        foreach ($cRoles as $role) {
            $mapRoles[$role->getName()] = $role;
        }

        /** @var SubjectIdentityInterface $subject */
        foreach ($idSubjects as $id => $subject) {
            foreach ($this->cacheRoleSharing[$id] as $roleId) {
                if (isset($mapRoles[$roleId])) {
                    $cRole = $mapRoles[$roleId];

                    foreach ($cRole->getPermissions() as $perm) {
                        $class = $subject->getType();
                        $field = PermissionUtils::getMapAction($perm->getField());
                        $this->cacheSharing[$id][$class][$field][$perm->getOperation()] = true;
                    }
                }
            }
        }
    }
428975
private void addRolesToSubject(Subject subject, Set<String> userRoles) {
        if (userRoles == null) {
            userRoles = Collections.emptySet();
        }

        Map<String, Set<String>> attributes =
                SubjectUtils.getAttributes(subject);

        Set<String> roles = attributes.get(ROLE_KEY);
        if (roles == null) {
            roles = new HashSet<String>(userRoles);
            attributes.put(ROLE_KEY, roles);
        } else {
            roles.addAll(userRoles);
        }
        if (logger.isDebugEnabled()) {
            for (String role : userRoles) {
                logger.debug("added role: {}", role);
            }
        }
    }
835570
private function deletePersonalWorkspace($all, $rolesSearch, $includeOrphans)
    {
        $empty = $this->getInput()->getOption('empty');
        $workspaceManager = $this->getContainer()->get('claroline.manager.workspace_manager');
        $workspacesToDelete = $all ?
            $workspaceManager->getPersonalWorkspaceExcludingRoles($rolesSearch, $includeOrphans, $empty, null, self::BATCH_SIZE) :
            $workspaceManager->getPersonalWorkspaceByRolesIncludingGroups($rolesSearch, $includeOrphans, $empty, null, self::BATCH_SIZE);

        if (count($workspacesToDelete) > 0) {
            $this->confirmWorkspaceDelete($workspacesToDelete);
            $this->deletePersonalWorkspace($all, $rolesSearch, $includeOrphans);
        }
    }
327938
private function deleteRolesByEntityIds(EntityRepository $repository, array $entityIds)
    {
        $qb = $repository->createQueryBuilder('role')
            ->delete()
            ->where('role.entityId IN (:ids)')
            ->setParameter('ids', $entityIds);

        $qb->getQuery()->execute();
    }
752122
public function getArrayRolesByWorkspace(Workspace $workspace)
    {
        $workspaceRoles = [];
        $uow = $this->om->getUnitOfWork();
        $wRoles = $this->roleManager->getRolesByWorkspace($workspace);
        $scheduledForInsert = $uow->getScheduledEntityInsertions();

        foreach ($scheduledForInsert as $entity) {
            if ('Claroline\CoreBundle\Entity\Role' === get_class($entity)) {
                if ($entity->getWorkspace()) {
                    if ($entity->getWorkspace()->getGuid() === $workspace->getGuid()) {
                        $wRoles[] = $entity;
                    }
                }
            }
        }
        //now we build the array
        foreach ($wRoles as $wRole) {
            $workspaceRoles[$wRole->getTranslationKey()] = $wRole;
        }

        return $workspaceRoles;
    }
652578
public function deleteWorkspace(Workspace $workspace)
    {
        $this->om->startFlushSuite();
        $root = $this->resourceManager->getWorkspaceRoot($workspace);
        $this->log('Removing root directory ' . $root->getName() . '[id:' . $root->getId() . ']');

        if ($root) {
            $children = $root->getChildren();
            $this->log('Looping through ' . count($children) . ' children...');

            if ($children) {
                foreach ($children as $node) {
                    $this->resourceManager->delete($node);
                }
            }
        }
        $this->dispatcher->dispatch(
            'claroline_workspaces_delete',
            'GenericDatas',
            array(array($workspace))
        );
        $this->om->remove($workspace);
        $this->om->endFlushSuite();
    }