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);
 }
 public function processSavePolicy(FormActionEvent $event)
 {
     /** @var \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft */
     $roleDraft = $event->getData()->roleDraft;
     $this->roleService->publishRoleDraft($roleDraft);
 }
 public function processSaveRole(FormActionEvent $event)
 {
     $roleDraft = $this->getRoleDraft($event);
     $this->roleService->updateRoleDraft($roleDraft, $this->getRoleData($event));
     $this->roleService->publishRoleDraft($roleDraft);
 }
 public function processSaveRole(FormActionEvent $event)
 {
     /** @var RoleDraft $roleDraft */
     $roleDraft = $event->getData()->roleDraft;
     $this->roleService->publishRoleDraft($roleDraft);
 }
Exemplo n.º 6
0
 /**
  * Publishes a given Role draft.
  *
  * @since 6.0
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to publish this role
  *
  * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft
  */
 public function publishRoleDraft(RoleDraft $roleDraft)
 {
     $returnValue = $this->service->publishRoleDraft($roleDraft);
     $this->signalDispatcher->emit(new PublishRoleDraftSignal(array('roleId' => $roleDraft->id)));
     return $returnValue;
 }
Exemplo n.º 7
0
 /**
  * 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));
 }