Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions app/V1Module/presenters/GroupExternalAttributesPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,24 @@ public function actionDefault(string $instance, ?string $service, ?string $user)
));
}

public function checkGet(string $groupId)
{
$group = $this->groups->findOrThrow($groupId);
if (!$this->groupAcl->canViewDetail($group)) {
throw new ForbiddenRequestException();
}
}

/**
* Get all external attributes for a group. This endpoint is meant to be used by webapp to display the attributes.
* @GET
*/
#[Path("groupId", new VUuid(), required: true)]
public function actionGet(string $groupId)
{
$attributes = $this->groupExternalAttributes->findBy(['group' => $groupId]);
$this->sendSuccessResponse($attributes);
}

public function checkAdd(string $groupId)
{
Expand Down
1 change: 1 addition & 0 deletions app/V1Module/router/RouterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ private static function createGroupAttributesRoutes(string $prefix): RouteList
$router = new RouteList();

$router[] = new GetRoute($prefix, "GroupExternalAttributes:");
$router[] = new GetRoute("$prefix/<groupId>", "GroupExternalAttributes:get");
$router[] = new PostRoute("$prefix/<groupId>", "GroupExternalAttributes:add");
$router[] = new DeleteRoute("$prefix/<groupId>", "GroupExternalAttributes:remove");
return $router;
Expand Down
27 changes: 27 additions & 0 deletions tests/Presenters/GroupExternalAttributesPresenter.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,33 @@ class TestGroupExternalAttributesPresenter extends Tester\TestCase
Assert::true($total > 0);
}

public function testGetGroupAttributes()
{
PresenterTestHelper::loginDefaultAdmin($this->container);

$groups = array_filter($this->presenter->groups->findAll(), function ($g) {
return !$g->isArchived() && count($g->getExternalAttributes()) > 1;
});
Assert::true(count($groups) > 0);
$group = reset($groups);

$payload = PresenterTestHelper::performPresenterRequest(
$this->presenter,
'V1:GroupExternalAttributes',
'GET',
['action' => 'get', 'groupId' => $group->getId()],
);

Assert::count(count($group->getExternalAttributes()), $payload);
$attributes = array_map(function ($a) {
return join('|', [$a->getService(), $a->getKey(), $a->getValue()]);
}, $group->getExternalAttributes()->toArray());
foreach ($payload as $a) {
$id = join('|', [$a->getService(), $a->getKey(), $a->getValue()]);
Assert::true(in_array($id, $attributes));
}
}

public function testGetAttributesAdd()
{
PresenterTestHelper::loginDefaultAdmin($this->container, [TokenScope::GROUP_EXTERNAL]);
Expand Down