Skip to content

Commit 4077ef0

Browse files
committed
Implementing an endpoint that updates archived status of a group.
1 parent 70527b5 commit 4077ef0

4 files changed

Lines changed: 49 additions & 0 deletions

File tree

app/helpers/Recodex/RecodexApiHelper.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,4 +503,18 @@ public function createTermGroup(string $instanceId, string $parentGroupId, strin
503503

504504
return null;
505505
}
506+
507+
/**
508+
* Set or unset archived flag of a group.
509+
* @param string $groupId ReCodEx ID of a group which is being updated
510+
* @param bool $archived true to set archived flag, false to unset
511+
*/
512+
public function setGroupArchivedFlag(string $groupId, bool $archived): void
513+
{
514+
Debugger::log(
515+
"ReCodEx::setGroupArchivedFlag('$groupId', " . ($archived ? 'true' : 'false') . ")",
516+
Debugger::INFO
517+
);
518+
$this->post("groups/$groupId/archived", [], ['value' => $archived]);
519+
}
506520
}

app/presenters/GroupsPresenter.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Exceptions\BadRequestException;
66
use App\Exceptions\ForbiddenRequestException;
77
use App\Exceptions\NotFoundException;
8+
use App\Exceptions\RecodexApiException;
89
use App\Helpers\RecodexGroup;
910
use App\Model\Entity\SisScheduleEvent;
1011
use App\Model\Repository\SisScheduleEvents;
@@ -401,4 +402,35 @@ public function actionRemoveAttribute(string $id)
401402
$this->recodexApi->removeAttribute($id, $key, $value);
402403
$this->sendSuccessResponse("OK");
403404
}
405+
406+
public function checkSetArchived()
407+
{
408+
if (!$this->groupAcl->canSetArchived()) {
409+
throw new ForbiddenRequestException("You do not have permissions to set archived flag.");
410+
}
411+
}
412+
413+
/**
414+
* Proxy to ReCodEx that sets or unsets the 'archived' flag of a group.
415+
* @POST
416+
* @Param(type="query", name="id", validation="string:1..",
417+
* description="ReCodEx ID of a group for which the archived flag will be set or unset.")
418+
* @Param(type="post", name="value", validation="bool",
419+
* description="Boolean value indicating whether the group should be archived or not.")
420+
*/
421+
public function actionSetArchived(string $id)
422+
{
423+
$archived = $this->getRequest()->getPost('value');
424+
if (!is_bool($archived)) {
425+
throw new BadRequestException("Missing or invalid 'value' parameter (expected boolean).");
426+
}
427+
428+
try {
429+
$this->recodexApi->setGroupArchivedFlag($id, $archived);
430+
} catch (RecodexApiException $e) {
431+
throw new BadRequestException("Failed to set archived flag for group $id: " . $e->getMessage());
432+
}
433+
434+
$this->sendSuccessResponse("OK");
435+
}
404436
}

app/router/RouterFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ private static function createGroupsRoutes(string $prefix): RouteList
8383
$router[] = new PostRoute("$prefix/<id>/add-attribute", "Groups:addAttribute");
8484
$router[] = new PostRoute("$prefix/<id>/remove-attribute", "Groups:removeAttribute");
8585
$router[] = new PostRoute("$prefix/<parentId>/create-term/<term>", "Groups:createTerm");
86+
$router[] = new PostRoute("$prefix/<id>/archived", "Groups:setArchived");
8687
return $router;
8788
}
8889
}

app/security/ACL/IGroupPermissions.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ public function canViewTeacher(): bool;
1313
public function canEditRawAttributes(): bool;
1414

1515
public function canCreateTermGroup(): bool;
16+
17+
public function canSetArchived(): bool;
1618
}

0 commit comments

Comments
 (0)