import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { uiConfig } from "@goauthentik/common/ui/config"; import { PFColor } from "@goauthentik/elements/Label"; import "@goauthentik/elements/buttons/SpinnerButton"; import { PaginatedResponse } from "@goauthentik/elements/table/Table"; import { TableColumn } from "@goauthentik/elements/table/Table"; import { TableModal } from "@goauthentik/elements/table/TableModal"; import { t } from "@lingui/macro"; import { CSSResult, TemplateResult, html } from "lit"; import { customElement, property } from "lit/decorators.js"; import PFBanner from "@patternfly/patternfly/components/Banner/banner.css"; import { CoreApi, Group } from "@goauthentik/api"; @customElement("ak-user-group-select-table") export class GroupSelectModal extends TableModal { checkbox = true; checkboxChip = true; searchEnabled(): boolean { return true; } @property() confirm!: (selectedItems: Group[]) => Promise; order = "name"; static get styles(): CSSResult[] { return super.styles.concat(PFBanner); } async apiEndpoint(page: number): Promise> { return new CoreApi(DEFAULT_CONFIG).coreGroupsList({ ordering: this.order, page: page, pageSize: (await uiConfig()).pagination.perPage, search: this.search || "", }); } columns(): TableColumn[] { return [ new TableColumn(t`Name`, "username"), new TableColumn(t`Superuser`, "is_superuser"), new TableColumn(t`Members`, ""), ]; } row(item: Group): TemplateResult[] { return [ html`
${item.name}
`, html` ${item.isSuperuser ? t`Yes` : t`No`} `, html`${(item.users || []).length}`, ]; } renderSelectedChip(item: Group): TemplateResult { return html`${item.name}`; } renderModalInner(): TemplateResult { const willSuperuser = this.selectedElements.filter((g) => g.isSuperuser).length > 0; return html`

${t`Select groups to add user to`}

${willSuperuser ? html`
${t`Warning: Adding the user to the selected group(s) will give them superuser permissions.`}
` : html``}
${this.renderTable()}
`; } }