Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 19 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
EditUserEndpoint | |
0.00% |
0 / 19 |
|
0.00% |
0 / 2 |
42 | |
0.00% |
0 / 1 |
configure | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
handle | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
30 |
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 | public function configure(): void { |
18 | parent::configure(); |
19 | $this->configureUserEndpointTrait(); |
20 | $this->phpStanUtils->registerTypeImport(UserEndpointTrait::class); |
21 | } |
22 | |
23 | protected function handle(mixed $input): mixed { |
24 | $entity = $this->getEntityById($input['id']); |
25 | |
26 | $current_user = $this->authUtils()->getCurrentUser(); |
27 | $is_me = ( |
28 | $current_user |
29 | && $entity->getUsername() === $current_user->getUsername() |
30 | && $entity->getId() === $current_user->getId() |
31 | ); |
32 | $can_update = $this->entityUtils()->canUpdateOlzEntity($entity, null, 'users'); |
33 | if (!$is_me && !$can_update) { |
34 | throw new HttpError(403, "Kein Zugriff!"); |
35 | } |
36 | |
37 | $this->editUploads($entity); |
38 | |
39 | return [ |
40 | 'id' => $entity->getId() ?? 0, |
41 | 'meta' => $entity->getMetaData(), |
42 | 'data' => $this->getEntityData($entity), |
43 | ]; |
44 | } |
45 | } |