import "@goauthentik/admin/groups/GroupForm"; import "@goauthentik/admin/policies/PolicyBindingForm"; import "@goauthentik/admin/policies/PolicyWizard"; import "@goauthentik/admin/users/UserForm"; import { DEFAULT_CONFIG } from "@goauthentik/common/api/config"; import { uiConfig } from "@goauthentik/common/ui/config"; import { PFColor } from "@goauthentik/elements/Label"; import { PFSize } from "@goauthentik/elements/Spinner"; import "@goauthentik/elements/Tabs"; import "@goauthentik/elements/forms/DeleteBulkForm"; import "@goauthentik/elements/forms/ModalForm"; import "@goauthentik/elements/forms/ProxyForm"; import { PaginatedResponse } from "@goauthentik/elements/table/Table"; import { Table, TableColumn } from "@goauthentik/elements/table/Table"; import { t } from "@lingui/macro"; import { TemplateResult, html } from "lit"; import { customElement, property } from "lit/decorators.js"; import { ifDefined } from "lit/directives/if-defined.js"; import { PoliciesApi, PolicyBinding } from "@goauthentik/api"; @customElement("ak-bound-policies-list") export class BoundPoliciesList extends Table { @property() target?: string; @property({ type: Boolean }) policyOnly = false; checkbox = true; async apiEndpoint(page: number): Promise> { return new PoliciesApi(DEFAULT_CONFIG).policiesBindingsList({ target: this.target || "", ordering: "order", page: page, pageSize: (await uiConfig()).pagination.perPage, }); } columns(): TableColumn[] { return [ new TableColumn(t`Order`, "order"), new TableColumn(t`Policy / User / Group`), new TableColumn(t`Enabled`, "enabled"), new TableColumn(t`Timeout`, "timeout"), new TableColumn(t`Actions`), ]; } getPolicyUserGroupRowLabel(item: PolicyBinding): string { if (item.policy) { return t`Policy ${item.policyObj?.name}`; } else if (item.group) { return t`Group ${item.groupObj?.name}`; } else if (item.user) { return t`User ${item.userObj?.name}`; } else { return t`-`; } } getPolicyUserGroupRow(item: PolicyBinding): TemplateResult { const label = this.getPolicyUserGroupRowLabel(item); if (item.user) { return html` ${label} `; } if (item.group) { return html` ${label} `; } return html`${label}`; } getObjectEditButton(item: PolicyBinding): TemplateResult { if (item.policy) { return html` ${t`Update`} ${t`Update ${item.policyObj?.name}`} `; } else if (item.group) { return html` ${t`Update`} ${t`Update Group`} `; } else if (item.user) { return html` ${t`Update`} ${t`Update User`} `; } else { return html``; } } renderToolbarSelected(): TemplateResult { const disabled = this.selectedElements.length < 1; return html` { return [ { key: t`Order`, value: item.order.toString() }, { key: t`Policy / User / Group`, value: this.getPolicyUserGroupRowLabel(item) }, ]; }} .usedBy=${(item: PolicyBinding) => { return new PoliciesApi(DEFAULT_CONFIG).policiesBindingsUsedByList({ policyBindingUuid: item.pk, }); }} .delete=${(item: PolicyBinding) => { return new PoliciesApi(DEFAULT_CONFIG).policiesBindingsDestroy({ policyBindingUuid: item.pk, }); }} > `; } row(item: PolicyBinding): TemplateResult[] { return [ html`${item.order}`, html`${this.getPolicyUserGroupRow(item)}`, html` ${item.enabled ? t`Yes` : t`No`} `, html`${item.timeout}`, html` ${this.getObjectEditButton(item)} ${t`Update`} ${t`Update Binding`} `, ]; } renderEmpty(): TemplateResult { return super.renderEmpty(html`
${t`No policies are currently bound to this object.`}
${t`Create`} ${t`Create Binding`}
`); } renderToolbar(): TemplateResult { return html` ${t`Create`} ${t`Create Binding`} `; } }