Creates unique role assignments for the securable object.
@param bool $copyRoleAssignments
495033
public function breakRoleInheritance($copyRoleAssignments)
    {
        $qry = new InvokePostMethodQuery($this->getResourcePath(),"breakroleinheritance",array(
            $copyRoleAssignments
        ));
        $this->getContext()->addQuery($qry);
    }
143139
public function detachRoles($roles=null)
    {
        if (!$roles) $roles = $this->roles()->get();

        foreach ($roles as $role) {
            $this->detachRole($role);
        }
    }
369547
public function assignProfiles($profiles) : void
    {
        $profiles = (array) $profiles;
        foreach ($profiles as $profile) {
            $electedProfile = Profile::where('code', $profile)->first();

            // Profile exists and not assigned to user?
            if (!is_null($electedProfile) && !$this->hasProfile($profile)) {
                // Assign both role and permissions defined for this user profile.
                // Into the Spatie Permissions.
                $this->assignRole(Role::find([$electedProfile->role_id])->first()->name);
                $this->givePermissionTo(Permission::find([$electedProfile->permission_id])->first()->name);

                // Assign user profile into the profiles table.
                $this->profiles()->save($electedProfile);
            }
        }
    }
1305065
public function syncRoles(...$roles): self
    {
        $roles = array_flatten($roles);
        $roles = $this->getRoles($roles);

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

        return $this;
    }
1109260
public function setNewRoles($newRoles)
    {
        $allowedValues = $this->getNewRolesAllowableValues();
        if (array_diff($newRoles, $allowedValues)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value for 'newRoles', must be one of '%s'",
                    implode("', '", $allowedValues)
                )
            );
        }
        $this->container['newRoles'] = $newRoles;

        return $this;
    }
1284197
public static function assign_roles($assignments) {
        global $DB;

        // Do basic automatic PARAM checks on incoming data, using params description
        // If any problems are found then exceptions are thrown with helpful error messages
        $params = self::validate_parameters(self::assign_roles_parameters(), array('assignments'=>$assignments));

        $transaction = $DB->start_delegated_transaction();

        foreach ($params['assignments'] as $assignment) {
            // Ensure correct context level with a instance id or contextid is passed.
            $context = self::get_context_from_params($assignment);

            // Ensure the current user is allowed to run this function in the enrolment context.
            self::validate_context($context);
            require_capability('moodle/role:assign', $context);

            // throw an exception if user is not able to assign the role in this context
            $roles = get_assignable_roles($context, ROLENAME_SHORT);

            if (!array_key_exists($assignment['roleid'], $roles)) {
                throw new invalid_parameter_exception('Can not assign roleid='.$assignment['roleid'].' in contextid='.$assignment['contextid']);
            }

            role_assign($assignment['roleid'], $assignment['userid'], $context->id);
        }

        $transaction->allow_commit();
    }
429894
public function setRoles(array $roles = array())
    {
        if ($this->instance instanceof \Phavour\Session\Storage) {
            if ($this->instance->isLocked()) {
                $this->instance->unlock();
            }
            $this->instance->set('roles', $roles);
            $this->instance->lock();
            return true;
        }

        return false;
    }
260335
public function createRole(RoleAssignment $roleAssignment): UIValue\User\Role
    {
        return new UIValue\User\Role($roleAssignment);
    }
1139957
public Authorizations setRoles(Set<Role> roles) {
        this.roles.clear();
        this.aggregatePermissions = null;
        addRoles(roles);

        return this;
    }
121427
public function setRoles(\WobbleCode\UserBundle\Document\Role $roles)
    {
        $this->roles = $roles;

        return $this;
    }
870946
public function assignTasksRoles(array $roles)
    {
        foreach ($roles as $roles => $tasks) {
            $tasks = (array) $tasks;
            $roles = (array) $roles;

            foreach ($tasks as $task) {
                $this->builder->buildTask($task)->addRoles($roles);
            }
        }
    }
1124277
private function validateRole($role, $roles, $checkExistence = true)
    {
        if (empty($roles)) {
            return null;
        }

        $roleExists = array_key_exists($role, $roles);
        $condition =  $checkExistence ? !$roleExists : $roleExists;
        if ($condition) {
            $errorMessage = $checkExistence ? "Role %s doesn't exist" : 'Role %s already exists';
            throw new \InvalidArgumentException(sprintf($errorMessage, $role));
        }

        return $role;
    }
301675
public function whereHasRoleIn(array $roles)
    {
        $managerRoles = array();
        $otherRoles = array();

        foreach ($roles as $role) {
            $roleName = $role instanceof RoleInterface ? $role->getRole() : $role;

            if (preg_match('/^ROLE_WS_MANAGER_/', $roleName)) {
                $managerRoles[] = $roleName;
            } else {
                $otherRoles[] = $roleName;
            }
        }

        $eol = PHP_EOL;

        if (count($otherRoles) > 0 && count($managerRoles) === 0) {
            $this->leftJoinRights = true;
            $clause = "{$eol}({$eol}";
            $clause .= "rightRole.name IN (:roles){$eol}";
            $this->parameters[":roles"] = $otherRoles;
            $clause .= "AND{$eol}BIT_AND(rights.mask, 1) = 1{$eol})";
            $this->addWhereClause($clause);
        } elseif (count($otherRoles) === 0 && count($managerRoles) > 0) {
            $this->leftJoinRoles = true;
            $clause = "{$eol}({$eol}";
            $clause .= "role.name IN (:roles){$eol}";
            $this->parameters[":roles"] = $managerRoles;
            $this->addWhereClause($clause . ')');
        } elseif (count($otherRoles) > 0 && count($managerRoles) > 0) {
            $this->leftJoinRoles = true;
            $this->leftJoinRights = true;
            $clause = "{$eol}({$eol}({$eol}";
            $clause .= "rightRole.name IN (:otherroles){$eol}";
            $this->parameters[":otherroles"] = $otherRoles;
            $clause .= "AND{$eol}BIT_AND(rights.mask, 1) = 1{$eol}){$eol}";
            $clause .= "OR{$eol}";
            $clause .= "role.name IN (:managerroles){$eol}";
            $this->parameters[":managerroles"] = $managerRoles;
            $this->addWhereClause($clause . ")");
        }

        return $this;
    }
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;
    }
1000027
public function loadRoleAssignment($roleAssignmentId)
    {
        $query = $this->handler->createSelectQuery();
        $query->select(
            $this->handler->quoteColumn('id'),
            $this->handler->quoteColumn('contentobject_id'),
            $this->handler->quoteColumn('limit_identifier'),
            $this->handler->quoteColumn('limit_value'),
            $this->handler->quoteColumn('role_id')
        )->from(
            $this->handler->quoteTable('ezuser_role')
        )->where(
            $query->expr->eq(
                $this->handler->quoteColumn('id'),
                $query->bindValue($roleAssignmentId, null, \PDO::PARAM_INT)
            )
        );

        $statement = $query->prepare();
        $statement->execute();

        return $statement->fetchAll(\PDO::FETCH_ASSOC);
    }
140809
private function setUserRoles()
    {
        $this->initRoleHierarchy();
        $this->user->setRoles($this->roleHierarchy->getAccessibleRoles($this->user->getRoles()));
    }
960163
public function changeRoles($roleRepository, $roleMapping = null)
    {
        $this->repositories['role'] = $roleRepository;
        $this->mappings['role'] = $roleMapping ?: $this->mappings['role'];

        return $this;
    }