Save role

@param RoleForm $roleForm
@param bool     $newFlag
430385
private function saveRole ($roleForm)
		{

			$auth = Yii::$app->getAuthManager();
			$role = $auth->createRole($roleForm->name);
			$role->type = Role::TYPE_ROLE;
			$role->description = $roleForm->description;
			if (!empty($roleForm->ruleName))
				$role->ruleName = $roleForm->ruleName;
			$role->data = $roleForm->data;

			if ($roleForm->method == 'rbac-add')
				$auth->add($role);
			else
			{
				$auth->update($roleForm->method, $role);
				$auth->removeChildren($role);
			}

			if (is_array($roleForm->childRoles) and count($roleForm->childRoles) > 0)
				foreach ($roleForm->childRoles as $childRole)
				{
					$child = $auth->getRole($childRole);
					$auth->addChild($role, $child);
				}

			if (is_array($roleForm->childPermissions) and count($roleForm->childPermissions) > 0)
				foreach ($roleForm->childPermissions as $childPermission)
				{
					$child = $auth->getPermission($childPermission);
					$auth->addChild($role, $child);
				}
		}
1218565
public function copy($oldRole, $newRoleName)
    {
        /**
         * @var Role $newRole
         */
        $newRole = new $this->model();
        $newRole->fill([
            'name'       => $newRoleName,
            'label'      => $newRoleName,
            'guard_name' => $oldRole->guard_name
        ]);
        $newRole->save();

        $newRole = $this->update(['permissions' => $oldRole->permissions->toArray()], $newRole->id);
        return $newRole;
    }
664604
public function addRole(string ...$role)
    {
        foreach ($role as $_role)
        {
            $this->roleRegistry->save($_role);
        }
    }
786599
public function editAction(Request $request, Role $role)
    {
        $deleteForm = $this->createDeleteForm($role);
        $editForm = $this->createForm('CoreBundle\Form\RoleType', $role);
        $editForm->handleRequest($request);

        if ($editForm->isSubmitted() && $editForm->isValid()) {
            $this->getDoctrine()->getManager()->flush();

            //if come from popup
            if ($request->isXMLHttpRequest()) {         
                return new JsonResponse(array(
                            'id' => $role->getId(), 
                        ));
            }
            $this->get('session')->getFlashBag()->add('success', 'role.edited');
            
            return $this->redirectToRoute('core_role_edit', array('id' => $role->getId()));
        }

        return array(
            'role' => $role,
            'edit_form' => $editForm->createView(),
            'delete_form' => $deleteForm->createView(),
        );
    }
380966
public function update(Role $role, UpdateRole $request)
    {
        try {
            $role->update($request->except('permissions'));
            $role->syncPermissions($request->permissions());

            flash()->success(__('The :name role has been updated', ['name' => $role->name]));
        } catch (\Exception $e) {
            flash()->error(__('Error: :msg', ['msg' => $e->getMessage()]));
            return redirect()->back();
        }

        return redirect(route('appshell.role.show', $role));
    }
1142242
private function createDeleteRoleScopeForm(PermissionsGroup $permissionsGroup,
            RoleScope $roleScope)
    {
        return $this->createFormBuilder()
            ->setAction($this->generateUrl('admin_permissionsgroup_delete_role_scope', 
                    array('pgid' => $permissionsGroup->getId(), 'rsid' => $roleScope->getId())))
            ->setMethod('DELETE')
            ->add('submit', 'submit', array('label' => 'Delete'))
            ->getForm()
        ;
    }
1320137
public function updateAction(Request $request, Role $role): Response
    {
        $this->denyAccessUnlessGranted(new Attribute('role', 'update'));
        $form = $this->formFactory->updateRole(
            new RoleUpdateData($role)
        );
        $form->handleRequest($request);

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

                $roleUpdateStruct = $this->roleUpdateMapper->reverseMap($data);
                $roleDraft = $this->roleService->createRoleDraft($role);

                $this->roleService->updateRoleDraft($roleDraft, $roleUpdateStruct);
                $this->roleService->publishRoleDraft($roleDraft);

                $this->notificationHandler->success(
                    $this->translator->trans(
                        /** @Desc("Role '%role%' updated.") */
                        'role.update.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/edit.html.twig', [
            'role' => $role,
            'form' => $form->createView(),
        ]);
    }
684430
def add_role(self, role, description=None):
        
        new_group = AuthGroup(role=role, creator=self.client)
        try:
            new_group.save()
            return True
        except NotUniqueError:
            return False
309156
public function handle($request, Closure $next, $role)
    {
        if ($this->auth->check() && $this->auth->user()->isRole($role)) {
            return $next($request);
        }
        throw new RoleDeniedException($role);
    }
1167275
public function store(RoleCreateRequest $request)
    {
        $result = $this->service->create($request->except(['_token', '_method']));

        if ($result) {
            return redirect('admin/roles')->with('message', 'Successfully created');
        }

        return back()->with('error', 'Failed to invite');
    }
147317
public function addRole(Role $role)
    {
        if (!in_array($role, $this->roles)) {
            $this->roles[] = $role;
            return true;
        }
        return false;
    }
1185105
public function deactivateRole($featureName, $roleName)
    {
        $feature = $this->getFeature($featureName);
        $feature->removeRole($roleName);
        $this->saveFeature($feature);
    }
1344788
public function grantRoleAccess(RoleInterface $role, ResourceInterface $resource, string $action)
    {
        $resourcePermissions = $this->getGroupPermissions($resource);
        $matchedPermission = null;

        //
        // 1. Check to see if the role, or its parents already have access.  Don't pollute the database.
        //
        $examinedRole = $role;
        while ($examinedRole) {
            foreach ($resourcePermissions as $permission) {
                if ($role === $permission->getRole()) {
                    $matchedPermission = $permission;
                }

                if ($permission->can($action)) {
                    throw new ExistingAccessException($role, $resource, $action, $permission->getRole()->getName());
                }
            }
            $examinedRole = $examinedRole->getParent();
        }

        //
        // 2. Give access
        //
        if (!$matchedPermission) {
            $newPermission = $this->groupPermissions->create($role, $resource->getClass(), $resource->getId(), [$action]);
            $this->groupPermissions->save($newPermission);
        } else {
            $matchedPermission->addAction($action);
            $this->groupPermissions->update($matchedPermission);

        }
    }
193777
protected function form(Fluent $model, FormBuilder $form)
    {
        $form->extend(function (FormGrid $form) {
            $form->fieldset('Role Configuration', function (Fieldset $fieldset) {
                $roles = Role::pluck('name', 'id');

                $fieldset->control('select', 'admin_role')
                    ->label(trans('orchestra/control::label.roles.admin'))
                    ->options($roles);

                $fieldset->control('select', 'member_role')
                    ->label(trans('orchestra/control::label.roles.member'))
                    ->options($roles);
            });

            $form->fieldset('Timezone', function (Fieldset $fieldset) {
                $agreement = ['yes' => 'Yes', 'no' => 'No'];

                $fieldset->control('select', 'localtime')
                    ->attributes(['role' => 'agreement'])
                    ->label(trans('orchestra/control::label.enable-timezone'))
                    ->options($agreement)
                    ->value(function ($row) {
                        return ($row->localtime === true) ? 'yes' : 'no';
                    });
            });
        });
    }
400190
public function newRole(Role $request)
    {

        $role = $this->addRole($request->input('title'));

        return redirect()
            ->route('configuration.access.roles.edit', ['id' => $role->id])
            ->with('success', trans('web::seat.role_added'));
    }
342279
public function addChildRole(Role $parentRole, Role $childRole)
    {
        $roleHierarchy = new RoleHierarchy();

        $roleHierarchy->setParentRole($parentRole);
        $roleHierarchy->setChildRole($childRole);

        $this->checkForCyclicHierarchy($childRole->getId(), $parentRole->getId());

        try {
            $this->saveEntity($roleHierarchy);
        }  catch (UniqueConstraintViolationException $e) {
            throw new NotUniqueException('Child role ' . $childRole->getName() . ' is already has parent role ' . $parentRole->getName());
        }
    }
825383
public function newAction() {

        $entity = new Role();

        $form = $this->createCreateForm($entity);

        return array(
            'entity' => $entity,
            'form' => $form->createView(),
        );
    }