web/admin: show warning when deleting currently logged in user

closes #1937

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-12-15 10:11:35 +01:00
parent 186634fc67
commit 7b8cde17e6
5 changed files with 43 additions and 2 deletions

View File

@ -187,6 +187,7 @@ export class DeleteBulkForm extends ModalButton {
<p class="pf-c-title"> <p class="pf-c-title">
${t`Are you sure you want to delete ${this.objects.length} ${this.objectLabel}?`} ${t`Are you sure you want to delete ${this.objects.length} ${this.objectLabel}?`}
</p> </p>
<slot name="notice"></slot>
</form> </form>
</section> </section>
<section class="pf-c-page__main-section"> <section class="pf-c-page__main-section">

View File

@ -5205,6 +5205,7 @@ msgid "UI settings"
msgstr "UI settings" msgstr "UI settings"
#: src/pages/events/EventInfo.ts #: src/pages/events/EventInfo.ts
#: src/pages/users/UserListPage.ts
msgid "UID" msgid "UID"
msgstr "UID" msgstr "UID"
@ -5770,6 +5771,10 @@ msgstr "Warning: Provider is not used by any Outpost."
msgid "Warning: Provider not assigned to any application." msgid "Warning: Provider not assigned to any application."
msgstr "Warning: Provider not assigned to any application." msgstr "Warning: Provider not assigned to any application."
#: src/pages/users/UserListPage.ts
msgid "Warning: You're about to delete the user you're logged in as ({0}). Proceed at your own risk."
msgstr "Warning: You're about to delete the user you're logged in as ({0}). Proceed at your own risk."
#: src/pages/outposts/OutpostListPage.ts #: src/pages/outposts/OutpostListPage.ts
msgid "Warning: authentik Domain is not configured, authentication will not work." msgid "Warning: authentik Domain is not configured, authentication will not work."
msgstr "Warning: authentik Domain is not configured, authentication will not work." msgstr "Warning: authentik Domain is not configured, authentication will not work."

View File

@ -5146,6 +5146,7 @@ msgid "UI settings"
msgstr "Paramètres d'UI" msgstr "Paramètres d'UI"
#: src/pages/events/EventInfo.ts #: src/pages/events/EventInfo.ts
#: src/pages/users/UserListPage.ts
msgid "UID" msgid "UID"
msgstr "UID" msgstr "UID"
@ -5708,6 +5709,10 @@ msgstr ""
msgid "Warning: Provider not assigned to any application." msgid "Warning: Provider not assigned to any application."
msgstr "Avertissement : le fournisseur n'est assigné à aucune application." msgstr "Avertissement : le fournisseur n'est assigné à aucune application."
#: src/pages/users/UserListPage.ts
msgid "Warning: You're about to delete the user you're logged in as ({0}). Proceed at your own risk."
msgstr ""
#: src/pages/outposts/OutpostListPage.ts #: src/pages/outposts/OutpostListPage.ts
msgid "Warning: authentik Domain is not configured, authentication will not work." msgid "Warning: authentik Domain is not configured, authentication will not work."
msgstr "Avertissement : le domaine d'authentik n'est pas configuré, l'authentification ne fonctionnera pas." msgstr "Avertissement : le domaine d'authentik n'est pas configuré, l'authentification ne fonctionnera pas."

View File

@ -5185,6 +5185,7 @@ msgid "UI settings"
msgstr "" msgstr ""
#: src/pages/events/EventInfo.ts #: src/pages/events/EventInfo.ts
#: src/pages/users/UserListPage.ts
msgid "UID" msgid "UID"
msgstr "" msgstr ""
@ -5750,6 +5751,10 @@ msgstr ""
msgid "Warning: Provider not assigned to any application." msgid "Warning: Provider not assigned to any application."
msgstr "" msgstr ""
#: src/pages/users/UserListPage.ts
msgid "Warning: You're about to delete the user you're logged in as ({0}). Proceed at your own risk."
msgstr ""
#: src/pages/outposts/OutpostListPage.ts #: src/pages/outposts/OutpostListPage.ts
msgid "Warning: authentik Domain is not configured, authentication will not work." msgid "Warning: authentik Domain is not configured, authentication will not work."
msgstr "" msgstr ""

View File

@ -4,12 +4,14 @@ import { CSSResult, TemplateResult, html } from "lit";
import { customElement, property } from "lit/decorators.js"; import { customElement, property } from "lit/decorators.js";
import { until } from "lit/directives/until.js"; import { until } from "lit/directives/until.js";
import PFAlert from "@patternfly/patternfly/components/Alert/alert.css";
import PFDescriptionList from "@patternfly/patternfly/components/DescriptionList/description-list.css"; import PFDescriptionList from "@patternfly/patternfly/components/DescriptionList/description-list.css";
import { CoreApi, User } from "@goauthentik/api"; import { CoreApi, User } from "@goauthentik/api";
import { AKResponse } from "../../api/Client"; import { AKResponse } from "../../api/Client";
import { DEFAULT_CONFIG, tenant } from "../../api/Config"; import { DEFAULT_CONFIG, tenant } from "../../api/Config";
import { me } from "../../api/Users";
import { uiConfig } from "../../common/config"; import { uiConfig } from "../../common/config";
import { PFColor } from "../../elements/Label"; import { PFColor } from "../../elements/Label";
import "../../elements/buttons/ActionButton"; import "../../elements/buttons/ActionButton";
@ -51,7 +53,7 @@ export class UserListPage extends TablePage<User> {
hideServiceAccounts = getURLParam<boolean>("hideServiceAccounts", true); hideServiceAccounts = getURLParam<boolean>("hideServiceAccounts", true);
static get styles(): CSSResult[] { static get styles(): CSSResult[] {
return super.styles.concat(PFDescriptionList); return super.styles.concat(PFDescriptionList, PFAlert);
} }
async apiEndpoint(page: number): Promise<AKResponse<User>> { async apiEndpoint(page: number): Promise<AKResponse<User>> {
@ -79,13 +81,14 @@ export class UserListPage extends TablePage<User> {
renderToolbarSelected(): TemplateResult { renderToolbarSelected(): TemplateResult {
const disabled = this.selectedElements.length < 1; const disabled = this.selectedElements.length < 1;
return html` <ak-forms-delete-bulk return html`<ak-forms-delete-bulk
objectLabel=${t`User(s)`} objectLabel=${t`User(s)`}
.objects=${this.selectedElements} .objects=${this.selectedElements}
.metadata=${(item: User) => { .metadata=${(item: User) => {
return [ return [
{ key: t`Username`, value: item.username }, { key: t`Username`, value: item.username },
{ key: t`ID`, value: item.pk.toString() }, { key: t`ID`, value: item.pk.toString() },
{ key: t`UID`, value: item.uid },
]; ];
}} }}
.usedBy=${(item: User) => { .usedBy=${(item: User) => {
@ -99,6 +102,28 @@ export class UserListPage extends TablePage<User> {
}); });
}} }}
> >
${until(
me().then((user) => {
const shouldShowWarning = this.selectedElements.find((el) => {
return el.pk === user.user.pk || el.pk == user.original?.pk;
});
if (shouldShowWarning) {
return html`
<div slot="notice" class="pf-c-form__alert">
<div class="pf-c-alert pf-m-inline pf-m-warning">
<div class="pf-c-alert__icon">
<i class="fas fa-exclamation-circle"></i>
</div>
<h4 class="pf-c-alert__title">
${t`Warning: You're about to delete the user you're logged in as (${shouldShowWarning.username}). Proceed at your own risk.`}
</h4>
</div>
</div>
`;
}
return html``;
}),
)}
<button ?disabled=${disabled} slot="trigger" class="pf-c-button pf-m-danger"> <button ?disabled=${disabled} slot="trigger" class="pf-c-button pf-m-danger">
${t`Delete`} ${t`Delete`}
</button> </button>