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

View File

@ -25100,7 +25100,7 @@ components:
title:
type: string
configure_flow:
type: boolean
type: string
required:
- component
- 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 {
switch (stage.component) {
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>`;
case "ak-user-settings-password":
return html`<ak-user-settings-password objectId=${stage.objectUid}>
</ak-user-settings-password>`;
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>`;
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>`;
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>`;
default:
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 { until } from "lit-html/directives/until";
import { DEFAULT_CONFIG } from "../../../api/Config";
import { FlowURLManager } from "../../../api/legacy";
import { BaseUserSettings } from "./BaseUserSettings";
@customElement("ak-user-settings-authenticator-duo")
export class UserSettingsAuthenticatorDuo extends BaseUserSettings {
@property({ type: Boolean })
configureFlow = false;
@property()
configureFlow?: string;
renderEnabled(): TemplateResult {
return html`<div class="pf-c-card__body">
@ -50,7 +49,7 @@ export class UserSettingsAuthenticatorDuo extends BaseUserSettings {
</div>
<div class="pf-c-card__footer">
${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`}
</a>`: html``}
</div>`;

View File

@ -3,15 +3,14 @@ import { t } from "@lingui/macro";
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")
export class UserSettingsAuthenticatorStatic extends BaseUserSettings {
@property({ type: Boolean })
configureFlow = false;
@property()
configureFlow?: string;
static get styles(): CSSResult[] {
return super.styles.concat(STATIC_TOKEN_STYLE);
@ -65,7 +64,7 @@ export class UserSettingsAuthenticatorStatic extends BaseUserSettings {
</div>
<div class="pf-c-card__footer">
${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`}
</a>`: html``}
</div>`;

View File

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

View File

@ -2,7 +2,6 @@ import { CSSResult, customElement, html, property, TemplateResult } from "lit-el
import { t } from "@lingui/macro";
import { AuthenticatorsApi, WebAuthnDevice } from "authentik-api";
import { until } from "lit-html/directives/until";
import { FlowURLManager } from "../../../api/legacy";
import { DEFAULT_CONFIG } from "../../../api/Config";
import { BaseUserSettings } from "./BaseUserSettings";
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")
export class UserSettingsAuthenticatorWebAuthn extends BaseUserSettings {
@property({type: Boolean})
configureFlow = false;
@property()
configureFlow?: string;
static get styles(): CSSResult[] {
return super.styles.concat(PFDataList);
@ -102,7 +101,7 @@ export class UserSettingsAuthenticatorWebAuthn extends BaseUserSettings {
</div>
<div class="pf-c-card__footer">
${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`}
</a>`: html``}
</div>