| @@ 465-489 (lines=25) @@ | ||
| 462 | * |
|
| 463 | * @return \eZ\Publish\API\Repository\Values\User\Policy |
|
| 464 | */ |
|
| 465 | public function updatePolicy($roleId, $policyId, Request $request) |
|
| 466 | { |
|
| 467 | $updateStruct = $this->inputDispatcher->parse( |
|
| 468 | new Message( |
|
| 469 | array('Content-Type' => $request->headers->get('Content-Type')), |
|
| 470 | $request->getContent() |
|
| 471 | ) |
|
| 472 | ); |
|
| 473 | ||
| 474 | $role = $this->roleService->loadRole($roleId); |
|
| 475 | foreach ($role->getPolicies() as $policy) { |
|
| 476 | if ($policy->id == $policyId) { |
|
| 477 | try { |
|
| 478 | return $this->roleService->updatePolicy( |
|
| 479 | $policy, |
|
| 480 | $updateStruct |
|
| 481 | ); |
|
| 482 | } catch (LimitationValidationException $e) { |
|
| 483 | throw new BadRequestException($e->getMessage()); |
|
| 484 | } |
|
| 485 | } |
|
| 486 | } |
|
| 487 | ||
| 488 | throw new Exceptions\NotFoundException("Policy not found: '{$request->getPathInfo()}'."); |
|
| 489 | } |
|
| 490 | ||
| 491 | /** |
|
| 492 | * Updates a policy. |
|
| @@ 501-525 (lines=25) @@ | ||
| 498 | * |
|
| 499 | * @return \eZ\Publish\API\Repository\Values\User\Policy |
|
| 500 | */ |
|
| 501 | public function updatePolicyByRoleDraft($roleId, $policyId, Request $request) |
|
| 502 | { |
|
| 503 | $updateStruct = $this->inputDispatcher->parse( |
|
| 504 | new Message( |
|
| 505 | array('Content-Type' => $request->headers->get('Content-Type')), |
|
| 506 | $request->getContent() |
|
| 507 | ) |
|
| 508 | ); |
|
| 509 | ||
| 510 | $role = $this->roleService->loadRoleDraft($roleId); |
|
| 511 | foreach ($role->getPolicies() as $policy) { |
|
| 512 | if ($policy->id == $policyId) { |
|
| 513 | try { |
|
| 514 | return $this->roleService->updatePolicy( |
|
| 515 | $policy, |
|
| 516 | $updateStruct |
|
| 517 | ); |
|
| 518 | } catch (LimitationValidationException $e) { |
|
| 519 | throw new BadRequestException($e->getMessage()); |
|
| 520 | } |
|
| 521 | } |
|
| 522 | } |
|
| 523 | ||
| 524 | throw new Exceptions\NotFoundException("Policy not found: '{$request->getPathInfo()}'."); |
|
| 525 | } |
|
| 526 | ||
| 527 | /** |
|
| 528 | * Delete a policy from role. |
|