2021-04-03 17:26:43 +00:00
|
|
|
import { t } from "@lingui/macro";
|
2021-09-21 09:31:37 +00:00
|
|
|
|
2021-10-28 07:48:51 +00:00
|
|
|
import { TemplateResult, html } from "lit";
|
2021-11-04 21:34:48 +00:00
|
|
|
import { customElement, property } from "lit/decorators.js";
|
2021-02-16 21:52:54 +00:00
|
|
|
|
2021-09-21 09:31:37 +00:00
|
|
|
import { Flow, FlowsApi } from "@goauthentik/api";
|
|
|
|
|
|
|
|
import { AKResponse } from "../../api/Client";
|
|
|
|
import { DEFAULT_CONFIG } from "../../api/Config";
|
2021-10-14 10:48:52 +00:00
|
|
|
import { uiConfig } from "../../common/config";
|
2021-02-16 21:52:54 +00:00
|
|
|
import "../../elements/buttons/SpinnerButton";
|
2021-09-21 09:31:37 +00:00
|
|
|
import "../../elements/forms/ConfirmationForm";
|
2021-08-12 20:03:13 +00:00
|
|
|
import "../../elements/forms/DeleteBulkForm";
|
2021-03-29 20:24:46 +00:00
|
|
|
import "../../elements/forms/ModalForm";
|
2021-09-21 09:31:37 +00:00
|
|
|
import { TableColumn } from "../../elements/table/Table";
|
|
|
|
import { TablePage } from "../../elements/table/TablePage";
|
2021-10-11 15:51:49 +00:00
|
|
|
import { groupBy } from "../../utils";
|
2021-03-29 20:24:46 +00:00
|
|
|
import "./FlowForm";
|
|
|
|
import "./FlowImportForm";
|
2021-10-11 15:51:49 +00:00
|
|
|
import { DesignationToLabel } from "./utils";
|
2021-02-16 21:52:54 +00:00
|
|
|
|
|
|
|
@customElement("ak-flow-list")
|
|
|
|
export class FlowListPage extends TablePage<Flow> {
|
|
|
|
searchEnabled(): boolean {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
pageTitle(): string {
|
2021-04-03 17:26:43 +00:00
|
|
|
return t`Flows`;
|
2021-02-16 21:52:54 +00:00
|
|
|
}
|
|
|
|
pageDescription(): string {
|
2021-04-03 17:26:43 +00:00
|
|
|
return t`Flows describe a chain of Stages to authenticate, enroll or recover a user. Stages are chosen based on policies applied to them.`;
|
2021-02-16 21:52:54 +00:00
|
|
|
}
|
|
|
|
pageIcon(): string {
|
2021-03-20 15:06:56 +00:00
|
|
|
return "pf-icon pf-icon-process-automation";
|
2021-02-16 21:52:54 +00:00
|
|
|
}
|
|
|
|
|
2021-08-05 10:30:43 +00:00
|
|
|
checkbox = true;
|
|
|
|
|
2021-02-16 21:52:54 +00:00
|
|
|
@property()
|
|
|
|
order = "slug";
|
|
|
|
|
2021-10-14 10:48:52 +00:00
|
|
|
async apiEndpoint(page: number): Promise<AKResponse<Flow>> {
|
2021-03-08 10:14:00 +00:00
|
|
|
return new FlowsApi(DEFAULT_CONFIG).flowsInstancesList({
|
2021-02-16 21:52:54 +00:00
|
|
|
ordering: this.order,
|
|
|
|
page: page,
|
2021-10-14 10:48:52 +00:00
|
|
|
pageSize: (await uiConfig()).pagination.perPage,
|
2021-02-16 21:52:54 +00:00
|
|
|
search: this.search || "",
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-10-11 15:51:49 +00:00
|
|
|
groupBy(items: Flow[]): [string, Flow[]][] {
|
|
|
|
return groupBy(items, (flow) => {
|
|
|
|
if (!flow.designation) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
return DesignationToLabel(flow.designation);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-02-16 21:52:54 +00:00
|
|
|
columns(): TableColumn[] {
|
|
|
|
return [
|
2021-04-04 14:56:16 +00:00
|
|
|
new TableColumn(t`Identifier`, "slug"),
|
|
|
|
new TableColumn(t`Name`, "name"),
|
2021-04-04 14:22:29 +00:00
|
|
|
new TableColumn(t`Stages`),
|
|
|
|
new TableColumn(t`Policies`),
|
2021-08-05 10:30:43 +00:00
|
|
|
new TableColumn(t`Actions`),
|
2021-02-16 21:52:54 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-08-05 10:30:43 +00:00
|
|
|
renderToolbarSelected(): TemplateResult {
|
2021-08-12 20:03:13 +00:00
|
|
|
const disabled = this.selectedElements.length < 1;
|
|
|
|
return html`<ak-forms-delete-bulk
|
|
|
|
objectLabel=${t`Flow(s)`}
|
|
|
|
.objects=${this.selectedElements}
|
|
|
|
.usedBy=${(item: Flow) => {
|
2021-08-05 10:30:43 +00:00
|
|
|
return new FlowsApi(DEFAULT_CONFIG).flowsInstancesUsedByList({
|
|
|
|
slug: item.slug,
|
|
|
|
});
|
|
|
|
}}
|
2021-08-12 20:03:13 +00:00
|
|
|
.delete=${(item: Flow) => {
|
2021-08-05 10:30:43 +00:00
|
|
|
return new FlowsApi(DEFAULT_CONFIG).flowsInstancesDestroy({
|
|
|
|
slug: item.slug,
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<button ?disabled=${disabled} slot="trigger" class="pf-c-button pf-m-danger">
|
|
|
|
${t`Delete`}
|
|
|
|
</button>
|
2021-08-12 20:03:13 +00:00
|
|
|
</ak-forms-delete-bulk>`;
|
2021-08-05 10:30:43 +00:00
|
|
|
}
|
|
|
|
|
2021-02-16 21:52:54 +00:00
|
|
|
row(item: Flow): TemplateResult[] {
|
|
|
|
return [
|
2021-02-19 18:29:17 +00:00
|
|
|
html`<a href="#/flow/flows/${item.slug}">
|
2021-02-16 21:52:54 +00:00
|
|
|
<code>${item.slug}</code>
|
|
|
|
</a>`,
|
|
|
|
html`${item.name}`,
|
2021-03-27 21:02:01 +00:00
|
|
|
html`${Array.from(item.stages || []).length}`,
|
|
|
|
html`${Array.from(item.policies || []).length}`,
|
2021-08-03 15:52:21 +00:00
|
|
|
html` <ak-forms-modal>
|
|
|
|
<span slot="submit"> ${t`Update`} </span>
|
|
|
|
<span slot="header"> ${t`Update Flow`} </span>
|
|
|
|
<ak-flow-form slot="form" .instancePk=${item.slug}> </ak-flow-form>
|
2021-08-05 10:30:43 +00:00
|
|
|
<button slot="trigger" class="pf-c-button pf-m-plain">
|
|
|
|
<i class="fas fa-edit"></i>
|
|
|
|
</button>
|
2021-08-03 15:52:21 +00:00
|
|
|
</ak-forms-modal>
|
|
|
|
<button
|
2021-08-05 10:30:43 +00:00
|
|
|
class="pf-c-button pf-m-plain"
|
2021-08-03 15:52:21 +00:00
|
|
|
@click=${() => {
|
|
|
|
new FlowsApi(DEFAULT_CONFIG)
|
|
|
|
.flowsInstancesExecuteRetrieve({
|
|
|
|
slug: item.slug,
|
|
|
|
})
|
|
|
|
.then((link) => {
|
2021-09-28 07:36:48 +00:00
|
|
|
window.open(
|
|
|
|
`${link.link}?inspector&next=/%23${window.location.href}`,
|
|
|
|
);
|
2021-08-03 15:52:21 +00:00
|
|
|
});
|
|
|
|
}}
|
|
|
|
>
|
2021-08-05 10:30:43 +00:00
|
|
|
<i class="fas fa-play"></i>
|
2021-03-29 20:24:46 +00:00
|
|
|
</button>
|
2021-08-05 10:30:43 +00:00
|
|
|
<a class="pf-c-button pf-m-plain" href=${item.exportUrl}>
|
|
|
|
<i class="fas fa-download"></i>
|
|
|
|
</a>`,
|
2021-02-16 21:52:54 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
renderToolbar(): TemplateResult {
|
2021-08-03 15:52:21 +00:00
|
|
|
return html` <ak-forms-modal>
|
|
|
|
<span slot="submit"> ${t`Create`} </span>
|
|
|
|
<span slot="header"> ${t`Create Flow`} </span>
|
|
|
|
<ak-flow-form slot="form"> </ak-flow-form>
|
|
|
|
<button slot="trigger" class="pf-c-button pf-m-primary">${t`Create`}</button>
|
|
|
|
</ak-forms-modal>
|
|
|
|
<ak-forms-modal>
|
|
|
|
<span slot="submit"> ${t`Import`} </span>
|
|
|
|
<span slot="header"> ${t`Import Flow`} </span>
|
|
|
|
<ak-flow-import-form slot="form"> </ak-flow-import-form>
|
|
|
|
<button slot="trigger" class="pf-c-button pf-m-primary">${t`Import`}</button>
|
|
|
|
</ak-forms-modal>
|
|
|
|
${super.renderToolbar()}
|
|
|
|
<ak-forms-confirm
|
|
|
|
successMessage=${t`Successfully cleared flow cache`}
|
|
|
|
errorMessage=${t`Failed to delete flow cache`}
|
|
|
|
action=${t`Clear cache`}
|
|
|
|
.onConfirm=${() => {
|
|
|
|
return new FlowsApi(DEFAULT_CONFIG).flowsInstancesCacheClearCreate();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<span slot="header"> ${t`Clear Flow cache`} </span>
|
|
|
|
<p slot="body">
|
|
|
|
${t`Are you sure you want to clear the flow cache?
|
2021-05-22 11:04:13 +00:00
|
|
|
This will cause all flows to be re-evaluated on their next usage.`}
|
2021-08-03 15:52:21 +00:00
|
|
|
</p>
|
|
|
|
<button slot="trigger" class="pf-c-button pf-m-secondary" type="button">
|
|
|
|
${t`Clear cache`}
|
|
|
|
</button>
|
|
|
|
<div slot="modal"></div>
|
|
|
|
</ak-forms-confirm>`;
|
2021-02-16 21:52:54 +00:00
|
|
|
}
|
|
|
|
}
|