Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
EditRoleEndpoint | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
configure | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
handle | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | |
3 | namespace Olz\Roles\Endpoints; |
4 | |
5 | use Olz\Api\OlzEditEntityTypedEndpoint; |
6 | use PhpTypeScriptApi\HttpError; |
7 | |
8 | /** |
9 | * @phpstan-import-type OlzRoleId from RoleEndpointTrait |
10 | * @phpstan-import-type OlzRoleData from RoleEndpointTrait |
11 | * |
12 | * @extends OlzEditEntityTypedEndpoint<OlzRoleId, OlzRoleData> |
13 | */ |
14 | class EditRoleEndpoint extends OlzEditEntityTypedEndpoint { |
15 | use RoleEndpointTrait; |
16 | |
17 | public function configure(): void { |
18 | parent::configure(); |
19 | $this->phpStanUtils->registerTypeImport(RoleEndpointTrait::class); |
20 | } |
21 | |
22 | protected function handle(mixed $input): mixed { |
23 | $entity = $this->getEntityById($input['id']); |
24 | |
25 | $is_superior = $this->authUtils()->hasRoleEditPermission($input['id']); |
26 | $is_owner = $this->entityUtils()->canUpdateOlzEntity($entity, null, 'roles'); |
27 | if (!$is_superior && !$is_owner) { |
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 | } |