From e621eb74550cbcb457f7e2a8a4ad0cafcbce74cf Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 27 Mar 2021 23:11:44 +0100 Subject: [PATCH] web: cleanup message API, use enum for level Signed-off-by: Jens Langhammer --- authentik/root/messages/storage.py | 2 +- web/src/elements/buttons/ActionButton.ts | 5 +++-- web/src/elements/buttons/ModalButton.ts | 5 +++-- web/src/elements/forms/ConfirmationForm.ts | 5 +++-- web/src/elements/forms/DeleteForm.ts | 5 +++-- web/src/elements/messages/Message.ts | 13 ++++++++++--- web/src/elements/messages/MessageContainer.ts | 4 ++-- .../authenticator_totp/AuthenticatorTOTPStage.ts | 3 ++- web/src/pages/generic/SiteShell.ts | 5 +++-- web/src/pages/users/UserActiveForm.ts | 5 +++-- 10 files changed, 33 insertions(+), 19 deletions(-) diff --git a/authentik/root/messages/storage.py b/authentik/root/messages/storage.py index 0999c276c..4e23ca729 100644 --- a/authentik/root/messages/storage.py +++ b/authentik/root/messages/storage.py @@ -25,7 +25,7 @@ class ChannelsStorage(FallbackStorage): uid, { "type": "event.update", - "level_tag": message.level_tag, + "level": message.level_tag, "tags": message.tags, "message": message.message, }, diff --git a/web/src/elements/buttons/ActionButton.ts b/web/src/elements/buttons/ActionButton.ts index 868c99b36..6e3826f01 100644 --- a/web/src/elements/buttons/ActionButton.ts +++ b/web/src/elements/buttons/ActionButton.ts @@ -2,6 +2,7 @@ import { customElement, property } from "lit-element"; import { ERROR_CLASS, SUCCESS_CLASS } from "../../constants"; import { SpinnerButton } from "./SpinnerButton"; import { showMessage } from "../messages/MessageContainer"; +import { MessageLevel } from "../messages/Message"; @customElement("ak-action-button") export class ActionButton extends SpinnerButton { @@ -26,13 +27,13 @@ export class ActionButton extends SpinnerButton { .catch((e: Error | Response) => { if (e instanceof Error) { showMessage({ - level_tag: "error", + level: MessageLevel.error, message: e.toString() }); } else { e.text().then(t => { showMessage({ - level_tag: "error", + level: MessageLevel.error, message: t }); }); diff --git a/web/src/elements/buttons/ModalButton.ts b/web/src/elements/buttons/ModalButton.ts index 111fc0d04..34061b451 100644 --- a/web/src/elements/buttons/ModalButton.ts +++ b/web/src/elements/buttons/ModalButton.ts @@ -19,6 +19,7 @@ import { convertToSlug } from "../../utils"; import { SpinnerButton } from "./SpinnerButton"; import { PRIMARY_CLASS, EVENT_REFRESH } from "../../constants"; import { showMessage } from "../messages/MessageContainer"; +import { MessageLevel } from "../messages/Message"; @customElement("ak-modal-button") export class ModalButton extends LitElement { @@ -122,7 +123,7 @@ export class ModalButton extends LitElement { }) .catch((e) => { showMessage({ - level_tag: "error", + level: MessageLevel.error, message: "Unexpected error" }); console.error(e); @@ -150,7 +151,7 @@ export class ModalButton extends LitElement { }) .catch((e) => { showMessage({ - level_tag: "error", + level: MessageLevel.error, message: "Unexpected error" }); console.error(e); diff --git a/web/src/elements/forms/ConfirmationForm.ts b/web/src/elements/forms/ConfirmationForm.ts index edc2dbf55..0bfdfd3b2 100644 --- a/web/src/elements/forms/ConfirmationForm.ts +++ b/web/src/elements/forms/ConfirmationForm.ts @@ -2,6 +2,7 @@ import { gettext } from "django"; import { customElement, html, property, TemplateResult } from "lit-element"; import { EVENT_REFRESH } from "../../constants"; import { ModalButton } from "../buttons/ModalButton"; +import { MessageLevel } from "../messages/Message"; import { showMessage } from "../messages/MessageContainer"; @customElement("ak-forms-confirm") @@ -36,14 +37,14 @@ export class ConfirmationForm extends ModalButton { onSuccess(): void { showMessage({ message: gettext(this.successMessage), - level_tag: "success", + level: MessageLevel.success, }); } onError(e: Error): void { showMessage({ message: gettext(`${this.errorMessage}: ${e.toString()}`), - level_tag: "error", + level: MessageLevel.error, }); } diff --git a/web/src/elements/forms/DeleteForm.ts b/web/src/elements/forms/DeleteForm.ts index 7fbce8d8e..45c1e8d09 100644 --- a/web/src/elements/forms/DeleteForm.ts +++ b/web/src/elements/forms/DeleteForm.ts @@ -2,6 +2,7 @@ import { gettext } from "django"; import { customElement, html, property, TemplateResult } from "lit-element"; import { EVENT_REFRESH } from "../../constants"; import { ModalButton } from "../buttons/ModalButton"; +import { MessageLevel } from "../messages/Message"; import { showMessage } from "../messages/MessageContainer"; @customElement("ak-forms-delete") @@ -34,14 +35,14 @@ export class DeleteForm extends ModalButton { onSuccess(): void { showMessage({ message: gettext(`Successfully deleted ${this.objectLabel} ${ this.obj?.name }`), - level_tag: "success", + level: MessageLevel.success, }); } onError(e: Error): void { showMessage({ message: gettext(`Failed to delete ${this.objectLabel}: ${e.toString()}`), - level_tag: "error", + level: MessageLevel.error, }); } diff --git a/web/src/elements/messages/Message.ts b/web/src/elements/messages/Message.ts index 1c215f190..fddedd87c 100644 --- a/web/src/elements/messages/Message.ts +++ b/web/src/elements/messages/Message.ts @@ -5,10 +5,14 @@ import PFAlert from "@patternfly/patternfly/components/Alert/alert.css"; import PFBase from "@patternfly/patternfly/patternfly-base.css"; import PFButton from "@patternfly/patternfly/components/Button/button.css"; +export enum MessageLevel { + "error", "warning", "success", "info" +} export interface APIMessage { - level_tag: string; + level: MessageLevel; tags?: string; message: string; + description?: string; } const LEVEL_ICON_MAP: { [key: string]: string } = { @@ -44,13 +48,16 @@ export class Message extends LitElement { render(): TemplateResult { return html`
  • -
    +
    - +

    ${this.message?.message}

    + ${this.message?.description && html`
    +

    ${this.message.description}

    +
    `}