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:
1 parent
e7e3c73e77
commit
e4cd01e9ba
8 files changed
+151
-12
No files matched your search
+3
-3
@@ -530,11 +530,11 @@ osTicket's API cannot close a ticket, so this is the one place in the app that *
|
||||
they can no longer sign in, nothing of theirs is lost, *Switch on* brings it back) or **delete** one (a `DELETE`, for good: the user name has to be typed, and is checked again by the server against the user as Authentik has them now). **Refused, by the server, with the reason:** a service account, the account the token
|
||||
itself belongs to, and the last active administrator (so nobody can be locked out, or the sign-in in front of everything else cut off — for an edit, only when it would take them out of every group that makes them one); do those in Authentik. Each is in the audit log (*who edited — which fields, never their new values — switched off / on / deleted which user*). Switching off or deleting someone in Authentik does not end a session they
|
||||
already have in this app: end it under Users → *Signed in now*. Lists are read 200 at a time.
|
||||
**Groups** on the same tab, also read when it opens, lists the groups with how many are in each and lets an administrator **make** one (a name and nothing else, a `POST /core/groups/` with `is_superuser` always false: it starts empty and is never a group that makes administrators; a name Authentik already has is its own refusal), **rename** one and **put users in and take them out** (a `PATCH` of `name` and nothing else; `POST /core/groups/{id}/add_user/` and `remove_user/`, one user each,
|
||||
**Groups** on the same tab, also read when it opens, lists the groups with how many are in each and lets an administrator **make** one (a name and nothing else, a `POST /core/groups/` with `is_superuser` always false: it starts empty and is never a group that makes administrators; a name Authentik already has is its own refusal), **rename** one, **delete** one (a `DELETE`, for good — its members stay, just not in it: the group's name has to be typed and is checked again by the server against the group as Authentik has it now; **a group that makes its members administrators of Authentik is refused**, since deleting it would take that from all of them at once, possibly from the last administrator) and **put users in and take them out** (a `PATCH` of `name` and nothing else; `POST /core/groups/{id}/add_user/` and `remove_user/`, one user each,
|
||||
so somebody who joined meanwhile is never dropped by a whole list replacing the members). Everything asked is checked first and **nothing is changed unless all of it may be**: a service account, the token's own account, the last active administrator
|
||||
being taken out of the group that makes them one, and someone whose groups Authentik did not say (when taking them out of such a group) are refused with the reason. If Authentik fails part-way, the answer says how many of the changes had been made, and the audit log
|
||||
(*who renamed which group, who was put in and taken out*) has what was done. Whether a group **makes its members administrators of Authentik** is shown and is **not** changed or set from here, and groups are not deleted here. A group whose name is one of the
|
||||
*admin* or *operator* groups of **Settings → Sign-in** is marked *decides admins / operators here* and asks before it is saved: renaming it, or changing who is in it, changes people's roles in this app at their next sign-in. Making a group with such a name says so too (it is empty, so nothing changes until someone is put in it). Without it nothing about the page changes for anyone but an administrator, who sees where to add one. The calls (`GET /core/groups/`, `POST /core/users/`, `POST /core/users/{id}/recovery/`, `GET /core/users/`, `GET /core/users/{id}/`, `GET /core/users/me/`, `PATCH` (`is_active`, or `name`, `email` and `groups`) and `DELETE /core/users/{id}/`, `GET /core/groups/{id}/`, `POST /core/groups/`, `PATCH /core/groups/{id}/` and `POST /core/groups/{id}/add_user/` and `remove_user/`; asking for a link that lasts a day, which a version of
|
||||
(*who made, renamed or deleted which group — a deleted one with how many members it had and whether it decided a role here — and who was put in and taken out*) has what was done. Whether a group **makes its members administrators of Authentik** is shown and is **not** changed or set from here, and no group that makes administrators is deleted here either. A group whose name is one of the
|
||||
*admin* or *operator* groups of **Settings → Sign-in** is marked *decides admins / operators here* and asks before it is saved: renaming it, or changing who is in it, changes people's roles in this app at their next sign-in. Making a group with such a name says so too (it is empty, so nothing changes until someone is put in it); deleting one asks first and says that people in it lose that role here at their next sign-in. Without it nothing about the page changes for anyone but an administrator, who sees where to add one. The calls (`GET /core/groups/`, `POST /core/users/`, `POST /core/users/{id}/recovery/`, `GET /core/users/`, `GET /core/users/{id}/`, `GET /core/users/me/`, `PATCH` (`is_active`, or `name`, `email` and `groups`) and `DELETE /core/users/{id}/`, `GET /core/groups/{id}/`, `POST /core/groups/`, `PATCH` and `DELETE /core/groups/{id}/` and `POST /core/groups/{id}/add_user/` and `remove_user/`; asking for a link that lasts a day, which a version of
|
||||
Authentik that does not take that sets for itself) are **not verified against a live Authentik**; the tests use a pretend one.
|
||||
- **What it does:** every **five minutes** Authentik is read and stored — its version (and whether a newer one is out), whether a **worker** is connected, each **outpost** (the proxy outpost that guards your apps, an LDAP one) with how many instances reported in during the last five minutes and whether they run the right version, the
|
||||
**certificates** (those Authentik does not renew by itself) with their expiry, the **API tokens and app passwords** that expire, and how many **sign-ins failed** and **configuration errors** happened in the last day. **Apps → Authentik** shows it, with what runs out soonest first.
|
||||
|
||||
@@ -572,7 +572,7 @@ quietly never made. The page shows the photo and video counts, what the library
|
||||
|
||||
**Authentik** (Apps → Authentik). Add an Authentik integration (its address and an API token) and the app watches the sign-in in front of everything else: it raises a **critical** alert when an **outpost** that guards applications stops reporting, and warns when a **certificate** or an **API token** is
|
||||
about to run out (the token it reads Authentik with included), when **no worker** is connected, and when **sign-ins are failing** or flows are misconfigured. The page lists the outposts, what runs out soonest and the failed sign-ins of the last day. See INTEGRATIONS.md and docs/MONITORING.md.
|
||||
An administrator also has a second tab there, **Users and groups**, and can **make a user** on it — with a second, optional token for it — and gets a **one-time recovery link** to send them, so they choose their own password; no password is ever set or seen here, and the link is shown once and not kept. The same page lists the users and lets an administrator **edit** one (name, email, groups), **switch one off** (and on again) or **delete** one (the user name has to be typed); service accounts, the account the token belongs to and the last active administrator are refused. **Groups** can be made (empty, and never as a group that makes administrators), renamed and have users put in and taken out (not deleted, and whether a group makes administrators is not changed here); a group that decides roles in this app is marked and asks first.
|
||||
An administrator also has a second tab there, **Users and groups**, and can **make a user** on it — with a second, optional token for it — and gets a **one-time recovery link** to send them, so they choose their own password; no password is ever set or seen here, and the link is shown once and not kept. The same page lists the users and lets an administrator **edit** one (name, email, groups), **switch one off** (and on again) or **delete** one (the user name has to be typed); service accounts, the account the token belongs to and the last active administrator are refused. **Groups** can be made (empty, and never as a group that makes administrators), renamed, deleted (the name has to be typed; never one that makes administrators) and have users put in and taken out (whether a group makes administrators is not changed here); a group that decides roles in this app is marked and asks first.
|
||||
|
||||
**Jellyfin** (Apps → Jellyfin). Add a Jellyfin integration (its address and an API key) and the app shows whether it is up, **who is streaming what** and whether it is being transcoded, the scheduled tasks that failed, and a chart of how many watched at once; it warns when Jellyfin **wants a restart**, a
|
||||
**task failed** or **sign-ins are failing**. And when the Jellyfin runs on a server the app manages, **an update run asks first if people are watching**, and a patch plan **waits for them (up to two hours)** instead of restarting the machine in the middle of a film. See INTEGRATIONS.md and docs/MONITORING.md.
|
||||
|
||||
@@ -164,7 +164,7 @@ even further, to admin only:
|
||||
- **Immich** (Apps → Immich): everyone signed in sees the counts, the disk and the job queues; adding one (its address and API key) is an administrator's job, like any integration.
|
||||
- **Paperless-ngx** (Apps → Paperless): everyone signed in sees the counts, the system status and the names of the files that failed to import; adding one (its address and a superuser's token) is an administrator's job, like any integration.
|
||||
- **Prometheus** (Monitoring → Prometheus): everyone signed in sees the targets, what is down and the alerts firing; adding one (its address, and a token if it needs one) is an administrator's job, like any integration.
|
||||
- **Authentik** (Apps → Authentik): everyone signed in sees the outposts, what runs out and the failed-sign-in count (the names of tokens and certificates, not their values); adding one (its address and API token) is an administrator's job, like any integration. The **Users and groups** tab is an administrator's alone (others see only the status): **making a user** (and the groups to offer), **listing** the users and **editing, switching them off or on or deleting them**, and **making and renaming groups and changing who is in them**, are an administrator's alone, and only for an Authentik that was given a token for it; each is written in the audit log (who made, edited (which fields, not the new values), switched off, switched on or deleted which user, who made or renamed which group and who was put in or taken out of it, and who made a recovery link), never the link.
|
||||
- **Authentik** (Apps → Authentik): everyone signed in sees the outposts, what runs out and the failed-sign-in count (the names of tokens and certificates, not their values); adding one (its address and API token) is an administrator's job, like any integration. The **Users and groups** tab is an administrator's alone (others see only the status): **making a user** (and the groups to offer), **listing** the users and **editing, switching them off or on or deleting them**, and **making, renaming and deleting groups and changing who is in them**, are an administrator's alone, and only for an Authentik that was given a token for it; each is written in the audit log (who made, edited (which fields, not the new values), switched off, switched on or deleted which user, who made, renamed or deleted which group and who was put in or taken out of it, and who made a recovery link), never the link.
|
||||
- **Jellyfin** (Apps → Jellyfin): everyone signed in sees who is streaming and what is wrong; adding one (its address and API key) is an administrator's job, like any integration. Starting an update run on a server people are streaming from needs `startAnyway` — the update drawer asks (operators).
|
||||
- **Media managers** (Apps → Media managers, for Sonarr, Radarr and Prowlarr): everyone signed in sees what each says is wrong, its queue, disks and indexers; adding one (its API key) is an administrator's job, like any integration. Nothing on the page changes anything in them.
|
||||
- **App versions** (Operations → App versions): everyone signed in sees what each application runs against the newest release; switching the lookup of releases on and off, and the number of days after which a newer release is a warning, are an administrator's.
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* person gets to choose their own password: this app never sets, sees or keeps one. The link is handed back once and not stored.
|
||||
*
|
||||
* Looking after groups: the groups with who is in them (`GET /core/groups/`, one `GET /core/groups/{id}/`), making one (`POST /core/groups/` with a name and never as a group that makes administrators),
|
||||
* renaming one (`PATCH` with only `name`) and putting a user in or taking one out
|
||||
* renaming one (`PATCH` with only `name`), deleting one (`DELETE /core/groups/{id}/` — never one that makes administrators, which the caller refuses) and putting a user in or taking one out
|
||||
* (`POST /core/groups/{id}/add_user/` and `remove_user/`, one user each — never a whole list of members, so someone who joined meanwhile is not dropped). Whether a group makes its members
|
||||
* administrators of Authentik (`is_superuser`) is shown, and neither changed nor set when one is made, from here.
|
||||
*
|
||||
@@ -212,6 +212,7 @@ export interface AuthentikUsersAdapter {
|
||||
getGroup(id: string): Promise<AuthentikGroupDetail>;
|
||||
createGroup(name: string): Promise<AuthentikGroupDetail>;
|
||||
renameGroup(id: string, name: string): Promise<AuthentikGroupDetail>;
|
||||
deleteGroup(id: string): Promise<void>;
|
||||
addMember(id: string, userPk: number): Promise<void>;
|
||||
removeMember(id: string, userPk: number): Promise<void>;
|
||||
createUser(input: NewAuthentikUser): Promise<CreatedAuthentikUser>;
|
||||
@@ -314,6 +315,10 @@ export function createAuthentikUsersAdapter(config: AuthentikUsersConfig): Authe
|
||||
return group;
|
||||
}
|
||||
|
||||
async function deleteGroup(id: string): Promise<void> {
|
||||
await call("DELETE", `/core/groups/${groupId(id)}/`);
|
||||
}
|
||||
|
||||
async function addMember(id: string, userPk: number): Promise<void> {
|
||||
await call("POST", `/core/groups/${groupId(id)}/add_user/`, { pk: wholeNumber(userPk) }, true);
|
||||
}
|
||||
@@ -342,5 +347,5 @@ export function createAuthentikUsersAdapter(config: AuthentikUsersConfig): Authe
|
||||
return link;
|
||||
}
|
||||
|
||||
return withDiagLogging("authentik", { listUsers, getUser, whoAmI, activeAdmins, setActive, updateUser, deleteUser, listGroupDetails, getGroup, createGroup, renameGroup, addMember, removeMember, listGroups, createUser, recoveryLink });
|
||||
return withDiagLogging("authentik", { listUsers, getUser, whoAmI, activeAdmins, setActive, updateUser, deleteUser, listGroupDetails, getGroup, createGroup, renameGroup, deleteGroup, addMember, removeMember, listGroups, createUser, recoveryLink });
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}));
|
||||
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* Looking after Authentik groups: reading them with who is in them, making one, renaming one, putting users in and taking them out — and what is refused (service accounts, the account the token belongs
|
||||
* Looking after Authentik groups: reading them with who is in them, making one, renaming one, deleting one, putting users in and taking them out — and what is refused (service accounts, the account the token belongs
|
||||
* to, the last active administrator losing that, a user whose groups Authentik did not say), that nothing is changed unless all of it may be, how far a failure got, who may, what is in the
|
||||
* audit log, and which groups decide roles in this app.
|
||||
*
|
||||
@@ -136,6 +136,11 @@ before(async () => {
|
||||
const group = groupTable.find((g) => g.pk === grp[1]);
|
||||
if (!group) return send(404, { detail: "Not found." });
|
||||
if (!grp[2] && req.method === "GET") return send(200, group);
|
||||
if (!grp[2] && req.method === "DELETE") {
|
||||
groupTable = groupTable.filter((g) => g.pk !== group.pk);
|
||||
for (const u of userTable) if (u.groups) u.groups = u.groups.filter((g) => g !== group.pk);
|
||||
return send(204);
|
||||
}
|
||||
if (!grp[2] && req.method === "PATCH") {
|
||||
Object.assign(group, JSON.parse(body));
|
||||
return send(200, group);
|
||||
@@ -219,6 +224,20 @@ describe("the calls", () => {
|
||||
assert.deepEqual(groupTable.find((g) => g.pk === G_FAMILY)!.users, [4]);
|
||||
});
|
||||
|
||||
test("deleting is a DELETE of that group, answered with nothing", async () => {
|
||||
reset();
|
||||
await adapter().deleteGroup(G_OTHER);
|
||||
assert.deepEqual([seen[0].method, seen[0].path], ["DELETE", `/api/v3/core/groups/${G_OTHER}/`]);
|
||||
assert.equal(groupTable.some((g) => g.pk === G_OTHER), false);
|
||||
await assert.rejects(
|
||||
() => adapter().deleteGroup(G_OTHER),
|
||||
(err: Error & { kind?: string }) => err.kind === "missing",
|
||||
);
|
||||
seen.length = 0;
|
||||
await assert.rejects(() => adapter().deleteGroup("../x"), /not a group id/);
|
||||
assert.deepEqual(seen, []);
|
||||
});
|
||||
|
||||
test("a group id that is not an id and a user id that is not a whole number are never put in the address", async () => {
|
||||
reset();
|
||||
for (const bad of ["../../x", "", "not-a-uuid", `${G_FAMILY}/../x`]) {
|
||||
@@ -240,6 +259,7 @@ describe("the routes", () => {
|
||||
const as = (sub: string) => ({ "content-type": "application/json", "x-sub": sub });
|
||||
const details = (sub = "admin") => fetch(`${base}/${id}/group-details`, { headers: as(sub) });
|
||||
const change = (gid: string, body: unknown, sub = "admin") => fetch(`${base}/${id}/groups/${gid}`, { method: "PATCH", headers: as(sub), body: JSON.stringify(body) });
|
||||
const remove = (gid: string, name: unknown, sub = "admin") => fetch(`${base}/${id}/groups/${gid}`, { method: "DELETE", headers: as(sub), body: JSON.stringify({ name }) });
|
||||
const make = (body: unknown, sub = "admin") => fetch(`${base}/${id}/groups`, { method: "POST", headers: as(sub), body: JSON.stringify(body) });
|
||||
const writes = () => seen.filter((s) => s.method !== "GET");
|
||||
const audit = async (action: string) => (await db.select().from(auditLog)).filter((e) => e.action === action);
|
||||
@@ -439,6 +459,48 @@ describe("the routes", () => {
|
||||
assert.deepEqual(seen, []);
|
||||
});
|
||||
|
||||
test("deleting a group: admin only; the name has to match the group now; then it is gone, its members stay, and the audit log says so", async () => {
|
||||
reset();
|
||||
await updateSettings({ signIn: { roleFromGroups: false, groupsClaim: "groups", adminGroups: [], operatorGroups: [], otherwise: "viewer" } });
|
||||
for (const sub of ["viewer", "operator"]) assert.equal((await remove(G_OTHER, "Other", sub)).status, 403, sub);
|
||||
assert.deepEqual(seen, []);
|
||||
assert.equal((await remove(G_OTHER, undefined)).status, 400);
|
||||
assert.equal((await remove(G_OTHER, "")).status, 400);
|
||||
assert.equal((await remove("not-a-uuid", "Other")).status, 400);
|
||||
const wrong = await remove(G_OTHER, "Family");
|
||||
assert.equal(wrong.status, 400);
|
||||
assert.equal(((await wrong.json()) as { error: string }).error, "name_mismatch");
|
||||
assert.deepEqual(writes(), []);
|
||||
assert.equal(groupTable.some((g) => g.pk === G_OTHER), true);
|
||||
// Family has carol in it: she stays, just not in the group.
|
||||
assert.equal((await remove(G_FAMILY, "Family")).status, 204);
|
||||
assert.equal(groupTable.some((g) => g.pk === G_FAMILY), false);
|
||||
assert.equal(userTable.some((u) => u.username === "carol"), true);
|
||||
assert.deepEqual(writes().map((s) => [s.method, s.path]), [["DELETE", `/api/v3/core/groups/${G_FAMILY}/`]]);
|
||||
const [entry] = await audit("delete_authentik_group");
|
||||
assert.deepEqual([entry.category, entry.targetType, entry.targetId], ["integration", "authentik_group", G_FAMILY]);
|
||||
assert.deepEqual(JSON.parse(entry.detail ?? "{}"), { integrationId: id, integration: "Front door", group: "Family", members: 1, decidesRole: null });
|
||||
});
|
||||
|
||||
test("a group that makes administrators is refused and not touched; one that decides roles here may be deleted, and the audit log says it was one", async () => {
|
||||
reset();
|
||||
await updateSettings({ signIn: { roleFromGroups: true, groupsClaim: "groups", adminGroups: ["admins"], operatorGroups: ["Family"], otherwise: "viewer" } });
|
||||
await refused(await remove(G_ADMIN, "admins"), /makes its members administrators/);
|
||||
assert.deepEqual(writes(), []);
|
||||
assert.equal(groupTable.some((g) => g.pk === G_ADMIN), true);
|
||||
assert.equal((await remove(G_FAMILY, "Family")).status, 204);
|
||||
const entry = (await audit("delete_authentik_group")).at(-1)!;
|
||||
assert.equal(JSON.parse(entry.detail ?? "{}").decidesRole, "operator");
|
||||
});
|
||||
|
||||
test("a group that is gone is not found when deleting; an Authentik with no token for managing users is not asked", async () => {
|
||||
reset();
|
||||
assert.equal((await remove("99999999-9999-4999-8999-999999999999", "x")).status, 404);
|
||||
seen.length = 0;
|
||||
assert.equal((await fetch(`${base}/${readOnly}/groups/${G_FAMILY}`, { method: "DELETE", headers: as("admin"), body: JSON.stringify({ name: "Family" }) })).status, 400);
|
||||
assert.deepEqual(seen, []);
|
||||
});
|
||||
|
||||
test("a group that is gone is not found; an Authentik with no token for managing users is not asked anything", async () => {
|
||||
reset();
|
||||
assert.equal((await change("99999999-9999-4999-8999-999999999999", { name: "x" })).status, 404);
|
||||
|
||||
@@ -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 }) }),
|
||||
|
||||
@@ -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>
|
||||
),
|
||||
|
||||
Reference in new issue
Block a user