Skip to content

Commit a428b29

Browse files
committed
Fixing add/remove attribute endpoints to get their group ID from the URL.
1 parent c28ae57 commit a428b29

File tree

2 files changed

+24
-26
lines changed

2 files changed

+24
-26
lines changed

app/presenters/GroupsPresenter.php

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -280,30 +280,29 @@ public function checkAddAttribute()
280280
* Proxy to ReCodEx that adds an attribute to a group.
281281
* This is rather low-level operation for super-admins only (to edit top-level and term groups).
282282
* @POST
283-
* @Param(type="post", name="groupId", validation="string:1..",
283+
* @Param(type="query", name="id", validation="string:1..",
284284
* description="ReCodEx ID of a group to which the attribute will be added.")
285285
* @Param(type="post", name="key", validation="string:1..",
286286
* description="Key of the attribute to add.")
287287
* @Param(type="post", name="value", validation="string:1..",
288288
* description="Value of the attribute to add.")
289289
*/
290-
public function actionAddAttribute()
290+
public function actionAddAttribute(string $id)
291291
{
292-
$groupId = $this->getRequest()->getPost('groupId');
293292
$key = $this->getRequest()->getPost('key');
294293
$value = $this->getRequest()->getPost('value');
295294

296295
$groups = $this->recodexApi->getGroups($this->getCurrentUser());
297-
$group = $groups[$groupId] ?? null;
296+
$group = $groups[$id] ?? null;
298297
if ($group === null) {
299-
throw new BadRequestException("Group $groupId does not exist or is not accessible by the user.");
298+
throw new BadRequestException("Group $id does not exist or is not accessible by the user.");
300299
}
301300

302301
if ($group->hasAttribute($key, $value)) {
303-
throw new BadRequestException("Group $groupId already has attribute $key=$value.");
302+
throw new BadRequestException("Group $id already has attribute $key=$value.");
304303
}
305304

306-
$this->recodexApi->addAttribute($groupId, $key, $value);
305+
$this->recodexApi->addAttribute($id, $key, $value);
307306
$this->sendSuccessResponse("OK");
308307
}
309308

@@ -318,30 +317,29 @@ public function checkRemoveAttribute()
318317
* Proxy to ReCodEx that removes an attribute from a group.
319318
* This is rather low-level operation for super-admins only (to edit top-level and term groups).
320319
* @POST
321-
* @Param(type="post", name="groupId", validation="string:1..",
320+
* @Param(type="query", name="id", validation="string:1..",
322321
* description="ReCodex ID of a group from which the attribute will be removed.")
323322
* @Param(type="post", name="key", validation="string:1..",
324323
* description="Key of the attribute to remove.")
325324
* @Param(type="post", name="value", validation="string:1..",
326325
* description="Value of the attribute to remove.")
327326
*/
328-
public function actionRemoveAttribute()
327+
public function actionRemoveAttribute(string $id)
329328
{
330-
$groupId = $this->getRequest()->getPost('groupId');
331329
$key = $this->getRequest()->getPost('key');
332330
$value = $this->getRequest()->getPost('value');
333331

334332
$groups = $this->recodexApi->getGroups($this->getCurrentUser());
335-
$group = $groups[$groupId] ?? null;
333+
$group = $groups[$id] ?? null;
336334
if ($group === null) {
337-
throw new BadRequestException("Group $groupId does not exist or is not accessible by the user.");
335+
throw new BadRequestException("Group $id does not exist or is not accessible by the user.");
338336
}
339337

340338
if (!$group->hasAttribute($key, $value)) {
341-
throw new BadRequestException("Group $groupId does not have attribute $key=$value.");
339+
throw new BadRequestException("Group $id does not have attribute $key=$value.");
342340
}
343341

344-
$this->recodexApi->removeAttribute($groupId, $key, $value);
342+
$this->recodexApi->removeAttribute($id, $key, $value);
345343
$this->sendSuccessResponse("OK");
346344
}
347345
}

tests/Presenters/GroupsPresenter.phpt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -835,8 +835,8 @@ class TestGroupsPresenter extends Tester\TestCase
835835
$this->presenter,
836836
'Groups',
837837
'POST',
838-
['action' => 'addAttribute'],
839-
['groupId' => 'g1', 'key' => 'foo', 'value' => 'baz']
838+
['action' => 'addAttribute', 'id' => 'g1'],
839+
['key' => 'foo', 'value' => 'baz']
840840
);
841841

842842
Assert::equal("OK", $payload);
@@ -860,8 +860,8 @@ class TestGroupsPresenter extends Tester\TestCase
860860
$this->presenter,
861861
'Groups',
862862
'POST',
863-
['action' => 'addAttribute'],
864-
['groupId' => 'g2', 'key' => 'foo', 'value' => 'baz']
863+
['action' => 'addAttribute', 'id' => 'g2'],
864+
['key' => 'foo', 'value' => 'baz']
865865
);
866866
}, BadRequestException::class);
867867
}
@@ -884,8 +884,8 @@ class TestGroupsPresenter extends Tester\TestCase
884884
$this->presenter,
885885
'Groups',
886886
'POST',
887-
['action' => 'addAttribute'],
888-
['groupId' => 'g1', 'key' => 'foo', 'value' => 'bar']
887+
['action' => 'addAttribute', 'id' => 'g1'],
888+
['key' => 'foo', 'value' => 'bar']
889889
);
890890
}, BadRequestException::class);
891891
}
@@ -922,8 +922,8 @@ class TestGroupsPresenter extends Tester\TestCase
922922
$this->presenter,
923923
'Groups',
924924
'POST',
925-
['action' => 'removeAttribute'],
926-
['groupId' => 'g1', 'key' => 'foo', 'value' => 'bar']
925+
['action' => 'removeAttribute', 'id' => 'g1'],
926+
['key' => 'foo', 'value' => 'bar']
927927
);
928928

929929
Assert::equal("OK", $payload);
@@ -947,8 +947,8 @@ class TestGroupsPresenter extends Tester\TestCase
947947
$this->presenter,
948948
'Groups',
949949
'POST',
950-
['action' => 'removeAttribute'],
951-
['groupId' => 'g2', 'key' => 'foo', 'value' => 'bar']
950+
['action' => 'removeAttribute', 'id' => 'g2'],
951+
['key' => 'foo', 'value' => 'bar']
952952
);
953953
}, BadRequestException::class);
954954
}
@@ -971,8 +971,8 @@ class TestGroupsPresenter extends Tester\TestCase
971971
$this->presenter,
972972
'Groups',
973973
'POST',
974-
['action' => 'removeAttribute'],
975-
['groupId' => 'g1', 'key' => 'foo', 'value' => 'baz']
974+
['action' => 'removeAttribute', 'id' => 'g1'],
975+
['key' => 'foo', 'value' => 'baz']
976976
);
977977
}, BadRequestException::class);
978978
}

0 commit comments

Comments
 (0)