@EXT\Route(
"/role/{role}/increase/{amount}",
name="platform_role_increase_limit",
options={"expose"=true}
)
@EXT\Method("POST")

@param Role $role
@return JsonResponse
430482
public function increaseRoleMaxUsers(Role $role, $amount)
    {
        if ($amount < 0) {
            return new JsonResponse(
                array(
                    'name' => $role->getName(),
                    'limit' => $role->getMaxUsers(),
                    'translationKey' => $role->getTranslationKey(),
                    'error' => 'negative_amount_increased'
                ),
                500
            );
        }
        $this->roleManager->increaseRoleMaxUsers($role, $amount);

        return new JsonResponse(
            array(
                'name' => $role->getName(),
                'limit' => $role->getMaxUsers(),
                'translationKey' => $role->getTranslationKey()
            )
        );
    }
121334
public function updateAction(Request $request, Role $role)
    {
        $this->isAllowed('BUSINESS_MANAGE_ROLE');

        $em = $this->getDoctrine()->getManager();

        if (!$role) {
            throw $this->createNotFoundException('Unable to find Role entity.');
        }

        $editForm = $this->createEditForm($role);
        $editForm->handleRequest($request);

        if ($editForm->isValid()) {
            $em->flush();
            $this->get('session')->getFlashBag()->add('success', 'role.flash.updated');

            return $this->redirect($this->generateUrl('sam_role'));
        }

        return $this->render('CanalTPSamEcoreSecurityBundle:Role:edit.html.twig', array(
            'entity'      => $role,
            'edit_form'   => $editForm->createView()
        ));
    }
777427
public function deleteAction(Request $request, Role $role): Response
    {
        $this->denyAccessUnlessGranted(new Attribute('role', 'delete'));
        $form = $this->formFactory->deleteRole(
            new RoleDeleteData($role)
        );
        $form->handleRequest($request);

        if ($form->isSubmitted()) {
            $result = $this->submitHandler->handle($form, function (RoleDeleteData $data) {
                $role = $data->getRole();
                $this->roleService->deleteRole($role);

                $this->notificationHandler->success(
                    $this->translator->trans(
                        /** @Desc("Role '%role%' removed.") */
                        'role.delete.success',
                        ['%role%' => $role->identifier],
                        'role'
                    )
                );

                return new RedirectResponse($this->generateUrl('ezplatform.role.list'));
            });

            if ($result instanceof Response) {
                return $result;
            }
        }

        return $this->redirect($this->generateUrl('ezplatform.role.view', [
            'roleId' => $role->id,
        ]));
    }
377985
public function remove(Role $role)
    {
        $role->delete();

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

        return redirect()->route('platform.systems.roles');
    }
1013271
public function updated(Role $role)
    {
        $oldRole = new Role($role->getOriginal());
        $oldRoleName = $oldRole->snake_case_name;
        $newRoleName = $role->snake_case_name;
        if ($newRoleName != $oldRoleName) {
            $this->updateLanguageTerm($oldRoleName, $newRoleName);
        }
    }
117454
public function rolePermissionAdd(Role $role, Permission $permission)
    {
        return $this->storage->rolePermissionAdd($role, $permission);
    }
616868
public function bulkDeleteAction(Request $request, Role $role): Response
    {
        $this->denyAccessUnlessGranted(new Attribute('role', 'assign'));
        $form = $this->formFactory->deleteRoleAssignments(
            new RoleAssignmentsDeleteData()
        );
        $form->handleRequest($request);

        if ($form->isSubmitted()) {
            $result = $this->submitHandler->handle($form, function (RoleAssignmentsDeleteData $data) use ($role) {
                foreach ($data->getRoleAssignments() as $roleAssignmentId => $selected) {
                    $roleAssignment = $this->roleService->loadRoleAssignment($roleAssignmentId);
                    $this->roleService->removeRoleAssignment($roleAssignment);
                }

                $this->notificationHandler->success(
                    $this->translator->trans(
                        /** @Desc("Assignment on role '%role%' removed.") */
                        'role.assignment_delete.success',
                        ['%role%' => $role->identifier],
                        'role'
                    )
                );

                return new RedirectResponse($this->generateUrl('ezplatform.role.view', [
                    'roleId' => $role->id,
                ]));
            });

            if ($result instanceof Response) {
                return $result;
            }
        }

        return $this->redirect($this->generateUrl('ezplatform.role.view', [
            'roleId' => $role->id,
        ]));
    }
67131
public function attachRole($role)
    {
        if (! $this->hasRole($role->name)) {
            $this->roles()->attach($role);
        }
    }
568442
public function attachRole($role)
    {
        if(is_object($role)) {
            $role = $role->getKey();
        }

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

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

        self::clearCache();
    }
1063581
public function addRole(Role $role)
    {
        if ($role->isAbstract()) {
            throw new \InvalidArgumentException(sprintf('Abstract roles can\'t be assigned to accounts directly, but the role "%s" is marked abstract', $role->getIdentifier()), 1399900657);
        }
        $this->initializeRoles();
        if (!$this->hasRole($role)) {
            $roleIdentifier = $role->getIdentifier();
            $this->roleIdentifiers[] = $roleIdentifier;
            $this->roles[$roleIdentifier] = $role;
        }
    }
974588
protected function updateRole($role_id)
    {
        if (!$this->isError() && !$this->role->update($role_id, $this->getSubmitted())) {
            $this->errorAndExit($this->text('Unexpected result'));
        }
    }
1317783
public function grantUserRole($user, $role)
    {
        $params = [
            'user' => $user,
            'role' => $role,
        ];

        $body = $this->request(self::URI_AUTH_USER_GRANT, $params);

        return $body;
    }
437307
public function assignRole($role)
    {
        return $this->mapArray($role, function ($role) {

            $roleId = $this->parseRoleId($role);

            if ( ! $this->roles->keyBy('id')->has($roleId) ) {
                $this->roles()->attach($roleId);

                return $role;
            }

            return false;
        });
    }
39604
public function addRole($id, $role)
    {
        if (empty($role) || !$user = $this->getUser($id)) {
            return false;
        }

        // Add the role to the $user['roles'] array
        $user['roles'][] = $role;

        return $this->saveUser($user);
    }
1087330
public function assignRole($role)
    {
        if (Role::count() === 0) {
            throw new \Exception('No roles have been created.');
        }

        return $this->roles()->save(
            Role::whereName($role)->firstOrFail()
        );
    }
1215383
public function createWithLimitationAction(Request $request, Role $role, string $policyModule, string $policyFunction): Response
    {
        $this->denyAccessUnlessGranted(new Attribute('role', 'update'));
        $form = $this->formFactory->createPolicyWithLimitation(
            (new PolicyCreateData())->setPolicy([
                'module' => $policyModule,
                'function' => $policyFunction,
            ])
        );
        $form->handleRequest($request);

        if ($form->isSubmitted()) {
            $result = $this->submitHandler->handle($form, function (PolicyCreateData $data) use ($role) {
                $policyCreateStruct = $this->policyCreateMapper->reverseMap($data);
                $roleDraft = $this->roleService->createRoleDraft($role);
                $roleDraft = $this->roleService->addPolicyByRoleDraft($roleDraft, $policyCreateStruct);
                $this->roleService->publishRoleDraft($roleDraft);

                $this->notificationHandler->success(
                    $this->translator->trans(
                        /** @Desc("New policies in role '%role%' created.") */
                        'policy.add.success',
                        ['%role%' => $role->identifier],
                        'role'
                    )
                );

                return new RedirectResponse($this->generateUrl('ezplatform.role.view', [
                    'roleId' => $role->id,
                ]));
            });

            if ($result instanceof Response) {
                return $result;
            }
        }

        return $this->render('@ezdesign/admin/policy/create_with_limitation.html.twig', [
            'role' => $role,
            'form' => $form->createView(),
        ]);
    }
697570
public function roleSave(Role $role)
    {
        if ($role->role_id) {
            $query = "
                UPDATE
                    auth_role
                SET
                    `name` = :name, description = :description, updated_on = " . $this->sql_time_func . "
                WHERE
                    role_id = :role_id
            ";
        } else {
            $query = "
                INSERT INTO auth_role
                    (name, description, added_on, updated_on)
                VALUES
                    (:name, :description, " . $this->sql_time_func . ", " . $this->sql_time_func . ")
            ";
        }
        $cur = $this->db->prepare($query);
        $cur->bindParam(":name", $role->name, PDO::PARAM_STR, 32);
        $cur->bindParam(":description", $role->description, PDO::PARAM_STR);
        if ($role->role_id) {
            $cur->bindParam(":role_id", $role->role_id, PDO::PARAM_INT);
        }
        $this->db->beginTransaction();
        try {
            $cur->execute();
            if (!$role->role_id) {
                $role->role_id = (int)$this->db->lastInsertId();
            }
            $this->db->commit();
        } catch (PDOException $db_err) {
            $this->db->rollBack();
            if ($this->logger) {
                $this->logger->error("Failed to save role to DB", ['exception' => $db_err]);
            }
            return false;
        }
        foreach ($role->getPermissions() as $permission) {
            // TODO: Something on fail
            $this->rolePermissionAdd($role, $permission);
        }

        return true;
    }