From 07dc648470c8ca0049897cb4764cf961644248f7 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sun, 16 May 2021 18:59:33 +0200 Subject: [PATCH] web: fix mixed Static/TOTP pages Signed-off-by: Jens Langhammer --- authentik/admin/tests/test_api.py | 6 ++--- authentik/api/tests/test_config.py | 2 +- .../pages/user-settings/UserSettingsPage.ts | 2 +- .../UserSettingsAuthenticatorStatic.ts | 27 ++++++++++++++----- .../settings/UserSettingsAuthenticatorTOTP.ts | 25 ++++------------- 5 files changed, 31 insertions(+), 31 deletions(-) diff --git a/authentik/admin/tests/test_api.py b/authentik/admin/tests/test_api.py index 92fbd9b83..faa5d1397 100644 --- a/authentik/admin/tests/test_api.py +++ b/authentik/admin/tests/test_api.py @@ -74,21 +74,21 @@ class TestAdminAPI(TestCase): def test_version(self): """Test Version API""" - response = self.client.get(reverse("authentik_api:admin_version-list")) + response = self.client.get(reverse("authentik_api:admin_version")) self.assertEqual(response.status_code, 200) body = loads(response.content) self.assertEqual(body["version_current"], __version__) def test_workers(self): """Test Workers API""" - response = self.client.get(reverse("authentik_api:admin_workers-list")) + response = self.client.get(reverse("authentik_api:admin_workers")) self.assertEqual(response.status_code, 200) body = loads(response.content) self.assertEqual(body["pagination"]["count"], 0) def test_metrics(self): """Test metrics API""" - response = self.client.get(reverse("authentik_api:admin_metrics-list")) + response = self.client.get(reverse("authentik_api:admin_metrics")) self.assertEqual(response.status_code, 200) def test_apps(self): diff --git a/authentik/api/tests/test_config.py b/authentik/api/tests/test_config.py index 8e31e3ee0..91952be48 100644 --- a/authentik/api/tests/test_config.py +++ b/authentik/api/tests/test_config.py @@ -11,6 +11,6 @@ class TestConfig(APITestCase): def test_config(self): """Test YAML generation""" response = self.client.get( - reverse("authentik_api:configs-list"), + reverse("authentik_api:configs"), ) self.assertTrue(loads(response.content.decode())) diff --git a/web/src/pages/user-settings/UserSettingsPage.ts b/web/src/pages/user-settings/UserSettingsPage.ts index ee1bc1e12..75650bbba 100644 --- a/web/src/pages/user-settings/UserSettingsPage.ts +++ b/web/src/pages/user-settings/UserSettingsPage.ts @@ -21,8 +21,8 @@ import "../../elements/Tabs"; import "../../elements/PageHeader"; import "./tokens/UserTokenList"; import "./UserDetailsPage"; -import "./settings/UserSettingsAuthenticatorTOTP"; import "./settings/UserSettingsAuthenticatorStatic"; +import "./settings/UserSettingsAuthenticatorTOTP"; import "./settings/UserSettingsAuthenticatorWebAuthn"; import "./settings/UserSettingsPassword"; import "./settings/SourceSettingsOAuth"; diff --git a/web/src/pages/user-settings/settings/UserSettingsAuthenticatorStatic.ts b/web/src/pages/user-settings/settings/UserSettingsAuthenticatorStatic.ts index 399f9363e..a8c0e7b95 100644 --- a/web/src/pages/user-settings/settings/UserSettingsAuthenticatorStatic.ts +++ b/web/src/pages/user-settings/settings/UserSettingsAuthenticatorStatic.ts @@ -1,9 +1,10 @@ import { AuthenticatorsApi } from "authentik-api"; import { t } from "@lingui/macro"; -import { customElement, html, property, TemplateResult } from "lit-element"; +import { CSSResult, customElement, html, property, TemplateResult } from "lit-element"; import { until } from "lit-html/directives/until"; import { DEFAULT_CONFIG } from "../../../api/Config"; import { FlowURLManager } from "../../../api/legacy"; +import { STATIC_TOKEN_STYLE } from "../../../flows/stages/authenticator_static/AuthenticatorStaticStage"; import { BaseUserSettings } from "./BaseUserSettings"; @customElement("ak-user-settings-authenticator-static") @@ -12,28 +13,42 @@ export class UserSettingsAuthenticatorStatic extends BaseUserSettings { @property({ type: Boolean }) configureFlow = false; + static get styles(): CSSResult[] { + return super.styles.concat(STATIC_TOKEN_STYLE); + } + renderEnabled(): TemplateResult { return html`

${t`Status: Enabled`}

+
    + ${until(new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsStaticList({}).then((devices) => { + if (devices.results.length < 1) { + return; + } + return devices.results[0].tokenSet?.map((token) => { + return html`
  • ${token.token}
  • `; + }); + }))} +
`; } @@ -57,9 +72,9 @@ export class UserSettingsAuthenticatorStatic extends BaseUserSettings { render(): TemplateResult { return html`
- ${t`Static tokens`} + ${t`Time-based One-Time Passwords`}
- ${until(new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsTotpList({}).then((devices) => { + ${until(new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsStaticList({}).then((devices) => { return devices.results.length > 0 ? this.renderEnabled() : this.renderDisabled(); }))}
`; diff --git a/web/src/pages/user-settings/settings/UserSettingsAuthenticatorTOTP.ts b/web/src/pages/user-settings/settings/UserSettingsAuthenticatorTOTP.ts index 0d593e195..ca58bf791 100644 --- a/web/src/pages/user-settings/settings/UserSettingsAuthenticatorTOTP.ts +++ b/web/src/pages/user-settings/settings/UserSettingsAuthenticatorTOTP.ts @@ -1,10 +1,9 @@ import { AuthenticatorsApi } from "authentik-api"; import { t } from "@lingui/macro"; -import { CSSResult, customElement, html, property, TemplateResult } from "lit-element"; +import { customElement, html, property, TemplateResult } from "lit-element"; import { until } from "lit-html/directives/until"; import { DEFAULT_CONFIG } from "../../../api/Config"; import { FlowURLManager } from "../../../api/legacy"; -import { STATIC_TOKEN_STYLE } from "../../../flows/stages/authenticator_static/AuthenticatorStaticStage"; import { BaseUserSettings } from "./BaseUserSettings"; @customElement("ak-user-settings-authenticator-totp") @@ -13,42 +12,28 @@ export class UserSettingsAuthenticatorTOTP extends BaseUserSettings { @property({ type: Boolean }) configureFlow = false; - static get styles(): CSSResult[] { - return super.styles.concat(STATIC_TOKEN_STYLE); - } - renderEnabled(): TemplateResult { return html`

${t`Status: Enabled`}

-
    - ${until(new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsStaticList({}).then((devices) => { - if (devices.results.length < 1) { - return; - } - return devices.results[0].tokenSet?.map((token) => { - return html`
  • ${token.token}
  • `; - }); - }))} -
`; } @@ -72,7 +57,7 @@ export class UserSettingsAuthenticatorTOTP extends BaseUserSettings { render(): TemplateResult { return html`
- ${t`Time-based One-Time Passwords`} + ${t`Static tokens`}
${until(new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsTotpList({}).then((devices) => { return devices.results.length > 0 ? this.renderEnabled() : this.renderDisabled();