Lines
100.00%
24 / 24
Functions and Methods
100.00%
2 / 2
Classes and Traits
100.00%
1 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ProcessGetByExternalUserId | 100.00% | 24 / 24 | 100.00% | 2 / 2 | 7 | 100.00% | 1 / 1 | |||
| readResponse | 100.00% | 19 / 19 | 100.00% | 1 / 1 | 3 | |||||
| validateExternalUserId | 100.00% | 5 / 5 | 100.00% | 1 / 1 | 4 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | /** | |
| 4 | * @package ZMS API | |
| 5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG | |
| 6 | **/ | |
| 7 | ||
| 8 | namespace BO\Zmsbackend\Process\Api; | |
| 9 | ||
| 10 | use BO\Slim\Render; | |
| 11 | use BO\Mellon\Validator; | |
| 12 | use BO\Zmsbackend\Process\Service\Process; | |
| 13 | ||
| 14 | /** | |
| 15 | * Citizen-scoped process read for trusted backends (e.g. zmscitizenapi after JWT validation). | |
| 16 | * Requires workstation/service authentication via X-Authkey and matching external user id. | |
| 17 | */ | |
| 18 | class ProcessGetByExternalUserId extends \BO\Zmsbackend\Api\BaseController | |
| 19 | { | |
| 20 | /** | |
| 21 | * @SuppressWarnings(Param) | |
| 22 | * @return \Psr\Http\Message\ResponseInterface | |
| 23 | */ | |
| 24 | #[\Override] | |
| 25 | public function readResponse( | |
| 26 | \Psr\Http\Message\RequestInterface $request, | |
| 27 | \Psr\Http\Message\ResponseInterface $response, | |
| 28 | array $args | |
| 29 | ) { | |
| 30 | (new \BO\Zmsbackend\Helper\User($request, 2))->checkPermissions(); | |
| 31 | ||
| 32 | ||
| 33 | $resolveReferences = (int) (Validator::param('resolveReferences')->isNumber()->setDefault(2)->getValue() ?? 2); | |
| 34 | $processId = (int) $args['id']; | |
| 35 | $externalUserId = $args['externalUserId']; | |
| 36 | ||
| 37 | $process = (new \BO\Zmsbackend\Process\Service\Process())->readEntity( | |
| 38 | $processId, | |
| 39 | new \BO\Zmsbackend\Helper\NoAuth(), | |
| 40 | $resolveReferences | |
| 41 | ); | |
| 42 | ||
| 43 | if (!$process || !$process->hasId()) { | |
| 44 | $exception = new \BO\Zmsbackend\Process\Exception\ProcessNotFound(); | |
| 45 | $exception->data = ['processId' => $processId]; | |
| 46 | throw $exception; | |
| 47 | } | |
| 48 | ||
| 49 | $this->validateExternalUserId($process, $externalUserId); | |
| 50 | ||
| 51 | $message = \BO\Zmsbackend\Api\Response\Message::create($request); | |
| 52 | $message->data = $process; | |
| 53 | ||
| 54 | $response = Render::withLastModified($response, time(), '0'); | |
| 55 | $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode()); | |
| 56 | return $response; | |
| 57 | } | |
| 58 | ||
| 59 | protected function validateExternalUserId(\BO\Zmsentities\Process $process, string $externalUserId): void | |
| 60 | { | |
| 61 | $processExternalUserId = $process->getExternalUserId(); | |
| 62 | if ( | |
| 63 | $processExternalUserId === null | |
| 64 | || $processExternalUserId === '' | |
| 65 | || (string) $processExternalUserId !== $externalUserId | |
| 66 | ) { | |
| 67 | throw new \BO\Zmsbackend\Process\Exception\ExternalUserIdMatchFailed(); | |
| 68 | } | |
| 69 | } | |
| 70 | } |