This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/web/src/pages/policies/PolicyListPage.ts

128 lines
4.9 KiB
TypeScript
Raw Normal View History

2021-02-19 16:05:02 +00:00
import { gettext } from "django";
import { customElement, html, property, TemplateResult } from "lit-element";
import { AKResponse } from "../../api/Client";
import { TablePage } from "../../elements/table/TablePage";
import "../../elements/buttons/ModalButton";
import "../../elements/buttons/Dropdown";
import "../../elements/buttons/SpinnerButton";
import "../../elements/forms/DeleteForm";
import "../../elements/forms/ModalForm";
import "./PolicyTestForm";
2021-02-19 16:05:02 +00:00
import { TableColumn } from "../../elements/table/Table";
import { until } from "lit-html/directives/until";
2021-03-02 14:12:26 +00:00
import { PAGE_SIZE } from "../../constants";
import { PoliciesApi, Policy } from "authentik-api";
import { DEFAULT_CONFIG } from "../../api/Config";
import { AdminURLManager } from "../../api/legacy";
2021-02-19 16:05:02 +00:00
@customElement("ak-policy-list")
export class PolicyListPage extends TablePage<Policy> {
searchEnabled(): boolean {
return true;
}
pageTitle(): string {
return gettext("Policies");
}
pageDescription(): string {
return gettext("Allow users to use Applications based on properties, enforce Password Criteria and selectively apply Stages.");
}
pageIcon(): string {
return "pf-icon pf-icon-infrastructure";
2021-02-19 16:05:02 +00:00
}
@property()
order = "name";
apiEndpoint(page: number): Promise<AKResponse<Policy>> {
return new PoliciesApi(DEFAULT_CONFIG).policiesAllList({
2021-02-19 16:05:02 +00:00
ordering: this.order,
2021-03-02 14:12:26 +00:00
page: page,
pageSize: PAGE_SIZE,
2021-02-19 16:05:02 +00:00
search: this.search || "",
});
}
columns(): TableColumn[] {
return [
new TableColumn("Name", "name"),
new TableColumn("Type"),
new TableColumn(""),
];
}
row(item: Policy): TemplateResult[] {
return [
html`<div>
<div>${item.name}</div>
${(item.boundTo || 0) > 0 ?
2021-02-19 16:05:02 +00:00
html`<i class="pf-icon pf-icon-ok"></i>
<small>
${gettext(`Assigned to ${item.boundTo} objects.`)}
2021-02-19 16:05:02 +00:00
</small>`:
html`<i class="pf-icon pf-icon-warning-triangle"></i>
<small>${gettext("Warning: Policy is not assigned.")}</small>`}
2021-02-19 16:05:02 +00:00
</div>`,
html`${item.verboseName}`,
2021-02-19 16:05:02 +00:00
html`
<ak-modal-button href="${AdminURLManager.policies(`${item.pk}/update/`)}">
2021-02-19 16:05:02 +00:00
<ak-spinner-button slot="trigger" class="pf-m-secondary">
${gettext("Edit")}
</ak-spinner-button>
<div slot="modal"></div>
</ak-modal-button>
<ak-forms-modal .closeAfterSuccessfulSubmit=${false}>
<span slot="submit">
2021-02-19 16:05:02 +00:00
${gettext("Test")}
</span>
<span slot="header">
${gettext("Test Policy")}
</span>
<ak-policy-test-form slot="form" .policy=${item}>
</ak-policy-test-form>
<button slot="trigger" class="pf-c-button pf-m-secondary">
${gettext("Test")}
</button>
</ak-forms-modal>
<ak-forms-delete
.obj=${item}
objectLabel=${gettext("Policy")}
.delete=${() => {
return new PoliciesApi(DEFAULT_CONFIG).policiesAllDelete({
policyUuid: item.pk || ""
});
}}>
<button slot="trigger" class="pf-c-button pf-m-danger">
2021-02-19 16:05:02 +00:00
${gettext("Delete")}
</button>
</ak-forms-delete>`,
2021-02-19 16:05:02 +00:00
];
}
renderToolbar(): TemplateResult {
return html`
<ak-dropdown class="pf-c-dropdown">
<button class="pf-m-primary pf-c-dropdown__toggle" type="button">
<span class="pf-c-dropdown__toggle-text">${gettext("Create")}</span>
<i class="fas fa-caret-down pf-c-dropdown__toggle-icon" aria-hidden="true"></i>
</button>
<ul class="pf-c-dropdown__menu" hidden>
${until(new PoliciesApi(DEFAULT_CONFIG).policiesAllTypes({}).then((types) => {
2021-02-19 16:05:02 +00:00
return types.map((type) => {
return html`<li>
<ak-modal-button href="${type.link}">
<button slot="trigger" class="pf-c-dropdown__menu-item">${type.name}<br>
<small>${type.description}</small>
</button>
<div slot="modal"></div>
</ak-modal-button>
</li>`;
});
}), html`<ak-spinner></ak-spinner>`)}
</ul>
</ak-dropdown>
${super.renderToolbar()}`;
}
}