From d17f781d1179a932f2a9f7d2934d53752613ceb6 Mon Sep 17 00:00:00 2001 From: "Jens L." Date: Mon, 23 Dec 2024 14:08:42 +0100 Subject: [PATCH] web: misc fixes for admin and flow inspector (#12461) * fix flow inspector not closable on error Signed-off-by: Jens Langhammer # Conflicts: # authentik/enterprise/providers/ssf/views/configuration.py * unrelated: fix flow inspector for in memory stages Signed-off-by: Jens Langhammer * only open inspector when there's size Signed-off-by: Jens Langhammer * fix relative links Signed-off-by: Jens Langhammer --------- Signed-off-by: Jens Langhammer --- authentik/flows/api/stages.py | 7 ++ authentik/flows/models.py | 6 +- web/src/components/ak-nav-buttons.ts | 6 +- web/src/elements/oauth/UserAccessTokenList.ts | 2 +- .../elements/oauth/UserRefreshTokenList.ts | 2 +- web/src/flow/FlowExecutor.ts | 6 +- web/src/flow/FlowInspector.ts | 70 ++++++++++--------- web/src/user/UserInterface.ts | 3 +- 8 files changed, 62 insertions(+), 40 deletions(-) diff --git a/authentik/flows/api/stages.py b/authentik/flows/api/stages.py index 94169187d8..63c2db4d0f 100644 --- a/authentik/flows/api/stages.py +++ b/authentik/flows/api/stages.py @@ -1,5 +1,7 @@ """Flow Stage API Views""" +from uuid import uuid4 + from django.urls.base import reverse from drf_spectacular.utils import extend_schema from rest_framework import mixins @@ -27,6 +29,11 @@ class StageSerializer(ModelSerializer, MetaNameSerializer): component = SerializerMethodField() flow_set = FlowSetSerializer(many=True, required=False) + def to_representation(self, instance: Stage): + if isinstance(instance, Stage) and instance.is_in_memory: + instance.stage_uuid = uuid4() + return super().to_representation(instance) + def get_component(self, obj: Stage) -> str: """Get object type so that we know how to edit the object""" if obj.__class__ == Stage: diff --git a/authentik/flows/models.py b/authentik/flows/models.py index 2ee41f705c..d4d0369556 100644 --- a/authentik/flows/models.py +++ b/authentik/flows/models.py @@ -102,8 +102,12 @@ class Stage(SerializerModel): user settings are available, or a challenge.""" return None + @property + def is_in_memory(self): + return hasattr(self, "__in_memory_type") + def __str__(self): - if hasattr(self, "__in_memory_type"): + if self.is_in_memory: return f"In-memory Stage {getattr(self, '__in_memory_type')}" return f"Stage {self.name}" diff --git a/web/src/components/ak-nav-buttons.ts b/web/src/components/ak-nav-buttons.ts index 8055847942..86fbec2903 100644 --- a/web/src/components/ak-nav-buttons.ts +++ b/web/src/components/ak-nav-buttons.ts @@ -142,7 +142,11 @@ export class NavigationButtons extends AKElement { } return html`
- + diff --git a/web/src/elements/oauth/UserAccessTokenList.ts b/web/src/elements/oauth/UserAccessTokenList.ts index 53cdd92a34..a78ef7c56e 100644 --- a/web/src/elements/oauth/UserAccessTokenList.ts +++ b/web/src/elements/oauth/UserAccessTokenList.ts @@ -96,7 +96,7 @@ export class UserOAuthAccessTokenList extends Table { ${item.expires.toLocaleString()}` : msg("-")}`, html` - ${item.scope.map((scope) => { + ${item.scope.sort().map((scope) => { return html`${scope}`; })} `, diff --git a/web/src/elements/oauth/UserRefreshTokenList.ts b/web/src/elements/oauth/UserRefreshTokenList.ts index f3cd743701..fc9b3234fe 100644 --- a/web/src/elements/oauth/UserRefreshTokenList.ts +++ b/web/src/elements/oauth/UserRefreshTokenList.ts @@ -97,7 +97,7 @@ export class UserOAuthRefreshTokenList extends Table { ${item.expires.toLocaleString()}` : msg("-")}`, html` - ${item.scope.map((scope) => { + ${item.scope.sort().map((scope) => { return html`${scope}`; })} `, diff --git a/web/src/flow/FlowExecutor.ts b/web/src/flow/FlowExecutor.ts index 1375e6430c..669053b5a7 100644 --- a/web/src/flow/FlowExecutor.ts +++ b/web/src/flow/FlowExecutor.ts @@ -231,7 +231,11 @@ export class FlowExecutor extends Interface implements StageHost { async firstUpdated(): Promise { configureSentry(); - if (this.config?.capabilities.includes(CapabilitiesEnum.CanDebug)) { + if ( + this.config?.capabilities.includes(CapabilitiesEnum.CanDebug) && + // Only open inspector automatically in debug when we have enough space for it + window.innerWidth >= 768 + ) { this.inspectorOpen = true; } this.loading = true; diff --git a/web/src/flow/FlowInspector.ts b/web/src/flow/FlowInspector.ts index 8f8ba27f97..373102338c 100644 --- a/web/src/flow/FlowInspector.ts +++ b/web/src/flow/FlowInspector.ts @@ -87,16 +87,37 @@ export class FlowInspector extends AKElement { return stage; } + renderHeader() { + return html`
+
+

${msg("Flow inspector")}

+
+
+
+ +
+
+
`; + } + renderAccessDenied(): TemplateResult { return html`