Exemple #1
0
 /**
  * Updates a policy
  *
  * @param $roleId
  * @param $policyId
  *
  * @throws \eZ\Publish\Core\REST\Common\Exceptions\NotFoundException
  * @return \eZ\Publish\API\Repository\Values\User\Policy
  */
 public function updatePolicy($roleId, $policyId)
 {
     $updateStruct = $this->inputDispatcher->parse(new Message(array('Content-Type' => $this->request->headers->get('Content-Type')), $this->request->getContent()));
     $role = $this->roleService->loadRole($roleId);
     foreach ($role->getPolicies() as $policy) {
         if ($policy->id == $policyId) {
             try {
                 return $this->roleService->updatePolicy($policy, $updateStruct);
             } catch (LimitationValidationException $e) {
                 throw new BadRequestException($e->getMessage());
             }
         }
     }
     throw new Exceptions\NotFoundException("Policy not found: '{$this->request->getPathInfo()}'.");
 }
Exemple #2
0
 /**
  * Updates the limitations of a policy. The module and function cannot be changed and
  * the limitations are replaced by the ones in $roleUpdateStruct.
  *
  * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to update a policy
  * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if limitation of the same type is repeated in policy update
  *                                                                        struct or if limitation is not allowed on module/function
  * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if a limitation in the $policyUpdateStruct is not valid
  *
  * @param \eZ\Publish\API\Repository\Values\User\PolicyUpdateStruct $policyUpdateStruct
  * @param \eZ\Publish\API\Repository\Values\User\Policy $policy
  *
  * @return \eZ\Publish\API\Repository\Values\User\Policy
  */
 public function updatePolicy(Policy $policy, PolicyUpdateStruct $policyUpdateStruct)
 {
     $returnValue = $this->service->updatePolicy($policy, $policyUpdateStruct);
     $this->signalDispatcher->emit(new UpdatePolicySignal(array('policyId' => $policy->id)));
     return $returnValue;
 }