web/admin: pass full configure flow URL instead of just boolean

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-06-08 17:14:54 +02:00
parent ba1b23c879
commit 75404f1345
8 changed files with 22 additions and 33 deletions

View File

@ -1,10 +1,11 @@
"""Flow Stage API Views""" """Flow Stage API Views"""
from typing import Iterable from typing import Iterable
from django.urls.base import reverse
from drf_spectacular.utils import extend_schema from drf_spectacular.utils import extend_schema
from rest_framework import mixins from rest_framework import mixins
from rest_framework.decorators import action from rest_framework.decorators import action
from rest_framework.fields import BooleanField from rest_framework.fields import BooleanField, CharField
from rest_framework.request import Request from rest_framework.request import Request
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.serializers import ModelSerializer, SerializerMethodField from rest_framework.serializers import ModelSerializer, SerializerMethodField
@ -23,7 +24,7 @@ LOGGER = get_logger()
class StageUserSettingSerializer(UserSettingSerializer): class StageUserSettingSerializer(UserSettingSerializer):
"""User settings but can include a configure flow""" """User settings but can include a configure flow"""
configure_flow = BooleanField(required=False) configure_flow = CharField(required=False)
class StageSerializer(ModelSerializer, MetaNameSerializer): class StageSerializer(ModelSerializer, MetaNameSerializer):
@ -98,8 +99,8 @@ class StageViewSet(
continue continue
user_settings.initial_data["object_uid"] = str(stage.pk) user_settings.initial_data["object_uid"] = str(stage.pk)
if hasattr(stage, "configure_flow"): if hasattr(stage, "configure_flow"):
user_settings.initial_data["configure_flow"] = bool( user_settings.initial_data["configure_flow"] = reverse(
stage.configure_flow "authentik_flows:configure", kwargs={"stage_uuid": stage.uuid.hex},
) )
if not user_settings.is_valid(): if not user_settings.is_valid():
LOGGER.warning(user_settings.errors) LOGGER.warning(user_settings.errors)

View File

@ -25100,7 +25100,7 @@ components:
title: title:
type: string type: string
configure_flow: configure_flow:
type: boolean type: string
required: required:
- component - component
- object_uid - object_uid

View File

@ -8,11 +8,3 @@ export class AppURLManager {
} }
} }
export class FlowURLManager {
static configure(stageUuid: string, rest: string): string {
return `/flows/-/configure/${stageUuid}/${rest}`;
}
}

View File

@ -38,19 +38,19 @@ export class UserSettingsPage extends LitElement {
renderStageSettings(stage: StageUserSetting): TemplateResult { renderStageSettings(stage: StageUserSetting): TemplateResult {
switch (stage.component) { switch (stage.component) {
case "ak-user-settings-authenticator-webauthn": case "ak-user-settings-authenticator-webauthn":
return html`<ak-user-settings-authenticator-webauthn objectId=${stage.objectUid} ?configureFlow=${stage.configureFlow}> return html`<ak-user-settings-authenticator-webauthn objectId=${stage.objectUid} configureFlow=${stage.configureFlow}>
</ak-user-settings-authenticator-webauthn>`; </ak-user-settings-authenticator-webauthn>`;
case "ak-user-settings-password": case "ak-user-settings-password":
return html`<ak-user-settings-password objectId=${stage.objectUid}> return html`<ak-user-settings-password objectId=${stage.objectUid}>
</ak-user-settings-password>`; </ak-user-settings-password>`;
case "ak-user-settings-authenticator-totp": case "ak-user-settings-authenticator-totp":
return html`<ak-user-settings-authenticator-totp objectId=${stage.objectUid} ?configureFlow=${stage.configureFlow}> return html`<ak-user-settings-authenticator-totp objectId=${stage.objectUid} configureFlow=${stage.configureFlow}>
</ak-user-settings-authenticator-totp>`; </ak-user-settings-authenticator-totp>`;
case "ak-user-settings-authenticator-static": case "ak-user-settings-authenticator-static":
return html`<ak-user-settings-authenticator-static objectId=${stage.objectUid} ?configureFlow=${stage.configureFlow}> return html`<ak-user-settings-authenticator-static objectId=${stage.objectUid} configureFlow=${stage.configureFlow}>
</ak-user-settings-authenticator-static>`; </ak-user-settings-authenticator-static>`;
case "ak-user-settings-authenticator-duo": case "ak-user-settings-authenticator-duo":
return html`<ak-user-settings-authenticator-duo objectId=${stage.objectUid} ?configureFlow=${stage.configureFlow}> return html`<ak-user-settings-authenticator-duo objectId=${stage.objectUid} configureFlow=${stage.configureFlow}>
</ak-user-settings-authenticator-duo>`; </ak-user-settings-authenticator-duo>`;
default: default:
return html`<p>${t`Error: unsupported stage settings: ${stage.component}`}</p>`; return html`<p>${t`Error: unsupported stage settings: ${stage.component}`}</p>`;

View File

@ -3,14 +3,13 @@ import { t } from "@lingui/macro";
import { 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 { BaseUserSettings } from "./BaseUserSettings"; import { BaseUserSettings } from "./BaseUserSettings";
@customElement("ak-user-settings-authenticator-duo") @customElement("ak-user-settings-authenticator-duo")
export class UserSettingsAuthenticatorDuo extends BaseUserSettings { export class UserSettingsAuthenticatorDuo extends BaseUserSettings {
@property({ type: Boolean }) @property()
configureFlow = false; configureFlow?: string;
renderEnabled(): TemplateResult { renderEnabled(): TemplateResult {
return html`<div class="pf-c-card__body"> return html`<div class="pf-c-card__body">
@ -50,7 +49,7 @@ export class UserSettingsAuthenticatorDuo extends BaseUserSettings {
</div> </div>
<div class="pf-c-card__footer"> <div class="pf-c-card__footer">
${this.configureFlow ? ${this.configureFlow ?
html`<a href="${FlowURLManager.configure(this.objectId || "", "?next=/%23%2Fuser")}" html`<a href="${this.configureFlow}?next=/%23%2Fuser"
class="pf-c-button pf-m-primary">${t`Enable Static Tokens`} class="pf-c-button pf-m-primary">${t`Enable Static Tokens`}
</a>`: html``} </a>`: html``}
</div>`; </div>`;

View File

@ -3,15 +3,14 @@ import { t } from "@lingui/macro";
import { CSSResult, 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 { STATIC_TOKEN_STYLE } from "../../../flows/stages/authenticator_static/AuthenticatorStaticStage"; 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")
export class UserSettingsAuthenticatorStatic extends BaseUserSettings { export class UserSettingsAuthenticatorStatic extends BaseUserSettings {
@property({ type: Boolean }) @property()
configureFlow = false; configureFlow?: string;
static get styles(): CSSResult[] { static get styles(): CSSResult[] {
return super.styles.concat(STATIC_TOKEN_STYLE); return super.styles.concat(STATIC_TOKEN_STYLE);
@ -65,7 +64,7 @@ export class UserSettingsAuthenticatorStatic extends BaseUserSettings {
</div> </div>
<div class="pf-c-card__footer"> <div class="pf-c-card__footer">
${this.configureFlow ? ${this.configureFlow ?
html`<a href="${FlowURLManager.configure(this.objectId || "", "?next=/%23%2Fuser")}" html`<a href="${this.configureFlow}?next=/%23%2Fuser"
class="pf-c-button pf-m-primary">${t`Enable Static Tokens`} class="pf-c-button pf-m-primary">${t`Enable Static Tokens`}
</a>`: html``} </a>`: html``}
</div>`; </div>`;

View File

@ -3,14 +3,13 @@ import { t } from "@lingui/macro";
import { 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 { BaseUserSettings } from "./BaseUserSettings"; import { BaseUserSettings } from "./BaseUserSettings";
@customElement("ak-user-settings-authenticator-totp") @customElement("ak-user-settings-authenticator-totp")
export class UserSettingsAuthenticatorTOTP extends BaseUserSettings { export class UserSettingsAuthenticatorTOTP extends BaseUserSettings {
@property({ type: Boolean }) @property()
configureFlow = false; configureFlow?: string;
renderEnabled(): TemplateResult { renderEnabled(): TemplateResult {
return html`<div class="pf-c-card__body"> return html`<div class="pf-c-card__body">
@ -50,7 +49,7 @@ export class UserSettingsAuthenticatorTOTP extends BaseUserSettings {
</div> </div>
<div class="pf-c-card__footer"> <div class="pf-c-card__footer">
${this.configureFlow ? ${this.configureFlow ?
html`<a href="${FlowURLManager.configure(this.objectId || "", "?next=/%23%2Fuser")}" html`<a href="${this.configureFlow}?next=/%23%2Fuser"
class="pf-c-button pf-m-primary">${t`Enable TOTP`} class="pf-c-button pf-m-primary">${t`Enable TOTP`}
</a>`: html``} </a>`: html``}
</div>`; </div>`;

View File

@ -2,7 +2,6 @@ import { CSSResult, customElement, html, property, TemplateResult } from "lit-el
import { t } from "@lingui/macro"; import { t } from "@lingui/macro";
import { AuthenticatorsApi, WebAuthnDevice } from "authentik-api"; import { AuthenticatorsApi, WebAuthnDevice } from "authentik-api";
import { until } from "lit-html/directives/until"; import { until } from "lit-html/directives/until";
import { FlowURLManager } from "../../../api/legacy";
import { DEFAULT_CONFIG } from "../../../api/Config"; import { DEFAULT_CONFIG } from "../../../api/Config";
import { BaseUserSettings } from "./BaseUserSettings"; import { BaseUserSettings } from "./BaseUserSettings";
import PFDataList from "@patternfly/patternfly/components/DataList/data-list.css"; import PFDataList from "@patternfly/patternfly/components/DataList/data-list.css";
@ -17,8 +16,8 @@ import { ifDefined } from "lit-html/directives/if-defined";
@customElement("ak-user-settings-authenticator-webauthn") @customElement("ak-user-settings-authenticator-webauthn")
export class UserSettingsAuthenticatorWebAuthn extends BaseUserSettings { export class UserSettingsAuthenticatorWebAuthn extends BaseUserSettings {
@property({type: Boolean}) @property()
configureFlow = false; configureFlow?: string;
static get styles(): CSSResult[] { static get styles(): CSSResult[] {
return super.styles.concat(PFDataList); return super.styles.concat(PFDataList);
@ -102,7 +101,7 @@ export class UserSettingsAuthenticatorWebAuthn extends BaseUserSettings {
</div> </div>
<div class="pf-c-card__footer"> <div class="pf-c-card__footer">
${this.configureFlow ? ${this.configureFlow ?
html`<a href="${FlowURLManager.configure(this.objectId || "", "?next=/%23%2Fuser")}" html`<a href="${this.configureFlow}?next=/%23%2Fuser"
class="pf-c-button pf-m-primary">${t`Configure WebAuthn`} class="pf-c-button pf-m-primary">${t`Configure WebAuthn`}
</a>`: html``} </a>`: html``}
</div> </div>