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 { until } from "lit/directives/until.js"; import { PoliciesApi, Policy } from "@goauthentik/api"; import { AKResponse } from "../../api/Client"; import { DEFAULT_CONFIG } from "../../api/Config"; import { uiConfig } from "../../common/config"; import "../../elements/buttons/Dropdown"; import "../../elements/buttons/SpinnerButton"; import "../../elements/forms/ConfirmationForm"; import "../../elements/forms/DeleteBulkForm"; import "../../elements/forms/ModalForm"; import "../../elements/forms/ProxyForm"; import { TableColumn } from "../../elements/table/Table"; import { TablePage } from "../../elements/table/TablePage"; import { groupBy } from "../../utils"; import "./PolicyTestForm"; import "./dummy/DummyPolicyForm"; import "./event_matcher/EventMatcherPolicyForm"; import "./expiry/ExpiryPolicyForm"; import "./expression/ExpressionPolicyForm"; import "./hibp/HaveIBeenPwnedPolicyForm"; import "./password/PasswordPolicyForm"; import "./reputation/ReputationPolicyForm"; @customElement("ak-policy-list") export class PolicyListPage extends TablePage { searchEnabled(): boolean { return true; } pageTitle(): string { return t`Policies`; } pageDescription(): string { return t`Allow users to use Applications based on properties, enforce Password Criteria and selectively apply Stages.`; } pageIcon(): string { return "pf-icon pf-icon-infrastructure"; } checkbox = true; @property() order = "name"; async apiEndpoint(page: number): Promise> { return new PoliciesApi(DEFAULT_CONFIG).policiesAllList({ ordering: this.order, page: page, pageSize: (await uiConfig()).pagination.perPage, search: this.search || "", }); } columns(): TableColumn[] { return [ new TableColumn(t`Name`, "name"), new TableColumn(t`Type`), new TableColumn(t`Actions`), ]; } groupBy(items: Policy[]): [string, Policy[]][] { return groupBy(items, (policy) => policy.verboseNamePlural); } row(item: Policy): TemplateResult[] { return [ html`
${item.name}
${(item.boundTo || 0) > 0 ? html` ${t`Assigned to ${item.boundTo} object(s).`} ` : html` ${t`Warning: Policy is not assigned.`}`}
`, html`${item.verboseName}`, html` ${t`Update`} ${t`Update ${item.verboseName}`} ${t`Test`} ${t`Test Policy`} `, ]; } renderToolbarSelected(): TemplateResult { const disabled = this.selectedElements.length < 1; return html` { return new PoliciesApi(DEFAULT_CONFIG).policiesAllUsedByList({ policyUuid: item.pk, }); }} .delete=${(item: Policy) => { return new PoliciesApi(DEFAULT_CONFIG).policiesAllDestroy({ policyUuid: item.pk, }); }} > `; } renderToolbar(): TemplateResult { return html` ${super.renderToolbar()} { return new PoliciesApi(DEFAULT_CONFIG).policiesAllCacheClearCreate(); }} > ${t`Clear Policy cache`}

${t`Are you sure you want to clear the policy cache? This will cause all policies to be re-evaluated on their next usage.`}

`; } }