@param Role         $role
@param ResourceNode $node

@return ResourceRights $resourceRights
559985
public function getOneByRoleAndResource(Role $role, ResourceNode $node)
    {
        /** @var ResourceRights $resourceRights */
        $resourceRights = $this->rightsRepo->findOneBy(['resourceNode' => $node, 'role' => $role]);
        if ($resourceRights) {
            return $resourceRights;
        }

        $resourceRights = new ResourceRights();
        $resourceRights->setResourceNode($node);
        $resourceRights->setRole($role);

        return $resourceRights;
    }
807788
public function isWorkspaceOwnerOf(ResourceNode $node, TokenInterface $token)
    {
        $workspace = $node->getWorkspace();
        $managerRoleName = 'ROLE_WS_MANAGER_' . $workspace->getGuid();

        return in_array($managerRoleName, $this->secut->getRoles($token)) ? true: false;
    }
594085
public function findRootPageByResourceNode(ResourceNode $resourceNode)
    {
        return $this->createQueryBuilder('page')
            ->leftJoin('page.website', 'website')
            ->leftJoin('website.resourceNode', 'resource')
            ->where('resource = :resourceNode')
            ->andWhere('page.type = :type')
            ->setParameter('resourceNode', $resourceNode)
            ->setParameter('type', 'root')
            ->getQuery()
            ->getSingleResult();
    }
117454
public function rolePermissionAdd(Role $role, Permission $permission)
    {
        return $this->storage->rolePermissionAdd($role, $permission);
    }
432725
public function removeRole(Role $role)
    {
        $this->initializeRoles();
        if ($this->hasRole($role)) {
            $roleIdentifier = $role->getIdentifier();
            unset($this->roles[$roleIdentifier]);
            $identifierIndex = array_search($roleIdentifier, $this->roleIdentifiers);
            unset($this->roleIdentifiers[$identifierIndex]);
        }
    }
1223098
public function storeRolePermission(Role $role, Permission $permission)
    {
        $this->getTable()->insert([
            'role' => $role->getRoleName(),
            'type' => $permission->getType(),
            'action' => $permission->getAction(),
            'resource_type' => $permission->getResourceType(),
            'resource_id' => $permission->getResourceId(),
        ]);

        $this->resetPermissionsCacheForRole($role);
    }
238399
public function handleAddAcl(string $role, string $resource = null, string $privilege = null)
    {
        $idRole = $this->identityAuthorizator->getIdRoleByName($role);

        $idResource = null;
        if ($resource) {
            $idResource = $this->identityAuthorizator->getIdResourceByName($resource);
        }

        $idPrivilege = null;
        if ($privilege) {
            $idPrivilege = $this->identityAuthorizator->getIdPrivilegeByName($privilege);
            if (!$idPrivilege) {
                $this->identityAuthorizator->savePrivilege(['id' => null, 'privilege' => $privilege]);
                $idPrivilege = $this->identityAuthorizator->getIdPrivilegeByName($privilege);
            }
        } else {
            $idPrivilege = 'all';
        }

        if ($idResource && $idPrivilege) {
            // save acl by one
            if ($this->identityAuthorizator->saveAcl($idRole, [$idResource => [$idPrivilege]], false)) {
                $this->flashMessage('Save ACL');
            }
        }
        $this->redirect('this');
    }
147317
public function addRole(Role $role)
    {
        if (!in_array($role, $this->roles)) {
            $this->roles[] = $role;
            return true;
        }
        return false;
    }
921288
public function update(Role $role, Request $request)
    {
        $this->validate($request, Role::$rules, Role::$messages);

        $this->updateEntry($role, $request->all());

        return redirect_to_resource();
    }
804832
public function update(Role $role)
    {
        $this->validate($this->request, [
            'name'        => 'required',
            'slug'        => 'required|unique:roles,slug,' . $role->id,
        ]);

        $role->name = $this->request->get('name');
        if (! $role->system) {
            $role->slug = $this->request->get('slug');
        }
        $role->save();

        $role->syncPermissions($this->request->get('permissions', []));
        flash()->success('Role ' . $role->name . ' successfully updated!');

        return redirect()->route('administrator.roles.index');
    }
315640
public function findMaximumRights(array $roles, ResourceNode $resource)
    {
        //add the role anonymous for everyone !
        if (!in_array('ROLE_ANONYMOUS', $roles)) {
            $roles[] = 'ROLE_ANONYMOUS';
        }

        $dql = '
            SELECT rrw.mask
            FROM Claroline\CoreBundle\Entity\Resource\ResourceRights rrw
            JOIN rrw.role role
            JOIN rrw.resourceNode resource
            WHERE ';

        $index = 0;

        foreach ($roles as $key => $role) {
            $dql .= 0 !== $index ? ' OR ' : '';
            $dql .= "resource.id = {$resource->getId()} AND role.name = :role{$key}";
            ++$index;
        }

        $query = $this->_em->createQuery($dql);

        foreach ($roles as $key => $role) {
            $query->setParameter("role{$key}", $role);
        }

        $results = $query->getResult();
        $mask = 0;

        foreach ($results as $result) {
            $mask |= $result['mask'];
        }

        return $mask;
    }
900026
public function deserialize($data, Role $role, array $options = [])
    {
        // TODO : set readOnly based on role type
        if (!$role->isReadOnly()) {
            $this->sipe('name', 'setName', $data, $role);

            $this->sipe('type', 'setType', $data, $role);
            if (isset($data['translationKey'])) {
                $role->setTranslationKey($data['translationKey']);
                //this is if it's not a workspace and we send the translationKey role
                if (null === $role->getName() && !isset($data['workspace'])) {
                    $role->setName('ROLE_'.str_replace(' ', '_', strtoupper($data['translationKey'])));
                }
            }
        }

        $this->sipe('meta.personalWorkspaceCreationEnabled', 'setPersonalWorkspaceCreationEnabled', $data, $role);
        $this->sipe('restrictions.maxUsers', 'setMaxUsers', $data, $role);

        // we should test role type before trying to set the workspace
        if (!empty($data['workspace']) && !empty($data['workspace']['uuid'])) {
            if (isset($data['workspace']['uuid'])) {
                $workspace = $this->om->getRepository('ClarolineCoreBundle:Workspace\Workspace')
                    ->findOneBy(['uuid' => $data['workspace']['uuid']]);
                $role->setName('ROLE_WS_'.str_replace(' ', '_', strtoupper($data['translationKey'])).'_'.$data['workspace']['uuid']);

                if ($workspace) {
                    $role->setWorkspace($workspace);
                }
            }
        }

        // TODO : set the user for ROLE_USER

        if (isset($data['adminTools'])) {
            $adminTools = $this->om->getRepository('ClarolineCoreBundle:Tool\AdminTool')->findAll();

            /** @var AdminTool $adminTool */
            foreach ($adminTools as $adminTool) {
                if ($data['adminTools'][$adminTool->getName()]) {
                    $adminTool->addRole($role);
                } else {
                    $adminTool->removeRole($role);
                }
            }
        }

        // sets rights for workspace tools
        if (isset($data['tools']) && in_array(Options::SERIALIZE_ROLE_TOOLS_RIGHTS, $options)) {
            foreach ($data['tools'] as $toolName => $toolData) {
                $tool = $this->om->getRepository('ClarolineCoreBundle:Tool\Tool')->findOneBy(['name' => $toolName]);

                if ($tool) {
                    // TODO: Fix option for workspace uuid. For the moment the uuid of the workspace is prefixed with `workspace_id_`.
                    $workspaceId = null;

                    foreach ($options as $option) {
                        if ('workspace_id_' === substr($option, 0, 13)) {
                            $workspaceId = substr($option, 13);
                            break;
                        }
                    }
                    if ($workspaceId) {
                        $orderedTool = $this->orderedToolFinder
                          ->findOneBy(['tool' => $toolName, 'workspace' => $workspaceId]);

                        if ($orderedTool) {
                            $toolRights = $this->om
                                ->getRepository('ClarolineCoreBundle:Tool\ToolRights')
                                ->findBy(['orderedTool' => $orderedTool, 'role' => $role], ['id' => 'ASC']);

                            if (0 < count($toolRights)) {
                                $rights = $toolRights[0];
                            } else {
                                $rights = new ToolRights();
                                $rights->setRole($role);
                                $rights->setOrderedTool($orderedTool);
                            }
                            $mask = 0;

                            foreach (ToolMaskDecoder::$defaultActions as $action) {
                                if (isset($toolData[$action]) && $toolData[$action]) {
                                    $mask += ToolMaskDecoder::$defaultValues[$action];
                                }
                            }
                            $rights->setMask($mask);
                            $this->om->persist($rights);
                        }
                    }
                }
            }
        }

        // Sets desktop tools configuration for platform roles
        if (Role::PLATFORM_ROLE === $role->getType() && isset($data['desktopTools'])) {
            foreach ($data['desktopTools'] as $toolName => $toolData) {
                $tool = $this->om->getRepository(Tool::class)->findOneBy(['name' => $toolName]);

                if ($tool) {
                    $toolRole = $this->om->getRepository(ToolRole::class)->findOneBy(['tool' => $tool, 'role' => $role]);

                    if (!$toolRole) {
                        $toolRole = new ToolRole();
                        $toolRole->setTool($tool);
                        $toolRole->setRole($role);
                    }
                    $toolRole->setDisplay($toolData);
                    $this->om->persist($toolRole);
                }
            }
        }

        return $role;
    }
1137708
private function processRole(string $role, int $resource_id, string $method_code, int $action_id, $module_id = null) : int {
		// load all roles from datasource
		if (is_null(self::$cached_roles) && !\Object\Error\Base::$flag_database_tenant_not_found) {
			self::$cached_roles = \Object\ACL\Resources::getStatic('roles', 'primary');
		}
		// if role is not found
		if (empty(self::$cached_roles[$role])) return 0;
		// process permissions
		$all_actions = self::$cached_roles[$role]['permissions'][$resource_id]['AllActions'][-1] ?? [];
		$actual_action = self::$cached_roles[$role]['permissions'][$resource_id][$method_code][$action_id] ?? [];
		$temp = array_merge_hard($all_actions, $actual_action);
		if (!empty($temp)) {
			if (!empty($module_id)) {
				$temp = $temp[$module_id] ?? null;
			} else { // find any active permision
				$temp2 = $temp;
				$temp = null;
				foreach ($temp2 as $k => $v) {
					if ($v === 0) {
						$temp = 0;
						break;
					}
				}
			}
		}
		if ($temp === 0) {
			return 1;
		} else if ($temp === 1) {
			return 2;
		}
		// super admin
		if (!empty(self::$cached_roles[$role]['super_admin'])) return 1;
		// if permission is not found we need to check parents
		if (empty(self::$cached_roles[$role]['parents'])) return 0;
		// go though parents
		foreach (self::$cached_roles[$role]['parents'] as $k => $v) {
			if (!empty($v)) continue;
			$temp = $this->processRole($k, $resource_id, $method_code, $action_id);
			if ($temp === 1) {
				return 1;
			} else if ($temp === 2) {
				return 2;
			}
		}
		return 0;
	}
765879
public function findOneByRole($role)
    {
        $query = ' SELECT a'
                . ' FROM CoreBundle:BaseActor a'
                . " JOIN a.roles r  "
                . " WHERE r.role =  'ROLE_SUPER_ADMIN' "
                ;
        $q = $this->getEntityManager()->createQuery($query);
        return  $q->getOneOrNullResult();
        
    }
824658
public function getConfigurableRights(ResourceNode $node)
    {
        $existing = $this->rightsRepo->findConfigurableRights($node);
        $roles = $node->getWorkspace()->getRoles();
        $missings = [];

        foreach ($roles as $role) {
            $found = false;
            foreach ($existing as $right) {
                if ($right->getRole()->getId() === $role->getId()) {
                    $found = true;
                }
            }

            if (!$found) {
                $missings[] = $role;
            }
        }

        if (0 === count($missings)) {
            return $existing;
        }

        // might be slow on large data trees
        foreach ($missings as $missing) {
            $this->create([], $missing, $node, true, []);
        }

        return $this->rightsRepo->findConfigurableRights($node);
    }
1022262
public function removeRole(ChildRole $role)
    {
        if ($this->getRoles()->contains($role)) { $rolePermission = new ChildRolePermission();

            $rolePermission->setRole($role);
            if ($role->isPermissionsLoaded()) {
                //remove the back reference if available
                $role->getPermissions()->removeObject($this);
            }

            $rolePermission->setPermission($this);
            $this->removeRolePermission(clone $rolePermission);
            $rolePermission->clear();

            $this->collRoles->remove($this->collRoles->search($role));

            if (null === $this->rolesScheduledForDeletion) {
                $this->rolesScheduledForDeletion = clone $this->collRoles;
                $this->rolesScheduledForDeletion->clear();
            }

            $this->rolesScheduledForDeletion->push($role);
        }


        return $this;
    }
377985
public function remove(Role $role)
    {
        $role->delete();

        Alert::info(__('Role was removed'));

        return redirect()->route('platform.systems.roles');
    }