Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| EditUserEndpoint | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
5 | |
100.00% |
1 / 1 |
| handle | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
5 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Olz\Users\Endpoints; |
| 4 | |
| 5 | use Olz\Api\OlzEditEntityTypedEndpoint; |
| 6 | use PhpTypeScriptApi\HttpError; |
| 7 | |
| 8 | /** |
| 9 | * @phpstan-import-type OlzUserId from UserEndpointTrait |
| 10 | * @phpstan-import-type OlzUserData from UserEndpointTrait |
| 11 | * |
| 12 | * @extends OlzEditEntityTypedEndpoint<OlzUserId, OlzUserData> |
| 13 | */ |
| 14 | class EditUserEndpoint extends OlzEditEntityTypedEndpoint { |
| 15 | use UserEndpointTrait; |
| 16 | |
| 17 | protected function handle(mixed $input): mixed { |
| 18 | $entity = $this->getEntityById($input['id']); |
| 19 | |
| 20 | $current_user = $this->authUtils()->getCurrentUser(); |
| 21 | $is_me = ( |
| 22 | $current_user |
| 23 | && $entity->getUsername() === $current_user->getUsername() |
| 24 | && $entity->getId() === $current_user->getId() |
| 25 | ); |
| 26 | $can_update = $this->entityUtils()->canUpdateOlzEntity($entity, null, 'users'); |
| 27 | if (!$is_me && !$can_update) { |
| 28 | throw new HttpError(403, "Kein Zugriff!"); |
| 29 | } |
| 30 | |
| 31 | $this->editUploads($entity); |
| 32 | |
| 33 | return [ |
| 34 | 'id' => $entity->getId() ?? 0, |
| 35 | 'meta' => $entity->getMetaData(), |
| 36 | 'data' => $this->getEntityData($entity), |
| 37 | ]; |
| 38 | } |
| 39 | } |