From b7f4d15a94f61aaa182a8621cec46377e9c1c470 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 26 Jun 2021 21:22:10 +0200 Subject: [PATCH] web/admin: fix deletion of authenticator not reloading the state correctly Signed-off-by: Jens Langhammer --- .../pages/user-settings/UserSettingsPage.ts | 25 ++++++++++++++++--- .../settings/UserSettingsAuthenticatorDuo.ts | 8 +++++- .../UserSettingsAuthenticatorStatic.ts | 8 +++++- .../settings/UserSettingsAuthenticatorTOTP.ts | 8 +++++- .../UserSettingsAuthenticatorWebAuthn.ts | 8 +++++- 5 files changed, 50 insertions(+), 7 deletions(-) diff --git a/web/src/pages/user-settings/UserSettingsPage.ts b/web/src/pages/user-settings/UserSettingsPage.ts index e2427e510..cf890732e 100644 --- a/web/src/pages/user-settings/UserSettingsPage.ts +++ b/web/src/pages/user-settings/UserSettingsPage.ts @@ -1,5 +1,5 @@ import { t } from "@lingui/macro"; -import { CSSResult, customElement, html, LitElement, TemplateResult } from "lit-element"; +import { CSSResult, customElement, html, LitElement, property, TemplateResult } from "lit-element"; import PFPage from "@patternfly/patternfly/components/Page/page.css"; import PFContent from "@patternfly/patternfly/components/Content/content.css"; @@ -27,6 +27,7 @@ import "./settings/UserSettingsAuthenticatorTOTP"; import "./settings/UserSettingsAuthenticatorWebAuthn"; import "./settings/UserSettingsPassword"; import "./settings/SourceSettingsOAuth"; +import { EVENT_REFRESH } from "../../constants"; @customElement("ak-user-settings") export class UserSettingsPage extends LitElement { @@ -35,6 +36,24 @@ export class UserSettingsPage extends LitElement { return [PFBase, PFPage, PFFlex, PFDisplay, PFGallery, PFContent, PFCard, PFDescriptionList, PFSizing, PFForm, PFFormControl, AKGlobal]; } + @property() + userSettings?: Promise; + + @property() + sourceSettings?: Promise; + + constructor() { + super(); + this.addEventListener(EVENT_REFRESH, () => { + this.firstUpdated(); + }); + } + + firstUpdated() { + this.userSettings = new StagesApi(DEFAULT_CONFIG).stagesAllUserSettingsList(); + this.sourceSettings = new SourcesApi(DEFAULT_CONFIG).sourcesAllUserSettingsList(); + } + renderStageSettings(stage: UserSetting): TemplateResult { switch (stage.component) { case "ak-user-settings-authenticator-webauthn": @@ -82,14 +101,14 @@ export class UserSettingsPage extends LitElement {
- ${until(new StagesApi(DEFAULT_CONFIG).stagesAllUserSettingsList().then((stages) => { + ${until(this.userSettings?.then((stages) => { return stages.map((stage) => { return html`
${this.renderStageSettings(stage)}
`; }); }))} - ${until(new SourcesApi(DEFAULT_CONFIG).sourcesAllUserSettingsList().then((source) => { + ${until(this.sourceSettings?.then((source) => { return source.map((stage) => { return html`
${this.renderSourceSettings(stage)} diff --git a/web/src/pages/user-settings/settings/UserSettingsAuthenticatorDuo.ts b/web/src/pages/user-settings/settings/UserSettingsAuthenticatorDuo.ts index ea7277172..8b23b88ee 100644 --- a/web/src/pages/user-settings/settings/UserSettingsAuthenticatorDuo.ts +++ b/web/src/pages/user-settings/settings/UserSettingsAuthenticatorDuo.ts @@ -4,6 +4,7 @@ import { customElement, html, TemplateResult } from "lit-element"; import { until } from "lit-html/directives/until"; import { DEFAULT_CONFIG } from "../../../api/Config"; import { BaseUserSettings } from "./BaseUserSettings"; +import { EVENT_REFRESH } from "../../../constants"; @customElement("ak-user-settings-authenticator-duo") export class UserSettingsAuthenticatorDuo extends BaseUserSettings { @@ -27,7 +28,12 @@ export class UserSettingsAuthenticatorDuo extends BaseUserSettings { return new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsDuoDestroy({ id: devices.results[0].pk || 0 }).then(() => { - this.requestUpdate(); + this.dispatchEvent( + new CustomEvent(EVENT_REFRESH, { + bubbles: true, + composed: true, + }) + ); }); }); }}> diff --git a/web/src/pages/user-settings/settings/UserSettingsAuthenticatorStatic.ts b/web/src/pages/user-settings/settings/UserSettingsAuthenticatorStatic.ts index 5210a0b3c..31bcc7207 100644 --- a/web/src/pages/user-settings/settings/UserSettingsAuthenticatorStatic.ts +++ b/web/src/pages/user-settings/settings/UserSettingsAuthenticatorStatic.ts @@ -5,6 +5,7 @@ import { until } from "lit-html/directives/until"; import { DEFAULT_CONFIG } from "../../../api/Config"; import { STATIC_TOKEN_STYLE } from "../../../flows/stages/authenticator_static/AuthenticatorStaticStage"; import { BaseUserSettings } from "./BaseUserSettings"; +import { EVENT_REFRESH } from "../../../constants"; @customElement("ak-user-settings-authenticator-static") export class UserSettingsAuthenticatorStatic extends BaseUserSettings { @@ -42,7 +43,12 @@ export class UserSettingsAuthenticatorStatic extends BaseUserSettings { return new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsStaticDestroy({ id: devices.results[0].pk || 0 }).then(() => { - this.requestUpdate(); + this.dispatchEvent( + new CustomEvent(EVENT_REFRESH, { + bubbles: true, + composed: true, + }) + ); }); }); }}> diff --git a/web/src/pages/user-settings/settings/UserSettingsAuthenticatorTOTP.ts b/web/src/pages/user-settings/settings/UserSettingsAuthenticatorTOTP.ts index b4bbac9db..6f84a28cd 100644 --- a/web/src/pages/user-settings/settings/UserSettingsAuthenticatorTOTP.ts +++ b/web/src/pages/user-settings/settings/UserSettingsAuthenticatorTOTP.ts @@ -4,6 +4,7 @@ import { customElement, html, TemplateResult } from "lit-element"; import { until } from "lit-html/directives/until"; import { DEFAULT_CONFIG } from "../../../api/Config"; import { BaseUserSettings } from "./BaseUserSettings"; +import { EVENT_REFRESH } from "../../../constants"; @customElement("ak-user-settings-authenticator-totp") export class UserSettingsAuthenticatorTOTP extends BaseUserSettings { @@ -27,7 +28,12 @@ export class UserSettingsAuthenticatorTOTP extends BaseUserSettings { return new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsTotpDestroy({ id: devices.results[0].pk || 0 }).then(() => { - this.requestUpdate(); + this.dispatchEvent( + new CustomEvent(EVENT_REFRESH, { + bubbles: true, + composed: true, + }) + ); }); }); }}> diff --git a/web/src/pages/user-settings/settings/UserSettingsAuthenticatorWebAuthn.ts b/web/src/pages/user-settings/settings/UserSettingsAuthenticatorWebAuthn.ts index e25e0dd05..a47c2ee95 100644 --- a/web/src/pages/user-settings/settings/UserSettingsAuthenticatorWebAuthn.ts +++ b/web/src/pages/user-settings/settings/UserSettingsAuthenticatorWebAuthn.ts @@ -12,6 +12,7 @@ import "../../../elements/forms/Form"; import "../../../elements/forms/ModalForm"; import "../../../elements/forms/HorizontalFormElement"; import { ifDefined } from "lit-html/directives/if-defined"; +import { EVENT_REFRESH } from "../../../constants"; @customElement("ak-user-settings-authenticator-webauthn") export class UserSettingsAuthenticatorWebAuthn extends BaseUserSettings { @@ -28,7 +29,12 @@ export class UserSettingsAuthenticatorWebAuthn extends BaseUserSettings { return new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsWebauthnDestroy({ id: device.pk || 0 }).then(() => { - this.requestUpdate(); + this.dispatchEvent( + new CustomEvent(EVENT_REFRESH, { + bubbles: true, + composed: true, + }) + ); }); }}>