| @@ 479-503 (lines=25) @@ | ||
| 476 | * |
|
| 477 | * @return \eZ\Publish\API\Repository\Values\User\Policy |
|
| 478 | */ |
|
| 479 | public function updatePolicy($roleId, $policyId, Request $request) |
|
| 480 | { |
|
| 481 | $updateStruct = $this->inputDispatcher->parse( |
|
| 482 | new Message( |
|
| 483 | array('Content-Type' => $request->headers->get('Content-Type')), |
|
| 484 | $request->getContent() |
|
| 485 | ) |
|
| 486 | ); |
|
| 487 | ||
| 488 | $role = $this->roleService->loadRole($roleId); |
|
| 489 | foreach ($role->getPolicies() as $policy) { |
|
| 490 | if ($policy->id == $policyId) { |
|
| 491 | try { |
|
| 492 | return $this->roleService->updatePolicy( |
|
| 493 | $policy, |
|
| 494 | $updateStruct |
|
| 495 | ); |
|
| 496 | } catch (LimitationValidationException $e) { |
|
| 497 | throw new BadRequestException($e->getMessage()); |
|
| 498 | } |
|
| 499 | } |
|
| 500 | } |
|
| 501 | ||
| 502 | throw new Exceptions\NotFoundException("Policy not found: '{$request->getPathInfo()}'."); |
|
| 503 | } |
|
| 504 | ||
| 505 | /** |
|
| 506 | * Updates a policy. |
|
| @@ 517-541 (lines=25) @@ | ||
| 514 | * |
|
| 515 | * @return \eZ\Publish\API\Repository\Values\User\Policy |
|
| 516 | */ |
|
| 517 | public function updatePolicyByRoleDraft($roleId, $policyId, Request $request) |
|
| 518 | { |
|
| 519 | $updateStruct = $this->inputDispatcher->parse( |
|
| 520 | new Message( |
|
| 521 | array('Content-Type' => $request->headers->get('Content-Type')), |
|
| 522 | $request->getContent() |
|
| 523 | ) |
|
| 524 | ); |
|
| 525 | ||
| 526 | $role = $this->roleService->loadRoleDraft($roleId); |
|
| 527 | foreach ($role->getPolicies() as $policy) { |
|
| 528 | if ($policy->id == $policyId) { |
|
| 529 | try { |
|
| 530 | return $this->roleService->updatePolicy( |
|
| 531 | $policy, |
|
| 532 | $updateStruct |
|
| 533 | ); |
|
| 534 | } catch (LimitationValidationException $e) { |
|
| 535 | throw new BadRequestException($e->getMessage()); |
|
| 536 | } |
|
| 537 | } |
|
| 538 | } |
|
| 539 | ||
| 540 | throw new Exceptions\NotFoundException("Policy not found: '{$request->getPathInfo()}'."); |
|
| 541 | } |
|
| 542 | ||
| 543 | /** |
|
| 544 | * Delete a policy from role. |
|