web/admin: set required flag to false for user attributes (#6418)

* sert required flag to false for user attributes

* fallback for null value

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

---------

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
Co-authored-by: Tana Berry <tana@goauthentik.io>
Co-authored-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Tana M Berry 2023-08-26 14:13:39 -05:00 committed by GitHub
parent 5c5cd41548
commit b7faecea12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 2 deletions

View File

@ -17,6 +17,10 @@ import { CoreApi, User } from "@goauthentik/api";
@customElement("ak-user-form")
export class UserForm extends ModelForm<User, number> {
static get defaultUserAttributes(): { [key: string]: unknown } {
return {};
}
static get styles(): CSSResult[] {
return super.styles.concat(css`
.pf-c-button.pf-m-control {
@ -43,6 +47,9 @@ export class UserForm extends ModelForm<User, number> {
}
async send(data: User): Promise<User> {
if (data.attributes === null) {
data.attributes = UserForm.defaultUserAttributes;
}
if (this.instance?.pk) {
return new CoreApi(DEFAULT_CONFIG).coreUsersPartialUpdate({
id: this.instance.pk,
@ -145,12 +152,14 @@ export class UserForm extends ModelForm<User, number> {
</ak-form-element-horizontal>
<ak-form-element-horizontal
label=${msg("Attributes")}
?required=${true}
?required=${false}
name="attributes"
>
<ak-codemirror
mode="yaml"
value="${YAML.stringify(first(this.instance?.attributes, {}))}"
value="${YAML.stringify(
first(this.instance?.attributes, UserForm.defaultUserAttributes),
)}"
>
</ak-codemirror>
<p class="pf-c-form__helper-text">