Create Authentik groups from Apps → Authentik
A New group form in the Groups section makes a group with a name and nothing else: it starts empty and is never one that makes administrators of Authentik. A name Authentik already has is refused in its own words, and a name that decides a role in this app (Settings → Sign-in) is said to. Admin only; audited with who made which group. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6c5a5f0bd6
commit
c9385387bc
9 files changed
+152
-12
No files matched your search
@@ -423,3 +423,24 @@ authentikRouter.patch("/:id/groups/:gid", requireRole("admin"), asyncHandler(asy
|
||||
sendFailure(res, err);
|
||||
}
|
||||
}));
|
||||
|
||||
const newGroupSchema = z.object({ name: z.string().trim().min(1, "A group needs a name.").max(200) });
|
||||
|
||||
/**
|
||||
* Makes a group: a name, nothing else — it has no members (they are put in with the editor, which asks first where a group decides roles here) and it is never one that makes administrators of
|
||||
* Authentik. A name Authentik already has is its own refusal. The answer says whether the new name decides a role in this app, so the page can say what putting someone in it would mean.
|
||||
*/
|
||||
authentikRouter.post("/:id/groups", requireRole("admin"), asyncHandler(async (req, res) => {
|
||||
const parsed = newGroupSchema.safeParse(req.body);
|
||||
if (!parsed.success) return res.status(400).json({ error: "invalid_body", message: parsed.error.issues[0]?.message ?? "That is not a group.", details: parsed.error.flatten() });
|
||||
const target = await usersAdapterFor(req.params.id, res);
|
||||
if (!target) return;
|
||||
try {
|
||||
const group = await target.adapter.createGroup(parsed.data.name);
|
||||
await recordAudit({ actor: req.currentUser!, category: "integration", action: "create_authentik_group", targetType: "authentik_group", targetId: group.id, detail: { integrationId: target.id, integration: target.name, group: group.name } });
|
||||
const settings = await getSettings();
|
||||
res.status(201).json({ group: { ...group, decidesRole: roleForGroupName(settings.signIn, group.name) } });
|
||||
} catch (err) {
|
||||
sendFailure(res, err);
|
||||
}
|
||||
}));
|
||||
Reference in new issue
Block a user