Lines
96.66%
29 / 30
Methods
66.66%
2 / 3
Classes
0.00%
0 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| readResponse | 100.00% | 15 / 15 | 100.00% | 1 / 1 | 3 | ||
| testEntity | 91.66% | 11 / 12 | 0.00% | 0 / 1 | 6.02 | ||
| [BO\Zmsbackend\Api\BaseController] __invoke | 100.00% | 3 / 3 | 100.00% | 1 / 1 | 1 | ||
| 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 | } |
Inherited from BO\Zmsbackend\Api\BaseController
| 20 | public function __invoke(RequestInterface $request, ResponseInterface $response, array $args) | |
| 21 | { | |
| 22 | $request = $this->initRequest($request); | |
| 23 | $noCacheResponse = \BO\Slim\Render::withLastModified($response, time(), '0'); | |
| 24 | return $this->readResponse($request, $noCacheResponse, $args); | |
| 25 | } |