diff --git a/authentik/admin/forms/overview.py b/authentik/admin/forms/overview.py deleted file mode 100644 index 727b9c145..000000000 --- a/authentik/admin/forms/overview.py +++ /dev/null @@ -1,18 +0,0 @@ -"""Forms for modals on overview page""" -from django import forms - - -class PolicyCacheClearForm(forms.Form): - """Form to clear Policy cache""" - - title = "Clear Policy cache" - body = """Are you sure you want to clear the policy cache? - This will cause all policies to be re-evaluated on their next usage.""" - - -class FlowCacheClearForm(forms.Form): - """Form to clear Flow cache""" - - title = "Clear Flow cache" - body = """Are you sure you want to clear the flow cache? - This will cause all flows to be re-evaluated on their next usage.""" diff --git a/web/src/elements/forms/ConfirmationForm.ts b/web/src/elements/forms/ConfirmationForm.ts new file mode 100644 index 000000000..8d12d6496 --- /dev/null +++ b/web/src/elements/forms/ConfirmationForm.ts @@ -0,0 +1,88 @@ +import { gettext } from "django"; +import { customElement, html, property, TemplateResult } from "lit-element"; +import { ModalButton } from "../buttons/ModalButton"; +import { showMessage } from "../messages/MessageContainer"; + +@customElement("ak-forms-confirm") +export class ConfirmationForm extends ModalButton { + + @property() + successMessage!: string; + @property() + errorMessage!: string; + + @property() + action!: string; + + @property({attribute: false}) + onConfirm!: () => Promise; + + confirm(): void { + this.onConfirm().then(() => { + this.onSuccess(); + this.open = false; + this.dispatchEvent( + new CustomEvent("ak-refresh", { + bubbles: true, + composed: true, + }) + ); + }).catch((e) => { + this.onError(e); + }); + } + + onSuccess(): void { + showMessage({ + message: gettext(this.successMessage), + level_tag: "success", + }); + } + + onError(e: Error): void { + showMessage({ + message: gettext(`${this.errorMessage}: ${e.toString()}`), + level_tag: "error", + }); + } + + renderModalInner(): TemplateResult { + return html`
+
+

+ +

+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+ `; + } + +} diff --git a/web/src/pages/admin-overview/cards/FlowCacheStatusCard.ts b/web/src/pages/admin-overview/cards/FlowCacheStatusCard.ts index fd338021a..52a55ecc5 100644 --- a/web/src/pages/admin-overview/cards/FlowCacheStatusCard.ts +++ b/web/src/pages/admin-overview/cards/FlowCacheStatusCard.ts @@ -1,9 +1,9 @@ import { gettext } from "django"; import { customElement, html, TemplateResult } from "lit-element"; import { AdminStatus, AdminStatusCard } from "./AdminStatusCard"; -import "../../../elements/buttons/ModalButton"; import { FlowsApi } from "authentik-api"; import { DEFAULT_CONFIG } from "../../../api/Config"; +import "../../../elements/forms/ConfirmationForm"; @customElement("ak-admin-status-card-flow-cache") export class FlowCacheStatusCard extends AdminStatusCard { @@ -28,12 +28,25 @@ export class FlowCacheStatusCard extends AdminStatusCard { } renderHeaderLink(): TemplateResult { - return html` - - - -
-
`; + return html` { + return new FlowsApi(DEFAULT_CONFIG).flowsInstancesCacheClear(); + }}> + + ${gettext("Clear Flow cache")} + +

+ ${gettext(`Are you sure you want to clear the flow cache? + This will cause all flows to be re-evaluated on their next usage.`)} +

+ + + +
+
`; } } diff --git a/web/src/pages/admin-overview/cards/PolicyCacheStatusCard.ts b/web/src/pages/admin-overview/cards/PolicyCacheStatusCard.ts index a98dff22b..00df454c2 100644 --- a/web/src/pages/admin-overview/cards/PolicyCacheStatusCard.ts +++ b/web/src/pages/admin-overview/cards/PolicyCacheStatusCard.ts @@ -2,9 +2,9 @@ import { gettext } from "django"; import { customElement } from "lit-element"; import { TemplateResult, html } from "lit-html"; import { AdminStatusCard, AdminStatus } from "./AdminStatusCard"; -import "../../../elements/buttons/ModalButton"; import { PoliciesApi } from "authentik-api"; import { DEFAULT_CONFIG } from "../../../api/Config"; +import "../../../elements/forms/ConfirmationForm"; @customElement("ak-admin-status-card-policy-cache") export class PolicyCacheStatusCard extends AdminStatusCard { @@ -29,12 +29,25 @@ export class PolicyCacheStatusCard extends AdminStatusCard { } renderHeaderLink(): TemplateResult { - return html` - - - -
-
`; + return html` { + return new PoliciesApi(DEFAULT_CONFIG).policiesAllCacheClear(); + }}> + + ${gettext("Clear Policy cache")} + +

+ ${gettext(`Are you sure you want to clear the policy cache? + This will cause all policies to be re-evaluated on their next usage.`)} +

+ + + +
+
`; } }