Lines
96.29%
26 / 27
Functions and Methods
50.00%
1 / 2
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| UseraccountUpdate | 96.29% | 26 / 27 | 50.00% | 1 / 2 | 9 | 0.00% | 0 / 1 | |||
| readResponse | 100.00% | 15 / 15 | 100.00% | 1 / 1 | 3 | |||||
| testEntity | 91.66% | 11 / 12 | 0.00% | 0 / 1 | 6.02 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | /** | |
| 4 | * @package ZMS API | |
| 5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG | |
| 6 | **/ | |
| 7 | ||
| 8 | namespace BO\Zmsbackend\Useraccount\Api; | |
| 9 | ||
| 10 | use BO\Slim\Render; | |
| 11 | use BO\Mellon\Validator; | |
| 12 | use BO\Zmsbackend\Useraccount\Service\Useraccount; | |
| 13 | ||
| 14 | /** | |
| 15 | * @SuppressWarnings(Coupling) | |
| 16 | * @return \Psr\Http\Message\ResponseInterface | |
| 17 | */ | |
| 18 | class UseraccountUpdate 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('useraccount'); | |
| 31 | ||
| 32 | $resolveReferences = Validator::param('resolveReferences')->isNumber()->setDefault(2)->getValue(); | |
| 33 | $input = Validator::input()->isJson()->assertValid()->getValue(); | |
| 34 | $entity = new \BO\Zmsentities\Useraccount($input); | |
| 35 | if (! (new \BO\Zmsbackend\Useraccount\Service\Useraccount())->readIsUserExisting($args['loginname'])) { | |
| 36 | throw new \BO\Zmsbackend\Useraccount\Exception\UseraccountNotFound(); | |
| 37 | } | |
| 38 | ||
| 39 | $this->testEntity($entity, $input, $args); | |
| 40 | \BO\Zmsbackend\Helper\User::testWorkstationAssignedRoles($entity); | |
| 41 | ||
| 42 | if (isset($entity->changePassword)) { | |
| 43 | $entity->password = $entity->getHash(reset($entity->changePassword)); | |
| 44 | } | |
| 45 | ||
| 46 | $message = \BO\Zmsbackend\Api\Response\Message::create($request); | |
| 47 | $message->data = (new \BO\Zmsbackend\Useraccount\Service\Useraccount())->writeUpdatedEntity($args['loginname'], $entity, $resolveReferences); | |
| 48 | ||
| 49 | $response = Render::withLastModified($response, time(), '0'); | |
| 50 | $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode()); | |
| 51 | return $response; | |
| 52 | } | |
| 53 | ||
| 54 | /** | |
| 55 | * @return void | |
| 56 | */ | |
| 57 | protected function testEntity(\BO\Zmsentities\Useraccount $entity, $input, array $args) | |
| 58 | { | |
| 59 | if (0 == count($input)) { | |
| 60 | throw new \BO\Zmsbackend\Useraccount\Exception\UseraccountInvalidInput(); | |
| 61 | } | |
| 62 | if (!isset($entity['departments'])) { | |
| 63 | $entity->departments = []; | |
| 64 | } | |
| 65 | try { | |
| 66 | $entity->testValid('de_DE', 1); | |
| 67 | } catch (\Exception $exception) { | |
| 68 | $exception->data['input'] = $input; | |
| 69 | throw $exception; | |
| 70 | } | |
| 71 | ||
| 72 | if ($args['loginname'] != $entity->id && (new \BO\Zmsbackend\Useraccount\Service\Useraccount())->readIsUserExisting($entity->id)) { | |
| 73 | throw new \BO\Zmsbackend\Useraccount\Exception\UseraccountAlreadyExists(); | |
| 74 | } | |
| 75 | ||
| 76 | \BO\Zmsbackend\Helper\UserAuth::testUseraccountExists($args['loginname']); | |
| 77 | \BO\Zmsbackend\Helper\User::testWorkstationAccessRights($entity); | |
| 78 | } | |
| 79 | } |