import { gettext } from "django"; 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/buttons/ModalButton"; 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 { AdminURLManager } from "../../api/legacy"; import "../../elements/forms/ModalForm"; import "../groups/GroupForm"; @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("Enabled", "enabled"), new TableColumn("Order", "order"), new TableColumn("Timeout", "timeout"), new TableColumn(""), ]; } getPolicyUserGroupRow(item: PolicyBinding): string { if (item.policy) { return gettext(`Policy ${item.policy.name}`); } else if (item.group) { return gettext(`Group ${item.group.name}`); } else if (item.user) { return gettext(`User ${item.user.name}`); } else { return gettext(""); } } getObjectEditButton(item: PolicyBinding): TemplateResult { if (item.policy) { return html` ${gettext("Edit Policy")}
`; } else if (item.group) { return html` ${gettext("Update")} ${gettext("Update Group")} `; } else if (item.user) { return html` ${gettext("Edit User")}
`; } else { return html``; } } row(item: PolicyBinding): TemplateResult[] { return [ html`${this.getPolicyUserGroupRow(item)}`, html`${item.enabled ? "Yes" : "No"}`, html`${item.order}`, html`${item.timeout}`, html` ${this.getObjectEditButton(item)} ${gettext("Edit Binding")}
{ return new PoliciesApi(DEFAULT_CONFIG).policiesBindingsDelete({ policyBindingUuid: item.pk || "", }); }}> `, ]; } renderEmpty(): TemplateResult { return super.renderEmpty(html`
${gettext("No policies are currently bound to this object.")}
${gettext("Bind Policy")}
`); } renderToolbar(): TemplateResult { return html` ${gettext("Bind Policy")}
${super.renderToolbar()} `; } }