Exemplo n.º 1
0
 public function deletePolicyAction(Request $request, $roleId, $policyId)
 {
     $role = $this->roleService->loadRole($roleId);
     $deleteForm = $this->createForm(new PolicyDeleteType(), ['policyId' => $policyId, 'roleId' => $roleId]);
     $deleteForm->handleRequest($request);
     if ($deleteForm->isValid()) {
         try {
             $roleDraft = $this->roleService->loadRoleDraftByRoleId($roleId);
         } catch (NotFoundException $e) {
             // The draft doesn't exist, let's create one
             $roleDraft = $this->roleService->createRoleDraft($role);
         }
         $foundPolicy = false;
         /** @var PolicyDraft $policy */
         foreach ($roleDraft->getPolicies() as $policy) {
             if ($policy->originalId == $policyId) {
                 $foundPolicy = true;
                 break;
             }
         }
         if (!$foundPolicy) {
             throw new BadRequestHttpException($this->translator->trans('role.error.policy_not_found', ['%policyId%' => $policyId, '%roleId%' => $roleId], 'role'));
         }
         $this->roleService->removePolicyByRoleDraft($roleDraft, $policy);
         $this->roleService->publishRoleDraft($roleDraft);
         $this->notify('role.policy.deleted', ['%roleIdentifier%' => $role->identifier, '%policyId%' => $policyId], 'role');
     } elseif ($deleteForm->isSubmitted()) {
         $this->notifyError('role.policy.error.delete', ['%roleIdentifier%' => $role->identifier, '%policyId%' => $policyId], 'role');
     }
     return $this->redirectToRouteAfterFormPost('admin_roleView', ['roleId' => $roleId]);
 }
Exemplo n.º 2
0
 /**
  * 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);
 }
Exemplo n.º 3
0
 /**
  * Loads a RoleDraft by the ID of the role it was created from.
  *
  * @param mixed $roleId ID of the role the draft was created from.
  *
  * @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 RoleDraft with the given id was not found
  *
  * @return \eZ\Publish\API\Repository\Values\User\RoleDraft
  */
 public function loadRoleDraftByRoleId($roleId)
 {
     return $this->service->loadRoleDraftByRoleId($roleId);
 }