Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
25 / 25 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
UseraccountUpdate | |
100.00% |
25 / 25 |
|
100.00% |
2 / 2 |
8 | |
100.00% |
1 / 1 |
readResponse | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
3 | |||
testEntity | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
5 |
1 | <?php |
2 | |
3 | /** |
4 | * @package ZMS API |
5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG |
6 | **/ |
7 | |
8 | namespace BO\Zmsapi; |
9 | |
10 | use BO\Slim\Render; |
11 | use BO\Mellon\Validator; |
12 | use BO\Zmsdb\Useraccount; |
13 | |
14 | /** |
15 | * @SuppressWarnings(Coupling) |
16 | * @return String |
17 | */ |
18 | class UseraccountUpdate extends BaseController |
19 | { |
20 | /** |
21 | * @SuppressWarnings(Param) |
22 | * @return String |
23 | */ |
24 | public function readResponse( |
25 | \Psr\Http\Message\RequestInterface $request, |
26 | \Psr\Http\Message\ResponseInterface $response, |
27 | array $args |
28 | ) { |
29 | (new Helper\User($request, 2))->checkRights('useraccount'); |
30 | |
31 | $resolveReferences = Validator::param('resolveReferences')->isNumber()->setDefault(2)->getValue(); |
32 | $input = Validator::input()->isJson()->assertValid()->getValue(); |
33 | $entity = new \BO\Zmsentities\Useraccount($input); |
34 | if (! (new Useraccount())->readIsUserExisting($args['loginname'])) { |
35 | throw new Exception\Useraccount\UseraccountNotFound(); |
36 | } |
37 | |
38 | $this->testEntity($entity, $input, $args); |
39 | |
40 | if (isset($entity->changePassword)) { |
41 | $entity->password = $entity->getHash(reset($entity->changePassword)); |
42 | } |
43 | |
44 | $message = Response\Message::create($request); |
45 | $message->data = (new Useraccount())->writeUpdatedEntity($args['loginname'], $entity, $resolveReferences); |
46 | |
47 | $response = Render::withLastModified($response, time(), '0'); |
48 | $response = Render::withJson($response, $message->setUpdatedMetaData(), $message->getStatuscode()); |
49 | return $response; |
50 | } |
51 | |
52 | protected function testEntity($entity, $input, $args) |
53 | { |
54 | if (0 == count($input)) { |
55 | throw new Exception\Useraccount\UseraccountInvalidInput(); |
56 | } |
57 | try { |
58 | $entity->testValid('de_DE', 1); |
59 | } catch (\Exception $exception) { |
60 | $exception->data['input'] = $input; |
61 | throw $exception; |
62 | } |
63 | |
64 | if ($args['loginname'] != $entity->id && (new Useraccount())->readIsUserExisting($entity->id)) { |
65 | throw new Exception\Useraccount\UseraccountAlreadyExists(); |
66 | } |
67 | |
68 | Helper\UserAuth::testUseraccountExists($args['loginname']); |
69 | Helper\User::testWorkstationAccessRights($entity); |
70 | Helper\User::testWorkstationAssignedRights($entity); |
71 | } |
72 | } |