@param \Symfony\Component\HttpFoundation\Request $request
@param \eZ\Publish\API\Repository\Values\User\Role $role

@return \Symfony\Component\HttpFoundation\Response
501942
public function createAction(Request $request, Role $role): Response
    {
        $this->denyAccessUnlessGranted(new Attribute('role', 'assign'));
        $form = $this->formFactory->createRoleAssignment(new RoleAssignmentCreateData());
        $form->handleRequest($request);

        if ($form->isSubmitted()) {
            $result = $this->submitHandler->handle($form, function (RoleAssignmentCreateData $data) use ($role) {
                foreach ($this->createLimitations($data) as $limitation) {
                    foreach ($data->getUsers() as $user) {
                        $this->roleService->assignRoleToUser($role, $user, $limitation);
                    }
                    foreach ($data->getGroups() as $group) {
                        $this->roleService->assignRoleToUserGroup($role, $group, $limitation);
                    }
                }

                $this->notificationHandler->success(
                    $this->translator->trans(
                        /** @Desc("Assignments on role '%role%' created.") */
                        'role.assignment_create.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/role_assignment/create.html.twig', [
            'role' => $role,
            'form' => $form->createView(),
        ]);
    }
75206
public function actionRole($user, $operation, $role)
    {
        $user = $this->getUser($user);
        $role = Yii::$app->authManager->getRole($role);
        if ($operation == 'assign') {
            try {
                $assignment = Yii::$app->authManager->assign($role, $user);
            } catch (\yii\db\IntegrityException $ex) {
                echo "Failed to assign `" . $role->name . "`.\n";
                echo "Maybe the role has been assigned.\n";
                return static::EXIT_CODE_ERROR;
            }
            if ($assignment) {
                echo "`$role->name`" . " assigned to User (" . $user->getID() . ") successfully.\n";
            } else {
                echo "Failed to assign `" . $role->name . "`.\n";
            }
            return static::EXIT_CODE_NORMAL;
        }
        if ($operation == 'revoke') {
            $assignment = Yii::$app->authManager->revoke($role, $user);
            if ($assignment) {
                echo "`$role->name`" . " revoked from User (" . $user->getID() . ").\n";
            } else {
                echo "Failed to revoke `" . $role->name . "`.\n";
                echo "Maybe the role has not been assigned yet.\n";
            }
            return static::EXIT_CODE_NORMAL;
        }
        echo "Unrecognized operation: $operation.\n";
        echo "The accepted operations are `assign` and `revoke`.\n";
        return static::EXIT_CODE_ERROR;
    }
552678
public function addRole(Role $role): bool
    {
        return (new actions\AddRole($this->user, $role))->execute();
    }
197854
public function getRole($role = null)
    {
        /* @var $roleItem RoleInterface */
        foreach ($this->roles as $roleItem) {
            if ($role == $roleItem->getRole()) {
                return $roleItem;
            }
        }

        return null;
    }
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()}'.");
    }
1221673
public function addRole($role)
    {
        if (!$this->hasRole($role)) {
            $this->roles[] = strtoupper($role);
        }

        return $this;
    }
862732
public function validateRole($role)
    {
        $roleValidator = new RoleValidator();
        $response = $roleValidator->validate($role);

        if (!$response) {
            $this->addError('role', 'Role must be a valid instance of Role class - ' . $roleValidator->getErrorsAsString());
        }

        return $response;
    }
960053
public function role(Request $request)
    {
        if($request->get('_ajax')) {
            $ename = $request->input('ename');
            $parent = $request->input('parent');
            $uri = $request->input('uri');
            $query = CommonRoleUriModel::where('id', '>', 0);
            if($ename) {
                $query->where('ename', $ename);
            }
            if($uri) {
                $query->where('uri', $uri);
            }
            if($parent) {
                $query->where('parent', $parent);
            }
            $list = $query->orderby('id', 'desc')->paginate($this->paginate);
            $this->addMessage($list, 'list');
            return $this->showMessage('Hstcms::public.successful');
        }
        $view = [
            'navs'=>$this->getNavs('operation')
        ];
        $this->navs = [
            'nav'=>['name'=>hst_lang('hstcms::public.menu'), 'url'=>'manageMenuNav'],
            'role'=>['name'=>hst_lang('hstcms::manage.role.uri'), 'url'=>'manageMenuRole'],
            'add'=>['name'=>hst_lang('hstcms::public.add', 'hstcms::manage.role.uri'), 'url'=>'manageMenuRoleAdd', 'class'=>'J_dialogs', 'title'=>hst_lang('hstcms::public.add', 'hstcms::manage.role.uri')]
        ];
        $view = [
            'navs'=>$this->getNavs('role')
        ];
        return $this->loadTemplate('menu.role', $view);
    }
847950
public function handle($request, Closure $next, $role = 'super')
    {
        $roles = auth('admin')->user()->/* @scrutinizer ignore-call */roles()->pluck('name');
        if (in_array('super', $roles->toArray())) {
            return $next($request);
        }

        if (!in_array(strtolower($role), $roles->toArray())) {
            return redirect(route('admin.home'));
        }

        return $next($request);
    }
476148
public function postAction(Request $request)
    {
        $name = $request->get('name');

        if (null != $name) {
            $em = $this->getDoctrine()->getManager();

            $group = new Group();
            $group->setName($name);

            $this->setParent($group, $request);

            $roles = $request->get('roles');
            if (!empty($roles)) {
                foreach ($roles as $roleData) {
                    $this->addRole($group, $roleData);
                }
            }

            $em->persist($group);
            $em->flush();

            $view = $this->view($group, 200);
        } else {
            $view = $this->view(null, 400);
        }

        return $this->handleView($view);
    }
479737
public function destroy(Role $role)
    {
        if (! $role->system) {
            try {
                $role->delete();

                return $this->notifySuccess('Role successfully deleted!');
            } catch (QueryException $e) {
                return $this->notifyError($e->getMessage());
            }
        }

        return $this->notifyError('Role is protected and cannot be deleted!');
    }
50828
public function permissions(Role $role)
    {
        $this->authorize('manage_permissions', Role::class);

        return view('laralum_roles::permissions', ['permissions' => Permission::all(), 'role' => $role]);
    }
322445
public function hasRole($role, $user = null)
    {
        $roleName = $role instanceof Role ? $role->getRole() : $role;

        $user = $user ?: $this->getUser();

        if (!($user instanceof UserInterface)) {
            return false;
        }

        if (null === $this->roleHierarchy) {
            return in_array($roleName, $user->getRoles(), true);
        }

        $userRoles = $this->roleHierarchy->getReachableRoles($this->getUserRolesAsObjects($user));
        foreach ($userRoles as $userRole) {
            if ($roleName === $userRole->getRole()) {
                return true;
            }
        }

        return false;
    }
793055
public function switchRole($role)
    {
        if ($this->isAuthenticated()) {
            $entityId = $this->getConfig()->getEntityID();

            try {
                $isRole = false;

                /** @var Attribution $attribution **/
                foreach ($this->getUser()->getAttributions() as $attribution) {
                    if ($attribution->getRole()->getRole() == $role
                        && $attribution->getTarget()->getUrl() == $entityId
                    ) {
                        $isRole = true;
                    }
                }

                if ($isRole) {
                    $this->setUser($this->getUser()->setCurrentRole($role));
                } else {
                    throw new UserAttributionException('Role not found.', 400);
                }
            } catch (\Exception $e) {
                throw new UserAttributionException($e->getMessage(), $e->getCode(), $e->getPrevious());
            }
        } else {
            throw new UserAttributionException('User not found.', 400);
        }
    }
1287162
public function getPermission($role)
    {
        if ($role instanceof RoleInterface || $role instanceof \Symfony\Component\Security\Core\Role\Role) {
            $role = $role->getRole();
        }
        if (isset($this->permissions[$role])) {
            return $this->permissions[$role];
        }

        return null;
    }
309156
public function handle($request, Closure $next, $role)
    {
        if ($this->auth->check() && $this->auth->user()->isRole($role)) {
            return $next($request);
        }
        throw new RoleDeniedException($role);
    }
794068
public function edit(User $user, Role $role)
    {
        $this->authorize(UsersPolicy::PERMISSION_UPDATE);

        $user->load(['roles', 'roles.permissions']);
        $roles = $role->all();

        $this->setTitle($title = trans('auth::users.titles.edit-user'));
        $this->addBreadcrumb($title);

        return $this->view('admin.users.edit', compact('user', 'roles'));
    }