Skip to content

Commit 9b754b7

Browse files
committed
Changing the endpoint for deleting external attributes (using attribute key-values rather than IDs, which are not available to extension apps).
1 parent 310ea74 commit 9b754b7

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

app/V1Module/presenters/GroupExternalAttributesPresenter.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use App\Helpers\MetaFormats\Validators\VString;
99
use App\Helpers\MetaFormats\Validators\VUuid;
1010
use App\Exceptions\ForbiddenRequestException;
11+
use App\Exceptions\NotFoundException;
12+
use App\Exceptions\InternalServerException;
1113
use App\Model\Repository\GroupExternalAttributes;
1214
use App\Model\Repository\GroupMemberships;
1315
use App\Model\Repository\Groups;
@@ -130,11 +132,26 @@ public function checkRemove()
130132
* Remove selected attribute
131133
* @DELETE
132134
*/
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)
135140
{
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]);
138155
$this->sendSuccessResponse("OK");
139156
}
140157
}

app/V1Module/router/RouterFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ private static function createGroupAttributesRoutes(string $prefix): RouteList
312312

313313
$router[] = new GetRoute($prefix, "GroupExternalAttributes:");
314314
$router[] = new PostRoute("$prefix/<groupId>", "GroupExternalAttributes:add");
315-
$router[] = new DeleteRoute("$prefix/<id>", "GroupExternalAttributes:remove");
315+
$router[] = new DeleteRoute("$prefix/<groupId>", "GroupExternalAttributes:remove");
316316
return $router;
317317
}
318318

tests/Presenters/GroupExternalAttributesPresenter.phpt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,13 @@ class TestGroupExternalAttributesPresenter extends Tester\TestCase
224224
$this->presenter,
225225
'V1:GroupExternalAttributes',
226226
'DELETE',
227-
['action' => 'remove', 'id' => $id],
227+
[
228+
'action' => 'remove',
229+
'groupId' => $attribute->getGroup()->getId(),
230+
'service' => $attribute->getService(),
231+
'key' => $attribute->getKey(),
232+
'value' => $attribute->getValue()
233+
],
228234
);
229235

230236
Assert::equal("OK", $payload);

0 commit comments

Comments
 (0)