Delete Authentik groups

Each group in Apps → Authentik → Users and groups gets a Delete button: the
group's name has to be typed, and the server checks it against the group as
Authentik has it now. A group that makes its members administrators is
refused (deleted in Authentik). A group that decides roles in this app may be
deleted after a warning, and the audit log records its member count and that
it decided a role. Members stay, just not in the group.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-11-01 04:00:47 +01:00
1 parent e7e3c73e77
commit e4cd01e9ba
8 files changed
+151 -12

No files matched your search

+34
View File
@@ -444,3 +444,37 @@ authentikRouter.post("/:id/groups", requireRole("admin"), asyncHandler(async (re
sendFailure(res, err);
}
}));
const deleteGroupSchema = z.object({ name: z.string().min(1).max(200) });
/**
* Deletes a group for good; its members stay, just not in it. The group's name has to be sent along and has to be the one it has now (a page that is minutes old cannot delete another group),
* and a group that makes its members administrators of Authentik is refused: deleting it would take that from all of them at once, possibly from the last administrator. A group that decides
* roles in this app (Settings → Sign-in) may be deleted — the page asks first — and the audit log says it was one.
*/
authentikRouter.delete("/:id/groups/:gid", requireRole("admin"), asyncHandler(async (req, res) => {
const parsed = deleteGroupSchema.safeParse(req.body);
if (!parsed.success) return res.status(400).json({ error: "invalid_body", message: "The name of the group has to be sent along to delete it." });
const gid = req.params.gid;
if (!GROUP_ID.test(gid)) return res.status(400).json({ error: "invalid_group" });
const target = await usersAdapterFor(req.params.id, res);
if (!target) return;
try {
const group = await target.adapter.getGroup(gid);
if (group.name !== parsed.data.name) return res.status(400).json({ error: "name_mismatch", message: "That is not the name of that group." });
if (group.admin) return res.status(409).json({ error: "refused", message: "That group makes its members administrators of Authentik; deleting it would take that from all of them at once. Do it in Authentik if you mean to." });
const settings = await getSettings();
await target.adapter.deleteGroup(gid);
await recordAudit({
actor: req.currentUser!,
category: "integration",
action: "delete_authentik_group",
targetType: "authentik_group",
targetId: gid,
detail: { integrationId: target.id, integration: target.name, group: group.name, members: group.members?.length ?? null, decidesRole: roleForGroupName(settings.signIn, group.name) },
});
res.status(204).end();
} catch (err) {
sendFailure(res, err);
}
}));