From 5c0d7f9a583323e7b1d7e167b30f94620bb57049 Mon Sep 17 00:00:00 2001 From: Jens L Date: Sun, 26 Mar 2023 18:58:02 +0200 Subject: [PATCH] web/admin: fix error when creating bindings due to hidden inputs (#5081) * web/admin: fix error when creating bindings due to hidden inputs Signed-off-by: Jens Langhammer * fix flaky test Signed-off-by: Jens Langhammer --------- Signed-off-by: Jens Langhammer --- authentik/stages/user_write/tests.py | 4 +++- web/src/admin/flows/StageBindingForm.ts | 18 ++++++------------ web/src/admin/policies/PolicyBindingForm.ts | 14 +++++--------- 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/authentik/stages/user_write/tests.py b/authentik/stages/user_write/tests.py index 434adfdb9..9bbfcbcbf 100644 --- a/authentik/stages/user_write/tests.py +++ b/authentik/stages/user_write/tests.py @@ -59,7 +59,9 @@ class TestUserWriteStage(FlowTestCase): user_qs = User.objects.filter(username=plan.context[PLAN_CONTEXT_PROMPT]["username"]) self.assertTrue(user_qs.exists()) self.assertTrue(user_qs.first().check_password(password)) - self.assertEqual(list(user_qs.first().ak_groups.all()), [self.group, self.other_group]) + self.assertEqual( + list(user_qs.first().ak_groups.order_by("name")), [self.other_group, self.group] + ) self.assertEqual(user_qs.first().attributes, {USER_ATTRIBUTE_SOURCES: [self.source.name]}) def test_user_update(self): diff --git a/web/src/admin/flows/StageBindingForm.ts b/web/src/admin/flows/StageBindingForm.ts index b79c95194..fd927c4b0 100644 --- a/web/src/admin/flows/StageBindingForm.ts +++ b/web/src/admin/flows/StageBindingForm.ts @@ -10,7 +10,6 @@ import { t } from "@lingui/macro"; import { TemplateResult, html } from "lit"; import { customElement, property, state } from "lit/decorators.js"; -import { ifDefined } from "lit/directives/if-defined.js"; import { Flow, @@ -48,19 +47,21 @@ export class StageBindingForm extends ModelForm { return t`Successfully created binding.`; } } - - send = (data: FlowStageBinding): Promise => { + send(data: FlowStageBinding): Promise { if (this.instance?.pk) { return new FlowsApi(DEFAULT_CONFIG).flowsBindingsUpdate({ fsbUuid: this.instance.pk, flowStageBindingRequest: data, }); } else { + if (this.targetPk) { + data.target = this.targetPk; + } return new FlowsApi(DEFAULT_CONFIG).flowsBindingsCreate({ flowStageBindingRequest: data, }); } - }; + } async getOrder(): Promise { if (this.instance?.pk) { @@ -78,14 +79,7 @@ export class StageBindingForm extends ModelForm { renderTarget(): TemplateResult { if (this.instance?.target || this.targetPk) { - return html` - - `; + return html``; } return html` { ); } - send = (data: PolicyBinding): Promise => { + send(data: PolicyBinding): Promise { + if (this.targetPk) { + data.target = this.targetPk; + } if (this.instance?.pk) { return new PoliciesApi(DEFAULT_CONFIG).policiesBindingsUpdate({ policyBindingUuid: this.instance.pk, @@ -94,7 +96,7 @@ export class PolicyBindingForm extends ModelForm { policyBindingRequest: data, }); } - }; + } async getOrder(): Promise { if (this.instance?.pk) { @@ -270,12 +272,6 @@ export class PolicyBindingForm extends ModelForm { -