import "@goauthentik/admin/groups/MemberSelectModal"; 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/chips/Chip"; import "@goauthentik/elements/chips/ChipGroup"; import "@goauthentik/elements/forms/HorizontalFormElement"; import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; import "@goauthentik/elements/forms/SearchSelect"; import YAML from "yaml"; import { msg } from "@lit/localize"; import { CSSResult, TemplateResult, css, html } from "lit"; import { customElement, state } from "lit/decorators.js"; import { ifDefined } from "lit/directives/if-defined.js"; import { CoreApi, CoreGroupsListRequest, Group, PaginatedRoleList, RbacApi, } from "@goauthentik/api"; @customElement("ak-group-form") export class GroupForm extends ModelForm { @state() roles?: PaginatedRoleList; 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: string): Promise { return new CoreApi(DEFAULT_CONFIG).coreGroupsRetrieve({ groupUuid: pk, }); } getSuccessMessage(): string { if (this.instance) { return msg("Successfully updated group."); } else { return msg("Successfully created group."); } } async load(): Promise { this.roles = await new RbacApi(DEFAULT_CONFIG).rbacRolesList({ ordering: "name", }); } async send(data: Group): Promise { if (this.instance?.pk) { return new CoreApi(DEFAULT_CONFIG).coreGroupsPartialUpdate({ groupUuid: this.instance.pk, patchedGroupRequest: data, }); } else { data.users = []; return new CoreApi(DEFAULT_CONFIG).coreGroupsCreate({ groupRequest: data, }); } } renderForm(): TemplateResult { return html`

${msg("Users added to this group will be superusers.")}

=> { const args: CoreGroupsListRequest = { ordering: "name", }; if (query !== undefined) { args.search = query; } const groups = await new CoreApi(DEFAULT_CONFIG).coreGroupsList(args); if (this.instance) { return groups.results.filter((g) => g.pk !== this.instance?.pk); } return groups.results; }} .renderElement=${(group: Group): string => { return group.name; }} .value=${(group: Group | undefined): string | undefined => { return group?.pk; }} .selected=${(group: Group): boolean => { return group.pk === this.instance?.parent; }} ?blankable=${true} >

${msg( "Select roles to grant this groups' users' permissions from the selected roles.", )}

${msg("Hold control/command to select multiple items.")}

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

`; } }