Skip to content

Commit 043252b

Browse files
committed
Adding endpoint for fetching attributes of a single group.
1 parent 6be6d19 commit 043252b

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

app/V1Module/presenters/GroupExternalAttributesPresenter.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,24 @@ public function actionDefault(string $instance, ?string $service, ?string $user)
9393
));
9494
}
9595

96+
public function checkGet(string $groupId)
97+
{
98+
$group = $this->groups->findOrThrow($groupId);
99+
if (!$this->groupAcl->canViewDetail($group)) {
100+
throw new ForbiddenRequestException();
101+
}
102+
}
103+
104+
/**
105+
* Get all external attributes for a group. This endpoint is meant to be used by webapp to display the attributes.
106+
* @GET
107+
*/
108+
#[Path("groupId", new VUuid(), required: true)]
109+
public function actionGet(string $groupId)
110+
{
111+
$attributes = $this->groupExternalAttributes->findBy(['group' => $groupId]);
112+
$this->sendSuccessResponse($attributes);
113+
}
96114

97115
public function checkAdd(string $groupId)
98116
{

app/V1Module/router/RouterFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ private static function createGroupAttributesRoutes(string $prefix): RouteList
311311
$router = new RouteList();
312312

313313
$router[] = new GetRoute($prefix, "GroupExternalAttributes:");
314+
$router[] = new GetRoute("$prefix/<groupId>", "GroupExternalAttributes:get");
314315
$router[] = new PostRoute("$prefix/<groupId>", "GroupExternalAttributes:add");
315316
$router[] = new DeleteRoute("$prefix/<groupId>", "GroupExternalAttributes:remove");
316317
return $router;

tests/Presenters/GroupExternalAttributesPresenter.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,33 @@ class TestGroupExternalAttributesPresenter extends Tester\TestCase
184184
Assert::true($total > 0);
185185
}
186186

187+
public function testGetGroupAttributes()
188+
{
189+
PresenterTestHelper::loginDefaultAdmin($this->container);
190+
191+
$groups = array_filter($this->presenter->groups->findAll(), function ($g) {
192+
return !$g->isArchived() && count($g->getExternalAttributes()) > 1;
193+
});
194+
Assert::true(count($groups) > 0);
195+
$group = reset($groups);
196+
197+
$payload = PresenterTestHelper::performPresenterRequest(
198+
$this->presenter,
199+
'V1:GroupExternalAttributes',
200+
'GET',
201+
['action' => 'get', 'groupId' => $group->getId()],
202+
);
203+
204+
Assert::count(count($group->getExternalAttributes()), $payload);
205+
$attributes = array_map(function ($a) {
206+
return join('|', [$a->getService(), $a->getKey(), $a->getValue()]);
207+
}, $group->getExternalAttributes()->toArray());
208+
foreach ($payload as $a) {
209+
$id = join('|', [$a->getService(), $a->getKey(), $a->getValue()]);
210+
Assert::true(in_array($id, $attributes));
211+
}
212+
}
213+
187214
public function testGetAttributesAdd()
188215
{
189216
PresenterTestHelper::loginDefaultAdmin($this->container, [TokenScope::GROUP_EXTERNAL]);

0 commit comments

Comments
 (0)