From a7fc579202ed4a0ecb764508c6b9dd6122fd8226 Mon Sep 17 00:00:00 2001 From: Jens L Date: Mon, 27 Mar 2023 16:27:34 +0200 Subject: [PATCH] web/admin: show warning when adding user to superuser group (#5091) Signed-off-by: Jens Langhammer --- web/src/admin/groups/GroupListPage.ts | 2 +- web/src/admin/groups/RelatedGroupList.ts | 4 ++-- web/src/admin/users/GroupSelectModal.ts | 16 +++++++++++++++- web/src/admin/users/RelatedUserList.ts | 15 ++++++++++++--- web/src/elements/forms/ModalForm.ts | 1 + 5 files changed, 31 insertions(+), 7 deletions(-) diff --git a/web/src/admin/groups/GroupListPage.ts b/web/src/admin/groups/GroupListPage.ts index 12cf92f48..3df90d36a 100644 --- a/web/src/admin/groups/GroupListPage.ts +++ b/web/src/admin/groups/GroupListPage.ts @@ -81,7 +81,7 @@ export class GroupListPage extends TablePage { html`${item.name}`, html`${item.parentName || t`-`}`, html`${Array.from(item.users || []).length}`, - html` + html` ${item.isSuperuser ? t`Yes` : t`No`} `, html` diff --git a/web/src/admin/groups/RelatedGroupList.ts b/web/src/admin/groups/RelatedGroupList.ts index 70996f500..fb2429979 100644 --- a/web/src/admin/groups/RelatedGroupList.ts +++ b/web/src/admin/groups/RelatedGroupList.ts @@ -32,7 +32,7 @@ export class RelatedGroupAdd extends Form<{ groups: string[] }> { return t`Successfully added user to group(s).`; } - send = async (data: { groups: string[] }): Promise<{ groups: string[] }> => { + async send(data: { groups: string[] }): Promise { await Promise.all( data.groups.map((group) => { return new CoreApi(DEFAULT_CONFIG).coreGroupsAddUserCreate({ @@ -44,7 +44,7 @@ export class RelatedGroupAdd extends Form<{ groups: string[] }> { }), ); return data; - }; + } renderForm(): TemplateResult { return html`
diff --git a/web/src/admin/users/GroupSelectModal.ts b/web/src/admin/users/GroupSelectModal.ts index adcb3006b..19dbb0138 100644 --- a/web/src/admin/users/GroupSelectModal.ts +++ b/web/src/admin/users/GroupSelectModal.ts @@ -8,9 +8,11 @@ import { TableModal } from "@goauthentik/elements/table/TableModal"; import { t } from "@lingui/macro"; -import { TemplateResult, html } from "lit"; +import { CSSResult, TemplateResult, html } from "lit"; import { customElement, property } from "lit/decorators.js"; +import PFBanner from "@patternfly/patternfly/components/Banner/banner.css"; + import { CoreApi, Group } from "@goauthentik/api"; @customElement("ak-user-group-select-table") @@ -27,6 +29,10 @@ export class GroupSelectModal extends TableModal { order = "name"; + static get styles(): CSSResult[] { + return super.styles.concat(PFBanner); + } + async apiEndpoint(page: number): Promise> { return new CoreApi(DEFAULT_CONFIG).coreGroupsList({ ordering: this.order, @@ -61,11 +67,19 @@ export class GroupSelectModal extends TableModal { } renderModalInner(): TemplateResult { + const willSuperuser = this.selectedElements.filter((g) => g.isSuperuser).length > 0; return html`

${t`Select groups to add user to`}

+ ${willSuperuser + ? html` +
+ ${t`Warning: Adding the user to the selected group(s) will give them superuser permissions.`} +
+ ` + : html``}
${this.renderTable()}