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

+1
View File
@@ -3445,6 +3445,7 @@ export const api = {
setUserActive: (id: number, pk: number, active: boolean) => request<{ user: AuthentikPerson }>(`/api/authentik/${id}/users/${pk}/active`, { method: "POST", body: JSON.stringify({ active }) }),
groupDetails: (id: number) => request<{ groups: AuthentikGroupDetail[]; people: AuthentikGroupPerson[]; more: boolean; self: number | null }>(`/api/authentik/${id}/group-details`),
createGroup: (id: number, name: string) => request<{ group: AuthentikGroupDetail }>(`/api/authentik/${id}/groups`, { method: "POST", body: JSON.stringify({ name }) }),
deleteGroup: (id: number, gid: string, name: string) => request<void>(`/api/authentik/${id}/groups/${gid}`, { method: "DELETE", body: JSON.stringify({ name }) }),
updateGroup: (id: number, gid: string, body: { name?: string; membersAdd?: number[]; membersRemove?: number[] }) => request<{ changed: string[]; added: number; removed: number }>(`/api/authentik/${id}/groups/${gid}`, { method: "PATCH", body: JSON.stringify(body) }),
updateUser: (id: number, pk: number, body: { name?: string; email?: string; groupsAdd?: string[]; groupsRemove?: string[] }) => request<{ user: AuthentikPerson; changed: string[] }>(`/api/authentik/${id}/users/${pk}`, { method: "PATCH", body: JSON.stringify(body) }),
deleteUser: (id: number, pk: number, username: string) => request<void>(`/api/authentik/${id}/users/${pk}`, { method: "DELETE", body: JSON.stringify({ username }) }),
+41 -4
View File
@@ -1,7 +1,7 @@
import { useEffect, useState, type FormEvent } from "react";
import { api, type AuthentikGroupDetail, type AuthentikGroupPerson, type AuthentikInfo } from "../api/client";
import { ErrorNotice, SuccessNotice } from "./Notice";
import { confirmDialog } from "../utils/dialogs";
import { confirmDialog, promptDialog } from "../utils/dialogs";
import { readableError } from "../utils/errors";
function EditGroup({ g, people, self, busy, onSave, onCancel }: { g: AuthentikGroupDetail; people: AuthentikGroupPerson[]; self: number | null; busy: boolean; onSave: (name: string, add: number[], remove: number[]) => void; onCancel: () => void }) {
@@ -74,7 +74,7 @@ function EditGroup({ g, people, self, busy, onSave, onCancel }: { g: AuthentikGr
}
/**
* The groups of an Authentik, read when the tab opens, for an administrator to make, rename and to put users in and take them out of. Whether a group makes its members administrators is shown, not changed — and a group
* The groups of an Authentik, read when the tab opens, for an administrator to make, rename, delete and to put users in and take them out of. Whether a group makes its members administrators is shown, not changed — and a group
* made here never does. A group that
* decides somebody's role in this app says so, and asks before it is changed.
*/
@@ -133,6 +133,34 @@ export default function AuthentikGroupList({ a }: { a: AuthentikInfo }) {
}
}
async function removeGroup(g: AuthentikGroupDetail) {
const members = g.members === null ? "" : g.members.length === 0 ? " It has no members." : ` Its ${g.members.length} member${g.members.length === 1 ? "" : "s"} stay${g.members.length === 1 ? "s" : ""}, just not in it.`;
const roles = g.decidesRole ? ` It decides who is ${g.decidesRole === "admin" ? "an administrator" : "an operator"} in this app (Settings → Sign-in): people in it lose that role here at their next sign-in.` : "";
const typed = await promptDialog({
title: "Delete group",
message: `This deletes the group "${g.name}" in ${a.name} for good. It cannot be undone.${members}${roles} Type the name of the group to confirm.`,
label: "Group name",
confirmLabel: "Delete",
required: true,
});
if (typed === null) return;
if (typed.trim() !== g.name) {
setError("That is not the name of the group, so nothing was deleted.");
return;
}
setBusy(g.id);
setError(null);
setNotice(null);
try {
await api.authentik.deleteGroup(a.id, g.id, g.name);
setNotice(`Deleted "${g.name}".`);
await load();
} catch (err) {
setError(readableError(err));
setBusy(null);
}
}
async function save(g: AuthentikGroupDetail, name: string, add: number[], remove: number[]) {
if (g.decidesRole) {
const ok = await confirmDialog({
@@ -219,10 +247,19 @@ export default function AuthentikGroupList({ a }: { a: AuthentikInfo }) {
{g.decidesRole && <span className="badge bg-blue-lt text-blue ms-1">decides {g.decidesRole === "admin" ? "admins" : "operators"} here</span>}
</td>
<td className="text-end text-secondary">{g.members === null ? "?" : g.members.length}</td>
<td className="text-end">
<button type="button" className="btn btn-sm btn-outline-secondary" disabled={busy !== null} onClick={() => { setEditing(g.id); setNotice(null); }}>
<td className="text-end text-nowrap">
<button type="button" className="btn btn-sm btn-outline-secondary me-1" disabled={busy !== null} onClick={() => { setEditing(g.id); setNotice(null); }}>
Edit
</button>
{g.admin ? (
<span className="small text-secondary" title="A group that makes administrators of Authentik is deleted in Authentik, not here.">
deleted in Authentik
</span>
) : (
<button type="button" className="btn btn-sm btn-outline-danger" disabled={busy !== null} onClick={() => void removeGroup(g)}>
Delete
</button>
)}
</td>
</tr>
),