web: fix mixed Static/TOTP pages

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-05-16 18:59:33 +02:00
parent 41f6d3b6e7
commit 07dc648470
5 changed files with 31 additions and 31 deletions

View File

@ -74,21 +74,21 @@ class TestAdminAPI(TestCase):
def test_version(self): def test_version(self):
"""Test Version API""" """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) self.assertEqual(response.status_code, 200)
body = loads(response.content) body = loads(response.content)
self.assertEqual(body["version_current"], __version__) self.assertEqual(body["version_current"], __version__)
def test_workers(self): def test_workers(self):
"""Test Workers API""" """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) self.assertEqual(response.status_code, 200)
body = loads(response.content) body = loads(response.content)
self.assertEqual(body["pagination"]["count"], 0) self.assertEqual(body["pagination"]["count"], 0)
def test_metrics(self): def test_metrics(self):
"""Test metrics API""" """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) self.assertEqual(response.status_code, 200)
def test_apps(self): def test_apps(self):

View File

@ -11,6 +11,6 @@ class TestConfig(APITestCase):
def test_config(self): def test_config(self):
"""Test YAML generation""" """Test YAML generation"""
response = self.client.get( response = self.client.get(
reverse("authentik_api:configs-list"), reverse("authentik_api:configs"),
) )
self.assertTrue(loads(response.content.decode())) self.assertTrue(loads(response.content.decode()))

View File

@ -21,8 +21,8 @@ import "../../elements/Tabs";
import "../../elements/PageHeader"; import "../../elements/PageHeader";
import "./tokens/UserTokenList"; import "./tokens/UserTokenList";
import "./UserDetailsPage"; import "./UserDetailsPage";
import "./settings/UserSettingsAuthenticatorTOTP";
import "./settings/UserSettingsAuthenticatorStatic"; import "./settings/UserSettingsAuthenticatorStatic";
import "./settings/UserSettingsAuthenticatorTOTP";
import "./settings/UserSettingsAuthenticatorWebAuthn"; import "./settings/UserSettingsAuthenticatorWebAuthn";
import "./settings/UserSettingsPassword"; import "./settings/UserSettingsPassword";
import "./settings/SourceSettingsOAuth"; import "./settings/SourceSettingsOAuth";

View File

@ -1,9 +1,10 @@
import { AuthenticatorsApi } from "authentik-api"; import { AuthenticatorsApi } from "authentik-api";
import { t } from "@lingui/macro"; 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 { until } from "lit-html/directives/until";
import { DEFAULT_CONFIG } from "../../../api/Config"; import { DEFAULT_CONFIG } from "../../../api/Config";
import { FlowURLManager } from "../../../api/legacy"; import { FlowURLManager } from "../../../api/legacy";
import { STATIC_TOKEN_STYLE } from "../../../flows/stages/authenticator_static/AuthenticatorStaticStage";
import { BaseUserSettings } from "./BaseUserSettings"; import { BaseUserSettings } from "./BaseUserSettings";
@customElement("ak-user-settings-authenticator-static") @customElement("ak-user-settings-authenticator-static")
@ -12,28 +13,42 @@ export class UserSettingsAuthenticatorStatic extends BaseUserSettings {
@property({ type: Boolean }) @property({ type: Boolean })
configureFlow = false; configureFlow = false;
static get styles(): CSSResult[] {
return super.styles.concat(STATIC_TOKEN_STYLE);
}
renderEnabled(): TemplateResult { renderEnabled(): TemplateResult {
return html`<div class="pf-c-card__body"> return html`<div class="pf-c-card__body">
<p> <p>
${t`Status: Enabled`} ${t`Status: Enabled`}
<i class="pf-icon pf-icon-ok"></i> <i class="pf-icon pf-icon-ok"></i>
</p> </p>
<ul class="ak-otp-tokens">
${until(new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsStaticList({}).then((devices) => {
if (devices.results.length < 1) {
return;
}
return devices.results[0].tokenSet?.map((token) => {
return html`<li>${token.token}</li>`;
});
}))}
</ul>
</div> </div>
<div class="pf-c-card__footer"> <div class="pf-c-card__footer">
<button <button
class="pf-c-button pf-m-danger" class="pf-c-button pf-m-danger"
@click=${() => { @click=${() => {
return new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsTotpList({}).then((devices) => { return new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsStaticList({}).then((devices) => {
if (devices.results.length < 1) { if (devices.results.length < 1) {
return; return;
} }
// TODO: Handle multiple devices, currently we assume only one TOTP Device // TODO: Handle multiple devices, currently we assume only one TOTP Device
return new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsTotpDestroy({ return new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsStaticDestroy({
id: devices.results[0].pk || 0 id: devices.results[0].pk || 0
}); });
}); });
}}> }}>
${t`Disable Time-based OTP`} ${t`Disable Static Tokens`}
</button> </button>
</div>`; </div>`;
} }
@ -57,9 +72,9 @@ export class UserSettingsAuthenticatorStatic extends BaseUserSettings {
render(): TemplateResult { render(): TemplateResult {
return html`<div class="pf-c-card"> return html`<div class="pf-c-card">
<div class="pf-c-card__title"> <div class="pf-c-card__title">
${t`Static tokens`} ${t`Time-based One-Time Passwords`}
</div> </div>
${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(); return devices.results.length > 0 ? this.renderEnabled() : this.renderDisabled();
}))} }))}
</div>`; </div>`;

View File

@ -1,10 +1,9 @@
import { AuthenticatorsApi } from "authentik-api"; import { AuthenticatorsApi } from "authentik-api";
import { t } from "@lingui/macro"; 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 { until } from "lit-html/directives/until";
import { DEFAULT_CONFIG } from "../../../api/Config"; import { DEFAULT_CONFIG } from "../../../api/Config";
import { FlowURLManager } from "../../../api/legacy"; import { FlowURLManager } from "../../../api/legacy";
import { STATIC_TOKEN_STYLE } from "../../../flows/stages/authenticator_static/AuthenticatorStaticStage";
import { BaseUserSettings } from "./BaseUserSettings"; import { BaseUserSettings } from "./BaseUserSettings";
@customElement("ak-user-settings-authenticator-totp") @customElement("ak-user-settings-authenticator-totp")
@ -13,42 +12,28 @@ export class UserSettingsAuthenticatorTOTP extends BaseUserSettings {
@property({ type: Boolean }) @property({ type: Boolean })
configureFlow = false; configureFlow = false;
static get styles(): CSSResult[] {
return super.styles.concat(STATIC_TOKEN_STYLE);
}
renderEnabled(): TemplateResult { renderEnabled(): TemplateResult {
return html`<div class="pf-c-card__body"> return html`<div class="pf-c-card__body">
<p> <p>
${t`Status: Enabled`} ${t`Status: Enabled`}
<i class="pf-icon pf-icon-ok"></i> <i class="pf-icon pf-icon-ok"></i>
</p> </p>
<ul class="ak-otp-tokens">
${until(new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsStaticList({}).then((devices) => {
if (devices.results.length < 1) {
return;
}
return devices.results[0].tokenSet?.map((token) => {
return html`<li>${token.token}</li>`;
});
}))}
</ul>
</div> </div>
<div class="pf-c-card__footer"> <div class="pf-c-card__footer">
<button <button
class="pf-c-button pf-m-danger" class="pf-c-button pf-m-danger"
@click=${() => { @click=${() => {
return new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsStaticList({}).then((devices) => { return new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsTotpList({}).then((devices) => {
if (devices.results.length < 1) { if (devices.results.length < 1) {
return; return;
} }
// TODO: Handle multiple devices, currently we assume only one TOTP Device // TODO: Handle multiple devices, currently we assume only one TOTP Device
return new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsStaticDestroy({ return new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsTotpDestroy({
id: devices.results[0].pk || 0 id: devices.results[0].pk || 0
}); });
}); });
}}> }}>
${t`Disable Static Tokens`} ${t`Disable Time-based OTP`}
</button> </button>
</div>`; </div>`;
} }
@ -72,7 +57,7 @@ export class UserSettingsAuthenticatorTOTP extends BaseUserSettings {
render(): TemplateResult { render(): TemplateResult {
return html`<div class="pf-c-card"> return html`<div class="pf-c-card">
<div class="pf-c-card__title"> <div class="pf-c-card__title">
${t`Time-based One-Time Passwords`} ${t`Static tokens`}
</div> </div>
${until(new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsTotpList({}).then((devices) => { ${until(new AuthenticatorsApi(DEFAULT_CONFIG).authenticatorsTotpList({}).then((devices) => {
return devices.results.length > 0 ? this.renderEnabled() : this.renderDisabled(); return devices.results.length > 0 ? this.renderEnabled() : this.renderDisabled();