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 <jens@goauthentik.io>

* fix flaky test

Signed-off-by: Jens Langhammer <jens@goauthentik.io>

---------

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens L 2023-03-26 18:58:02 +02:00 committed by GitHub
parent 95b99e3e55
commit 5c0d7f9a58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 22 deletions

View File

@ -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):

View File

@ -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<FlowStageBinding, string> {
return t`Successfully created binding.`;
}
}
send = (data: FlowStageBinding): Promise<FlowStageBinding> => {
send(data: FlowStageBinding): Promise<unknown> {
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<number> {
if (this.instance?.pk) {
@ -78,14 +79,7 @@ export class StageBindingForm extends ModelForm<FlowStageBinding, string> {
renderTarget(): TemplateResult {
if (this.instance?.target || this.targetPk) {
return html`
<input
required
name="target"
type="hidden"
value=${ifDefined(this.instance?.target || this.targetPk)}
/>
`;
return html``;
}
return html`<ak-form-element-horizontal label=${t`Target`} ?required=${true} name="target">
<ak-search-select

View File

@ -9,7 +9,6 @@ import { t } from "@lingui/macro";
import { CSSResult, css } from "lit";
import { TemplateResult, html } from "lit";
import { customElement, property, state } from "lit/decorators.js";
import { ifDefined } from "lit/directives/if-defined.js";
import PFContent from "@patternfly/patternfly/components/Content/content.css";
import PFToggleGroup from "@patternfly/patternfly/components/ToggleGroup/toggle-group.css";
@ -83,7 +82,10 @@ export class PolicyBindingForm extends ModelForm<PolicyBinding, string> {
);
}
send = (data: PolicyBinding): Promise<PolicyBinding> => {
send(data: PolicyBinding): Promise<unknown> {
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<PolicyBinding, string> {
policyBindingRequest: data,
});
}
};
}
async getOrder(): Promise<number> {
if (this.instance?.pk) {
@ -270,12 +272,6 @@ export class PolicyBindingForm extends ModelForm<PolicyBinding, string> {
</ak-form-element-horizontal>
</div>
</div>
<input
required
name="target"
type="hidden"
value=${ifDefined(this.instance?.target || this.targetPk)}
/>
<ak-form-element-horizontal name="enabled">
<label class="pf-c-switch">
<input