From 86b450c6d16311b8bb1aa69c764f810b7033217c Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sat, 5 Jun 2021 20:04:30 +0200 Subject: [PATCH] flows: add compatibility_mode to toggle ShadyDOM closes #894 Signed-off-by: Jens Langhammer --- authentik/core/templates/if/flow.html | 2 ++ authentik/core/urls.py | 3 ++- authentik/core/views/interface.py | 17 +++++++++++++++ authentik/flows/api/flows.py | 1 + .../0020_flow_compatibility_mode.py | 21 +++++++++++++++++++ authentik/flows/models.py | 8 +++++++ authentik/flows/urls.py | 6 ------ schema.yml | 12 +++++++++++ web/src/locales/en.po | 8 +++++++ web/src/locales/pseudo-LOCALE.po | 8 +++++++ web/src/pages/flows/FlowForm.ts | 9 ++++++++ 11 files changed, 88 insertions(+), 7 deletions(-) create mode 100644 authentik/core/views/interface.py create mode 100644 authentik/flows/migrations/0020_flow_compatibility_mode.py diff --git a/authentik/core/templates/if/flow.html b/authentik/core/templates/if/flow.html index 35682d601..cdb9afbd5 100644 --- a/authentik/core/templates/if/flow.html +++ b/authentik/core/templates/if/flow.html @@ -4,7 +4,9 @@ {% load i18n %} {% block head_before %} +{% if flow.compatibility_mode %} +{% endif %} {% endblock %} {% block head %} diff --git a/authentik/core/urls.py b/authentik/core/urls.py index f221ffbe0..4f2b79aa9 100644 --- a/authentik/core/urls.py +++ b/authentik/core/urls.py @@ -6,6 +6,7 @@ from django.views.generic import RedirectView from django.views.generic.base import TemplateView from authentik.core.views import impersonate +from authentik.core.views.interface import FlowInterfaceView urlpatterns = [ path( @@ -32,7 +33,7 @@ urlpatterns = [ ), path( "if/flow//", - ensure_csrf_cookie(TemplateView.as_view(template_name="if/flow.html")), + ensure_csrf_cookie(FlowInterfaceView.as_view()), name="if-flow", ), # Fallback for WS diff --git a/authentik/core/views/interface.py b/authentik/core/views/interface.py new file mode 100644 index 000000000..d568d990b --- /dev/null +++ b/authentik/core/views/interface.py @@ -0,0 +1,17 @@ +"""Interface views""" +from typing import Any + +from django.shortcuts import get_object_or_404 +from django.views.generic.base import TemplateView + +from authentik.flows.models import Flow + + +class FlowInterfaceView(TemplateView): + """Flow interface""" + + template_name = "if/flow.html" + + def get_context_data(self, **kwargs: Any) -> dict[str, Any]: + kwargs["flow"] = get_object_or_404(Flow, slug=self.kwargs.get("slug")) + return super().get_context_data(**kwargs) diff --git a/authentik/flows/api/flows.py b/authentik/flows/api/flows.py index e1e50aee0..21717ac57 100644 --- a/authentik/flows/api/flows.py +++ b/authentik/flows/api/flows.py @@ -63,6 +63,7 @@ class FlowSerializer(ModelSerializer): "policies", "cache_count", "policy_engine_mode", + "compatibility_mode", ] extra_kwargs = { "background": {"read_only": True}, diff --git a/authentik/flows/migrations/0020_flow_compatibility_mode.py b/authentik/flows/migrations/0020_flow_compatibility_mode.py new file mode 100644 index 000000000..bb967e81e --- /dev/null +++ b/authentik/flows/migrations/0020_flow_compatibility_mode.py @@ -0,0 +1,21 @@ +# Generated by Django 3.2.3 on 2021-06-05 17:56 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("authentik_flows", "0019_alter_flow_background"), + ] + + operations = [ + migrations.AddField( + model_name="flow", + name="compatibility_mode", + field=models.BooleanField( + default=True, + help_text="Enable compatibility mode, increases compatibility with password managers on mobile devices.", + ), + ), + ] diff --git a/authentik/flows/models.py b/authentik/flows/models.py index 6e8f40bd1..f5e02aa0c 100644 --- a/authentik/flows/models.py +++ b/authentik/flows/models.py @@ -115,6 +115,14 @@ class Flow(SerializerModel, PolicyBindingModel): help_text=_("Background shown during execution"), ) + compatibility_mode = models.BooleanField( + default=True, + help_text=_( + "Enable compatibility mode, increases compatibility with " + "password managers on mobile devices." + ), + ) + @property def background_url(self) -> str: """Get the URL to the background image. If the name is /static or starts with http diff --git a/authentik/flows/urls.py b/authentik/flows/urls.py index 9be79ff68..bc15b6b39 100644 --- a/authentik/flows/urls.py +++ b/authentik/flows/urls.py @@ -1,6 +1,5 @@ """flow urls""" from django.urls import path -from django.views.generic import RedirectView from authentik.flows.models import FlowDesignation from authentik.flows.views import CancelView, ConfigureFlowInitView, ToDefaultFlow @@ -22,9 +21,4 @@ urlpatterns = [ ConfigureFlowInitView.as_view(), name="configure", ), - path( - "/", - RedirectView.as_view(pattern_name="authentik_core:if-flow"), - name="flow-executor-shell", - ), ] diff --git a/schema.yml b/schema.yml index 7cea3098c..6e3f09b6a 100644 --- a/schema.yml +++ b/schema.yml @@ -17294,6 +17294,10 @@ components: readOnly: true policy_engine_mode: $ref: '#/components/schemas/PolicyEngineMode' + compatibility_mode: + type: boolean + description: Enable compatibility mode, increases compatibility with password + managers on mobile devices. required: - background - cache_count @@ -17417,6 +17421,10 @@ components: flow is redirect to when an un-authenticated user visits authentik. policy_engine_mode: $ref: '#/components/schemas/PolicyEngineMode' + compatibility_mode: + type: boolean + description: Enable compatibility mode, increases compatibility with password + managers on mobile devices. required: - designation - name @@ -22245,6 +22253,10 @@ components: flow is redirect to when an un-authenticated user visits authentik. policy_engine_mode: $ref: '#/components/schemas/PolicyEngineMode' + compatibility_mode: + type: boolean + description: Enable compatibility mode, increases compatibility with password + managers on mobile devices. PatchedFlowStageBindingRequest: type: object description: FlowStageBinding Serializer diff --git a/web/src/locales/en.po b/web/src/locales/en.po index b1f4f0006..142413a47 100644 --- a/web/src/locales/en.po +++ b/web/src/locales/en.po @@ -641,6 +641,10 @@ msgstr "Code" msgid "Common Name" msgstr "Common Name" +#: src/pages/flows/FlowForm.ts +msgid "Compatibility mode" +msgstr "Compatibility mode" + #: src/pages/providers/oauth2/OAuth2ProviderForm.ts msgid "Confidential" msgstr "Confidential" @@ -1267,6 +1271,10 @@ msgstr "Enable Static Tokens" msgid "Enable TOTP" msgstr "Enable TOTP" +#: src/pages/flows/FlowForm.ts +msgid "Enable compatibility mode, increases compatibility with password managers on mobile devices." +msgstr "Enable compatibility mode, increases compatibility with password managers on mobile devices." + #: src/pages/providers/proxy/ProxyProviderForm.ts msgid "Enable forward-auth mode" msgstr "Enable forward-auth mode" diff --git a/web/src/locales/pseudo-LOCALE.po b/web/src/locales/pseudo-LOCALE.po index ae74cd44c..681650f3c 100644 --- a/web/src/locales/pseudo-LOCALE.po +++ b/web/src/locales/pseudo-LOCALE.po @@ -635,6 +635,10 @@ msgstr "" msgid "Common Name" msgstr "" +#: +msgid "Compatibility mode" +msgstr "" + #: msgid "Confidential" msgstr "" @@ -1259,6 +1263,10 @@ msgstr "" msgid "Enable TOTP" msgstr "" +#: +msgid "Enable compatibility mode, increases compatibility with password managers on mobile devices." +msgstr "" + #: msgid "Enable forward-auth mode" msgstr "" diff --git a/web/src/pages/flows/FlowForm.ts b/web/src/pages/flows/FlowForm.ts index 48373aa56..8bb980821 100644 --- a/web/src/pages/flows/FlowForm.ts +++ b/web/src/pages/flows/FlowForm.ts @@ -146,6 +146,15 @@ export class FlowForm extends ModelForm {

${t`Background shown during execution.`}

`; }))} + +
+ + +
+

${t`Enable compatibility mode, increases compatibility with password managers on mobile devices.`}

+
`; }