|
8 | 8 | use App\Helpers\MetaFormats\Validators\VString;
|
9 | 9 | use App\Helpers\MetaFormats\Validators\VUuid;
|
10 | 10 | use App\Exceptions\ForbiddenRequestException;
|
| 11 | +use App\Exceptions\NotFoundException; |
| 12 | +use App\Exceptions\InternalServerException; |
11 | 13 | use App\Model\Repository\GroupExternalAttributes;
|
12 | 14 | use App\Model\Repository\GroupMemberships;
|
13 | 15 | use App\Model\Repository\Groups;
|
@@ -130,11 +132,26 @@ public function checkRemove()
|
130 | 132 | * Remove selected attribute
|
131 | 133 | * @DELETE
|
132 | 134 | */
|
133 |
| - #[Path("id", new VUuid(), "Identifier of the external attribute.", required: true)] |
134 |
| - public function actionRemove(string $id) |
| 135 | + #[Query("service", new VString(1, 32), "Identifier of the external service creating the attribute", required: true)] |
| 136 | + #[Query("key", new VString(1, 32), "Key of the attribute (must be valid identifier)", required: true)] |
| 137 | + #[Query("value", new VString(0, 255), "Value of the attribute (arbitrary string)", required: true)] |
| 138 | + #[Path("groupId", new VString(), required: true)] |
| 139 | + public function actionRemove(string $groupId, string $service, string $key, string $value) |
135 | 140 | {
|
136 |
| - $attribute = $this->groupExternalAttributes->findOrThrow($id); |
137 |
| - $this->groupExternalAttributes->remove($attribute); |
| 141 | + $attributes = $this->groupExternalAttributes->findBy( |
| 142 | + ['group' => $groupId, 'service' => $service, 'key' => $key, 'value' => $value] |
| 143 | + ); |
| 144 | + if (!$attributes) { |
| 145 | + throw new NotFoundException("Specified attribute not found at selected group"); |
| 146 | + } |
| 147 | + if (count($attributes) > 1) { |
| 148 | + throw new InternalServerException( |
| 149 | + "Unique constraint violation " |
| 150 | + . "(multiple '$key' => '$value' attributes found at $groupId from service $service)" |
| 151 | + ); |
| 152 | + } |
| 153 | + |
| 154 | + $this->groupExternalAttributes->remove($attributes[0]); |
138 | 155 | $this->sendSuccessResponse("OK");
|
139 | 156 | }
|
140 | 157 | }
|
0 commit comments