import "@goauthentik/admin/users/GroupSelectModal"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { first } from "@goauthentik/common/utils"; import "@goauthentik/elements/CodeMirror"; import { CodeMirrorMode } from "@goauthentik/elements/CodeMirror"; import "@goauthentik/elements/forms/HorizontalFormElement"; import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import "@goauthentik/elements/forms/Radio"; import YAML from "yaml"; import { msg } from "@lit/localize"; import { CSSResult, TemplateResult, css, html } from "lit"; import { customElement } from "lit/decorators.js"; import { ifDefined } from "lit/directives/if-defined.js"; import { CoreApi, User, UserTypeEnum } from "@goauthentik/api"; @customElement("ak-user-form") export class UserForm extends ModelForm { static get defaultUserAttributes(): { [key: string]: unknown } { return {}; } static get styles(): CSSResult[] { return super.styles.concat(css` .pf-c-button.pf-m-control { height: 100%; } .pf-c-form-control { height: auto !important; } `); } loadInstance(pk: number): Promise { return new CoreApi(DEFAULT_CONFIG).coreUsersRetrieve({ id: pk, }); } getSuccessMessage(): string { if (this.instance) { return msg("Successfully updated user."); } else { return msg("Successfully created user."); } } async send(data: User): Promise { if (data.attributes === null) { data.attributes = UserForm.defaultUserAttributes; } if (this.instance?.pk) { return new CoreApi(DEFAULT_CONFIG).coreUsersPartialUpdate({ id: this.instance.pk, patchedUserRequest: data, }); } else { data.groups = []; return new CoreApi(DEFAULT_CONFIG).coreUsersCreate({ userRequest: data, }); } } renderForm(): TemplateResult { return html`

${msg("User's primary identifier. 150 characters or fewer.")}

${msg("User's display name.")}

${msg( "Designates whether this user should be treated as active. Unselect this instead of deleting accounts.", )}

${msg("Set custom attributes using YAML or JSON.")}

`; } }