Exemplo n.º 1
0
 /**
  * Delete a policy from role.
  *
  * @param $roleId int ID of a role or a role draft
  * @param $policyId int ID of a policy
  *
  * @throws \eZ\Publish\Core\REST\Common\Exceptions\NotFoundException
  *
  * @return \eZ\Publish\Core\REST\Server\Values\NoContent
  */
 public function deletePolicy($roleId, $policyId, Request $request)
 {
     try {
         // First try to treat $roleId as a role draft ID.
         $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();
         }
     } catch (NotFoundException $e) {
         // Then try to treat $roleId as a role ID.
         $role = $this->roleService->loadRole($roleId);
         $policy = null;
         foreach ($role->getPolicies() as $rolePolicy) {
             if ($rolePolicy->id == $policyId) {
                 $policy = $rolePolicy;
                 break;
             }
         }
         if ($policy !== null) {
             $this->roleService->deletePolicy($policy);
             return new Values\NoContent();
         }
     }
     throw new Exceptions\NotFoundException("Policy not found: '{$request->getPathInfo()}'.");
 }
Exemplo n.º 2
0
 /**
  * Delete a policy from role
  *
  * @param $roleId
  * @param $policyId
  *
  * @throws \eZ\Publish\Core\REST\Common\Exceptions\NotFoundException
  * @return \eZ\Publish\Core\REST\Server\Values\NoContent
  */
 public function deletePolicy($roleId, $policyId)
 {
     $role = $this->roleService->loadRole($roleId);
     $policy = null;
     foreach ($role->getPolicies() as $rolePolicy) {
         if ($rolePolicy->id == $policyId) {
             $policy = $rolePolicy;
             break;
         }
     }
     if ($policy !== null) {
         $this->roleService->deletePolicy($policy);
         return new Values\NoContent();
     }
     throw new Exceptions\NotFoundException("Policy not found: '{$this->request->getPathInfo()}'.");
 }
Exemplo n.º 3
0
 /**
  * Delete a policy.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove a policy
  *
  * @param \eZ\Publish\API\Repository\Values\User\Policy $policy the policy to delete
  */
 public function deletePolicy(Policy $policy)
 {
     $returnValue = $this->service->deletePolicy($policy);
     $this->signalDispatcher->emit(new RemovePolicySignal(array('roleId' => $policy->roleId, 'policyId' => $policy->id)));
     return $returnValue;
 }