Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
DeleteRoleEndpoint | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
3 | |
100.00% |
1 / 1 |
handle | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
3 |
1 | <?php |
2 | |
3 | namespace Olz\Roles\Endpoints; |
4 | |
5 | use Olz\Api\OlzDeleteEntityTypedEndpoint; |
6 | use PhpTypeScriptApi\HttpError; |
7 | |
8 | /** |
9 | * @phpstan-import-type OlzRoleId from RoleEndpointTrait |
10 | * @phpstan-import-type OlzRoleData from RoleEndpointTrait |
11 | * |
12 | * @extends OlzDeleteEntityTypedEndpoint<OlzRoleId, OlzRoleData> |
13 | */ |
14 | class DeleteRoleEndpoint extends OlzDeleteEntityTypedEndpoint { |
15 | use RoleEndpointTrait; |
16 | |
17 | protected function handle(mixed $input): mixed { |
18 | $entity = $this->getEntityById($input['id']); |
19 | |
20 | $is_superior = $this->authUtils()->hasRoleEditPermission($input['id']); |
21 | $is_owner = $this->entityUtils()->canUpdateOlzEntity($entity, null, 'roles'); |
22 | if (!$is_superior && !$is_owner) { |
23 | throw new HttpError(403, "Kein Zugriff!"); |
24 | } |
25 | |
26 | $this->entityUtils()->updateOlzEntity($entity, ['onOff' => false]); |
27 | $this->entityManager()->persist($entity); |
28 | $this->entityManager()->flush(); |
29 | |
30 | return []; |
31 | } |
32 | } |