/** * Updates a role. * * @param int $roleId Role ID * * @return \Symfony\Component\HttpFoundation\Response */ public function updateRoleAction(Request $request, $roleId) { try { // If the draft is not yet published, we load it directly. $roleDraft = $this->roleService->loadRoleDraft($roleId); } catch (NotFoundException $e) { try { // If the draft has been published, we load it by the published ID $roleDraft = $this->roleService->loadRoleDraftByRoleId($roleId); } catch (NotFoundException $e) { // The draft doesn't exist, let's create one $role = $this->roleService->loadRole($roleId); $roleDraft = $this->roleService->createRoleDraft($role); } } $roleData = (new RoleMapper())->mapToFormData($roleDraft); $form = $this->createForm(new RoleUpdateType(), $roleData); $actionUrl = $this->generateUrl('admin_roleUpdate', ['roleId' => $roleId]); // Synchronize form and data. $form->handleRequest($request); $hasErrors = false; if ($form->isValid()) { $this->roleActionDispatcher->dispatchFormAction($form, $roleData, $form->getClickedButton() ? $form->getClickedButton()->getName() : null); if ($response = $this->roleActionDispatcher->getResponse()) { return $response; } return $this->redirectAfterFormPost($actionUrl); } elseif ($form->isSubmitted()) { $hasErrors = true; } $formView = $form->createView(); return $this->render('eZPlatformUIBundle:Role:update_role.html.twig', ['form' => $formView, 'action_url' => $actionUrl, 'role_draft' => $roleDraft, 'role_name' => $roleData->isNew() ? 'role.name_new' : $roleDraft->identifier, 'hasErrors' => $hasErrors]); }
/** * Updates a role. * * @param int $roleId Role ID * * @return \Symfony\Component\HttpFoundation\Response */ public function updateRoleAction(Request $request, $roleId) { try { $roleDraft = $this->roleService->loadRoleDraft($roleId); } catch (NotFoundException $e) { // The draft doesn't exist, let's create one $role = $this->roleService->loadRole($roleId); $roleDraft = $this->roleService->createRoleDraft($role); } $roleData = (new RoleMapper())->mapToFormData($roleDraft); $form = $this->createForm(new RoleUpdateType(), $roleData); $actionUrl = $this->generateUrl('admin_roleUpdate', ['roleId' => $roleId]); // Synchronize form and data. $form->handleRequest($request); $hasErrors = false; if ($form->isValid()) { $this->actionDispatcher->dispatchFormAction($form, $roleData, $form->getClickedButton()->getName()); if ($response = $this->actionDispatcher->getResponse()) { return $response; } return $this->redirectAfterFormPost($actionUrl); } elseif ($form->isSubmitted()) { $hasErrors = true; } $formView = $form->createView(); // Show empty text input when name is not set, while showing "New role" in the page title $roleName = $roleDraft->identifier; if ($roleData->isNew()) { $roleName = 'role.name_new'; $formView->vars['role_input_value'] = ''; } else { $formView->vars['role_input_value'] = $roleName; } return $this->render('eZPlatformUIBundle:Role:update_role.html.twig', ['form' => $formView, 'action_url' => $actionUrl, 'role_draft' => $roleDraft, 'role_name' => $roleName, 'hasErrors' => $hasErrors]); }
/** * Publishes a role draft. * * @param mixed $roleId Original role ID, or ID of the role draft itself * @return Values\RestRole */ public function publishRoleDraft($roleId) { try { // First try to load the draft for given role. $roleDraft = $this->roleService->loadRoleDraftByRoleId($roleId); } catch (NotFoundException $e) { // We might want a newly created role, so try to load it by its ID. // loadRoleDraft() might throw a NotFoundException (wrong $roleId). If so, let it bubble up. $roleDraft = $this->roleService->loadRoleDraft($roleId); } $this->roleService->publishRoleDraft($roleDraft); $publishedRole = $this->roleService->loadRole($roleDraft->id); return new Values\RestRole($publishedRole); }
/** * Remove a policy from a role draft. * * @since 6.2 * @deprecated since 6.3, use {@see deletePolicy} * * @param $roleId * @param $policyId * * @throws \eZ\Publish\Core\REST\Common\Exceptions\NotFoundException * * @return \eZ\Publish\Core\REST\Server\Values\NoContent */ public function removePolicyByRoleDraft($roleId, $policyId, Request $request) { $roleDraft = $this->roleService->loadRoleDraft($roleId); $policy = null; foreach ($roleDraft->getPolicies() as $rolePolicy) { if ($rolePolicy->id == $policyId) { $policy = $rolePolicy; break; } } if ($policy !== null) { $this->roleService->removePolicyByRoleDraft($roleDraft, $policy); return new Values\NoContent(); } throw new Exceptions\NotFoundException("Policy not found: '{$request->getPathInfo()}'."); }
/** * Loads a role for the given id. * * @since 6.0 * * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read this role * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a role with the given id was not found * * @param mixed $id * * @return \eZ\Publish\API\Repository\Values\User\RoleDraft */ public function loadRoleDraft($id) { return $this->service->loadRoleDraft($id); }
/** * Publishes a role draft. * * @param $roleId */ public function publishRoleDraft($roleId, Request $request) { $createStruct = $this->inputDispatcher->parse(new Message(array('Content-Type' => $request->headers->get('Content-Type')), $request->getContent())); $this->roleService->publishRoleDraft($this->roleService->loadRoleDraft($roleId), $this->mapToUpdateStruct($createStruct)); }