import { t } from "@lingui/macro"; import { customElement, html, property, TemplateResult } from "lit-element"; import { AKResponse } from "../../api/Client"; import { Table, TableColumn } from "../../elements/table/Table"; import { PoliciesApi, PolicyBinding } from "authentik-api"; import "../../elements/forms/DeleteForm"; import "../../elements/Tabs"; import "../../elements/forms/ProxyForm"; import "../../elements/buttons/SpinnerButton"; import "../../elements/buttons/Dropdown"; import { until } from "lit-html/directives/until"; import { PAGE_SIZE } from "../../constants"; import { DEFAULT_CONFIG } from "../../api/Config"; import "../../elements/forms/ModalForm"; import "../groups/GroupForm"; import "../users/UserForm"; import "./PolicyBindingForm"; import { ifDefined } from "lit-html/directives/if-defined"; @customElement("ak-bound-policies-list") export class BoundPoliciesList extends Table { @property() target?: string; apiEndpoint(page: number): Promise> { return new PoliciesApi(DEFAULT_CONFIG).policiesBindingsList({ target: this.target || "", ordering: "order", page: page, pageSize: PAGE_SIZE, }); } columns(): TableColumn[] { return [ new TableColumn("Policy / User / Group"), new TableColumn(t`Enabled`, t`enabled`), new TableColumn(t`Order`, t`order`), new TableColumn(t`Timeout`, t`timeout`), new TableColumn(""), ]; } getPolicyUserGroupRow(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`-`; } } 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``; } } row(item: PolicyBinding): TemplateResult[] { return [ html`${this.getPolicyUserGroupRow(item)}`, html`${item.enabled ? t`Yes` : t`No`}`, html`${item.order}`, html`${item.timeout}`, html` ${this.getObjectEditButton(item)} ${t`Update`} ${t`Update Binding`} { return new PoliciesApi(DEFAULT_CONFIG).policiesBindingsDelete({ policyBindingUuid: item.pk || "", }); }}> `, ]; } 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`} ${super.renderToolbar()} `; } }