From 57e5acaf2f2b26e2f18e69f55f94e8c3e5e89c5a Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Thu, 7 Oct 2021 18:34:37 +0200 Subject: [PATCH] stages/prompt: add sub_text field to add HTML below prompt fields Signed-off-by: Jens Langhammer --- authentik/stages/prompt/api.py | 1 + .../prompt/migrations/0004_prompt_sub_text.py | 18 ++++++++++++++++++ authentik/stages/prompt/models.py | 1 + authentik/stages/prompt/stage.py | 1 + schema.yml | 9 +++++++++ web/src/elements/CodeMirror.ts | 1 + web/src/flows/stages/prompt/PromptStage.ts | 2 ++ web/src/locales/en.po | 12 ++++++++++++ web/src/locales/fr_FR.po | 12 ++++++++++++ web/src/locales/pseudo-LOCALE.po | 12 ++++++++++++ web/src/pages/stages/prompt/PromptForm.ts | 8 ++++++++ 11 files changed, 77 insertions(+) create mode 100644 authentik/stages/prompt/migrations/0004_prompt_sub_text.py diff --git a/authentik/stages/prompt/api.py b/authentik/stages/prompt/api.py index 4fbf4f8e5..4a7fedc37 100644 --- a/authentik/stages/prompt/api.py +++ b/authentik/stages/prompt/api.py @@ -48,6 +48,7 @@ class PromptSerializer(ModelSerializer): "placeholder", "order", "promptstage_set", + "sub_text", ] diff --git a/authentik/stages/prompt/migrations/0004_prompt_sub_text.py b/authentik/stages/prompt/migrations/0004_prompt_sub_text.py new file mode 100644 index 000000000..36a796ca2 --- /dev/null +++ b/authentik/stages/prompt/migrations/0004_prompt_sub_text.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.8 on 2021-10-07 16:04 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("authentik_stages_prompt", "0003_auto_20210222_1821"), + ] + + operations = [ + migrations.AddField( + model_name="prompt", + name="sub_text", + field=models.TextField(blank=True, default=""), + ), + ] diff --git a/authentik/stages/prompt/models.py b/authentik/stages/prompt/models.py index 6f73d5d42..48a7c4b61 100644 --- a/authentik/stages/prompt/models.py +++ b/authentik/stages/prompt/models.py @@ -64,6 +64,7 @@ class Prompt(SerializerModel): type = models.CharField(max_length=100, choices=FieldTypes.choices) required = models.BooleanField(default=True) placeholder = models.TextField(blank=True) + sub_text = models.TextField(blank=True, default="") order = models.IntegerField(default=0) diff --git a/authentik/stages/prompt/stage.py b/authentik/stages/prompt/stage.py index 6b650f2d3..4bdf21c2d 100644 --- a/authentik/stages/prompt/stage.py +++ b/authentik/stages/prompt/stage.py @@ -35,6 +35,7 @@ class StagePromptSerializer(PassiveSerializer): required = BooleanField() placeholder = CharField(allow_blank=True) order = IntegerField() + sub_text = CharField() class PromptChallenge(Challenge): diff --git a/schema.yml b/schema.yml index a9e165d79..a8bf4d290 100644 --- a/schema.yml +++ b/schema.yml @@ -26254,6 +26254,8 @@ components: type: array items: $ref: '#/components/schemas/StageRequest' + sub_text: + type: string PatchedPromptStageRequest: type: object description: PromptStage Serializer @@ -27133,6 +27135,8 @@ components: type: array items: $ref: '#/components/schemas/Stage' + sub_text: + type: string required: - field_key - label @@ -27197,6 +27201,8 @@ components: type: array items: $ref: '#/components/schemas/StageRequest' + sub_text: + type: string required: - field_key - label @@ -28509,12 +28515,15 @@ components: type: string order: type: integer + sub_text: + type: string required: - field_key - label - order - placeholder - required + - sub_text - type StageRequest: type: object diff --git a/web/src/elements/CodeMirror.ts b/web/src/elements/CodeMirror.ts index bed336f6d..1220ae081 100644 --- a/web/src/elements/CodeMirror.ts +++ b/web/src/elements/CodeMirror.ts @@ -4,6 +4,7 @@ import "codemirror/addon/display/autorefresh"; import "codemirror/addon/hint/show-hint"; import "codemirror/addon/search/search"; import "codemirror/addon/search/searchcursor"; +import "codemirror/mode/htmlmixed/htmlmixed.js"; import "codemirror/mode/javascript/javascript.js"; import "codemirror/mode/python/python.js"; import "codemirror/mode/xml/xml.js"; diff --git a/web/src/flows/stages/prompt/PromptStage.ts b/web/src/flows/stages/prompt/PromptStage.ts index e7e50679c..c4d8626d3 100644 --- a/web/src/flows/stages/prompt/PromptStage.ts +++ b/web/src/flows/stages/prompt/PromptStage.ts @@ -127,6 +127,7 @@ export class PromptStage extends BaseStage${t`Required.`}

` : html``} +

${unsafeHTML(prompt.subText)}

`; } // Special types that aren't rendered in a wrapper @@ -144,6 +145,7 @@ export class PromptStage extends BaseStage ${unsafeHTML(this.renderPromptInner(prompt))} +

${unsafeHTML(prompt.subText)}

`; })} ${"non_field_errors" in (this.challenge?.responseErrors || {}) diff --git a/web/src/locales/en.po b/web/src/locales/en.po index 670b16e81..647ec9430 100644 --- a/web/src/locales/en.po +++ b/web/src/locales/en.po @@ -278,6 +278,10 @@ msgstr "Alternatively, if your current device has Duo installed, click on this l msgid "Always require consent" msgstr "Always require consent" +#: src/pages/stages/prompt/PromptForm.ts +msgid "Any HTML can be used." +msgstr "Any HTML can be used." + #: src/pages/events/EventInfo.ts #: src/pages/policies/event_matcher/EventMatcherPolicyForm.ts msgid "App" @@ -2054,6 +2058,10 @@ msgstr "Healthy outposts" msgid "Healthy sources" msgstr "Healthy sources" +#: src/pages/stages/prompt/PromptForm.ts +msgid "Help text" +msgstr "Help text" + #: src/pages/stages/prompt/PromptForm.ts msgid "Hidden: Hidden field, can be used to insert data into form." msgstr "Hidden: Hidden field, can be used to insert data into form." @@ -5346,6 +5354,10 @@ msgstr "When selected, incoming assertion's Signatures will be validated against msgid "When this option is enabled, all executions of this policy will be logged. By default, only execution errors are logged." msgstr "When this option is enabled, all executions of this policy will be logged. By default, only execution errors are logged." +#: src/pages/stages/prompt/PromptForm.ts +msgid "When used in conjunction with a User Write stage, use attributes.foo to write attributes." +msgstr "When used in conjunction with a User Write stage, use attributes.foo to write attributes." + #: src/pages/tenants/TenantForm.ts msgid "When using an external logging solution for archiving, this can be set to \"minutes=5\"." msgstr "When using an external logging solution for archiving, this can be set to \"minutes=5\"." diff --git a/web/src/locales/fr_FR.po b/web/src/locales/fr_FR.po index f8d76b3c7..50fbcc567 100644 --- a/web/src/locales/fr_FR.po +++ b/web/src/locales/fr_FR.po @@ -282,6 +282,10 @@ msgstr "Sinon, si Duo est installé sur cet appareil, cliquez sur ce lien :" msgid "Always require consent" msgstr "Toujours exiger l'approbation" +#: src/pages/stages/prompt/PromptForm.ts +msgid "Any HTML can be used." +msgstr "" + #: src/pages/events/EventInfo.ts #: src/pages/policies/event_matcher/EventMatcherPolicyForm.ts msgid "App" @@ -2037,6 +2041,10 @@ msgstr "Avant-postes sains" msgid "Healthy sources" msgstr "Sources saines" +#: src/pages/stages/prompt/PromptForm.ts +msgid "Help text" +msgstr "" + #: src/pages/stages/prompt/PromptForm.ts msgid "Hidden: Hidden field, can be used to insert data into form." msgstr "Caché : champ caché, peut être utilisé pour insérer des données dans le formulaire." @@ -5285,6 +5293,10 @@ msgstr "Si activée, les signatures des assertions entrantes seront validées pa msgid "When this option is enabled, all executions of this policy will be logged. By default, only execution errors are logged." msgstr "Si activée, toutes les exécutions de cette politique seront enregistrées. Par défaut, seules les erreurs d'exécution sont consignées." +#: src/pages/stages/prompt/PromptForm.ts +msgid "When used in conjunction with a User Write stage, use attributes.foo to write attributes." +msgstr "" + #: src/pages/tenants/TenantForm.ts msgid "When using an external logging solution for archiving, this can be set to \"minutes=5\"." msgstr "En cas d'utilisation d'une solution de journalisation externe pour l'archivage, cette valeur peut être fixée à \"minutes=5\"." diff --git a/web/src/locales/pseudo-LOCALE.po b/web/src/locales/pseudo-LOCALE.po index c13dd3471..1aefe80dc 100644 --- a/web/src/locales/pseudo-LOCALE.po +++ b/web/src/locales/pseudo-LOCALE.po @@ -278,6 +278,10 @@ msgstr "" msgid "Always require consent" msgstr "" +#: src/pages/stages/prompt/PromptForm.ts +msgid "Any HTML can be used." +msgstr "" + #: src/pages/events/EventInfo.ts #: src/pages/policies/event_matcher/EventMatcherPolicyForm.ts msgid "App" @@ -2046,6 +2050,10 @@ msgstr "" msgid "Healthy sources" msgstr "" +#: src/pages/stages/prompt/PromptForm.ts +msgid "Help text" +msgstr "" + #: src/pages/stages/prompt/PromptForm.ts msgid "Hidden: Hidden field, can be used to insert data into form." msgstr "" @@ -5331,6 +5339,10 @@ msgstr "" msgid "When this option is enabled, all executions of this policy will be logged. By default, only execution errors are logged." msgstr "" +#: src/pages/stages/prompt/PromptForm.ts +msgid "When used in conjunction with a User Write stage, use attributes.foo to write attributes." +msgstr "" + #: src/pages/tenants/TenantForm.ts msgid "When using an external logging solution for archiving, this can be set to \"minutes=5\"." msgstr "" diff --git a/web/src/pages/stages/prompt/PromptForm.ts b/web/src/pages/stages/prompt/PromptForm.ts index bb41cda63..55387ada0 100644 --- a/web/src/pages/stages/prompt/PromptForm.ts +++ b/web/src/pages/stages/prompt/PromptForm.ts @@ -123,6 +123,9 @@ export class PromptForm extends ModelForm {

${t`Name of the form field, also used to store the value.`}

+

+ ${t`When used in conjunction with a User Write stage, use attributes.foo to write attributes.`} +

{ />

${t`Optionally pre-fill the input value`}

+ + + +

${t`Any HTML can be used.`}

+