2022-09-14 22:05:21 +00:00
|
|
|
import "@goauthentik/admin/users/GroupSelectModal";
|
|
|
|
import { DEFAULT_CONFIG } from "@goauthentik/common/api/config";
|
|
|
|
import { first } from "@goauthentik/common/utils";
|
|
|
|
import "@goauthentik/elements/CodeMirror";
|
|
|
|
import "@goauthentik/elements/forms/HorizontalFormElement";
|
|
|
|
import { ModelForm } from "@goauthentik/elements/forms/ModelForm";
|
2021-09-21 09:31:37 +00:00
|
|
|
import YAML from "yaml";
|
|
|
|
|
2021-04-03 17:26:43 +00:00
|
|
|
import { t } from "@lingui/macro";
|
2021-09-21 09:31:37 +00:00
|
|
|
|
2021-12-30 22:03:33 +00:00
|
|
|
import { CSSResult, TemplateResult, css, html } from "lit";
|
2021-11-04 21:34:48 +00:00
|
|
|
import { customElement } from "lit/decorators.js";
|
|
|
|
import { ifDefined } from "lit/directives/if-defined.js";
|
2021-09-21 09:31:37 +00:00
|
|
|
|
2023-02-14 15:15:43 +00:00
|
|
|
import { CoreApi, User } from "@goauthentik/api";
|
2021-09-21 09:31:37 +00:00
|
|
|
|
2021-03-29 14:16:27 +00:00
|
|
|
@customElement("ak-user-form")
|
2021-05-11 10:44:50 +00:00
|
|
|
export class UserForm extends ModelForm<User, number> {
|
2021-12-30 22:03:33 +00:00
|
|
|
static get styles(): CSSResult[] {
|
|
|
|
return super.styles.concat(css`
|
|
|
|
.pf-c-button.pf-m-control {
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
.pf-c-form-control {
|
|
|
|
height: auto !important;
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
}
|
|
|
|
|
2021-05-11 10:44:50 +00:00
|
|
|
loadInstance(pk: number): Promise<User> {
|
2021-05-16 12:43:42 +00:00
|
|
|
return new CoreApi(DEFAULT_CONFIG).coreUsersRetrieve({
|
2021-08-03 15:52:21 +00:00
|
|
|
id: pk,
|
2021-05-11 10:44:50 +00:00
|
|
|
});
|
|
|
|
}
|
2021-03-29 14:16:27 +00:00
|
|
|
|
|
|
|
getSuccessMessage(): string {
|
2021-05-11 10:44:50 +00:00
|
|
|
if (this.instance) {
|
2021-04-03 17:26:43 +00:00
|
|
|
return t`Successfully updated user.`;
|
2021-03-29 14:16:27 +00:00
|
|
|
} else {
|
2021-04-03 17:26:43 +00:00
|
|
|
return t`Successfully created user.`;
|
2021-03-29 14:16:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
send = (data: User): Promise<User> => {
|
2021-08-10 19:27:41 +00:00
|
|
|
if (this.instance?.pk) {
|
2023-02-14 15:15:43 +00:00
|
|
|
return new CoreApi(DEFAULT_CONFIG).coreUsersPartialUpdate({
|
2021-08-10 19:27:41 +00:00
|
|
|
id: this.instance.pk,
|
2023-02-14 15:15:43 +00:00
|
|
|
patchedUserRequest: data,
|
2021-03-29 14:16:27 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
return new CoreApi(DEFAULT_CONFIG).coreUsersCreate({
|
2021-08-03 15:52:21 +00:00
|
|
|
userRequest: data,
|
2021-03-29 14:16:27 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
renderForm(): TemplateResult {
|
|
|
|
return html`<form class="pf-c-form pf-m-horizontal">
|
2021-08-03 15:52:21 +00:00
|
|
|
<ak-form-element-horizontal label=${t`Username`} ?required=${true} name="username">
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
value="${ifDefined(this.instance?.username)}"
|
|
|
|
class="pf-c-form-control"
|
|
|
|
required
|
|
|
|
/>
|
|
|
|
<p class="pf-c-form__helper-text">
|
2022-06-10 20:59:59 +00:00
|
|
|
${t`User's primary identifier. 150 characters or fewer.`}
|
2021-08-03 15:52:21 +00:00
|
|
|
</p>
|
2021-03-29 14:16:27 +00:00
|
|
|
</ak-form-element-horizontal>
|
2022-06-15 10:12:26 +00:00
|
|
|
<ak-form-element-horizontal label=${t`Path`} ?required=${true} name="path">
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
value="${first(this.instance?.path, "users")}"
|
|
|
|
class="pf-c-form-control"
|
|
|
|
required
|
|
|
|
/>
|
|
|
|
</ak-form-element-horizontal>
|
2021-10-05 09:23:27 +00:00
|
|
|
<ak-form-element-horizontal label=${t`Name`} name="name">
|
2021-08-03 15:52:21 +00:00
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
value="${ifDefined(this.instance?.name)}"
|
|
|
|
class="pf-c-form-control"
|
|
|
|
/>
|
2021-04-03 17:26:43 +00:00
|
|
|
<p class="pf-c-form__helper-text">${t`User's display name.`}</p>
|
2021-03-29 14:16:27 +00:00
|
|
|
</ak-form-element-horizontal>
|
2021-08-05 12:43:16 +00:00
|
|
|
<ak-form-element-horizontal label=${t`Email`} name="email">
|
2021-08-03 15:52:21 +00:00
|
|
|
<input
|
|
|
|
type="email"
|
|
|
|
autocomplete="off"
|
|
|
|
value="${ifDefined(this.instance?.email)}"
|
|
|
|
class="pf-c-form-control"
|
|
|
|
/>
|
2021-03-29 14:16:27 +00:00
|
|
|
</ak-form-element-horizontal>
|
2021-08-03 15:52:21 +00:00
|
|
|
<ak-form-element-horizontal name="isActive">
|
2023-01-11 12:37:49 +00:00
|
|
|
<label class="pf-c-switch">
|
2021-08-03 15:52:21 +00:00
|
|
|
<input
|
2023-01-11 12:37:49 +00:00
|
|
|
class="pf-c-switch__input"
|
2021-08-03 15:52:21 +00:00
|
|
|
type="checkbox"
|
|
|
|
?checked=${first(this.instance?.isActive, true)}
|
|
|
|
/>
|
2023-01-11 12:37:49 +00:00
|
|
|
<span class="pf-c-switch__toggle">
|
|
|
|
<span class="pf-c-switch__toggle-icon">
|
|
|
|
<i class="fas fa-check" aria-hidden="true"></i>
|
|
|
|
</span>
|
|
|
|
</span>
|
|
|
|
<span class="pf-c-switch__label">${t`Is active`}</span>
|
|
|
|
</label>
|
2021-08-03 15:52:21 +00:00
|
|
|
<p class="pf-c-form__helper-text">
|
|
|
|
${t`Designates whether this user should be treated as active. Unselect this instead of deleting accounts.`}
|
|
|
|
</p>
|
2021-03-29 14:16:27 +00:00
|
|
|
</ak-form-element-horizontal>
|
2021-08-03 15:52:21 +00:00
|
|
|
<ak-form-element-horizontal label=${t`Attributes`} ?required=${true} name="attributes">
|
|
|
|
<ak-codemirror
|
|
|
|
mode="yaml"
|
|
|
|
value="${YAML.stringify(first(this.instance?.attributes, {}))}"
|
|
|
|
>
|
2021-03-29 14:16:27 +00:00
|
|
|
</ak-codemirror>
|
2021-08-03 15:52:21 +00:00
|
|
|
<p class="pf-c-form__helper-text">
|
|
|
|
${t`Set custom attributes using YAML or JSON.`}
|
|
|
|
</p>
|
2021-03-29 14:16:27 +00:00
|
|
|
</ak-form-element-horizontal>
|
|
|
|
</form>`;
|
|
|
|
}
|
|
|
|
}
|