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/groups/GroupListPage.ts

101 lines
3.2 KiB
TypeScript
Raw Normal View History

2021-02-19 16:18:09 +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/forms/DeleteForm";
2021-02-19 16:18:09 +00:00
import "../../elements/buttons/ModalButton";
import "../../elements/buttons/SpinnerButton";
import { TableColumn } from "../../elements/table/Table";
2021-03-02 14:12:26 +00:00
import { PAGE_SIZE } from "../../constants";
import { CoreApi, Group } from "authentik-api";
import { DEFAULT_CONFIG } from "../../api/Config";
import { AdminURLManager } from "../../api/legacy";
import "../../elements/forms/ModalForm";
import "./GroupForm";
2021-02-19 16:18:09 +00:00
@customElement("ak-group-list")
export class GroupListPage extends TablePage<Group> {
searchEnabled(): boolean {
return true;
}
pageTitle(): string {
return gettext("Groups");
}
pageDescription(): string {
return gettext("Group users together and give them permissions based on the membership.");
}
pageIcon(): string {
return "pf-icon pf-icon-users";
2021-02-19 16:18:09 +00:00
}
@property()
order = "slug";
apiEndpoint(page: number): Promise<AKResponse<Group>> {
return new CoreApi(DEFAULT_CONFIG).coreGroupsList({
2021-02-19 16:18:09 +00:00
ordering: this.order,
page: page,
pageSize: PAGE_SIZE,
2021-02-19 16:18:09 +00:00
search: this.search || "",
});
}
columns(): TableColumn[] {
return [
new TableColumn("Name", "name"),
new TableColumn("Parent", "parent"),
new TableColumn("Members"),
new TableColumn("Superuser privileges?"),
new TableColumn(""),
];
}
row(item: Group): TemplateResult[] {
return [
html`${item.name}`,
html`${item.parent || "-"}`,
html`${item.users?.keys.length}`,
html`${item.isSuperuser ? "Yes" : "No"}`,
2021-02-19 16:18:09 +00:00
html`
<ak-forms-modal>
<span slot="submit">
${gettext("Update")}
</span>
<span slot="header">
${gettext("Update Group")}
</span>
<ak-group-form slot="form" .group=${item}>
</ak-group-form>
<button slot="trigger" class="pf-c-button pf-m-primary">
2021-02-19 16:18:09 +00:00
${gettext("Edit")}
</button>
</ak-forms-modal>
<ak-forms-delete
.obj=${item}
objectLabel=${gettext("Group")}
.delete=${() => {
return new CoreApi(DEFAULT_CONFIG).coreGroupsDelete({
groupUuid: item.pk || ""
});
}}>
<button slot="trigger" class="pf-c-button pf-m-danger">
2021-02-19 16:18:09 +00:00
${gettext("Delete")}
</button>
</ak-forms-delete>`,
2021-02-19 16:18:09 +00:00
];
}
renderToolbar(): TemplateResult {
return html`
<ak-modal-button href=${AdminURLManager.groups("create/")}>
2021-02-19 16:18:09 +00:00
<ak-spinner-button slot="trigger" class="pf-m-primary">
${gettext("Create")}
</ak-spinner-button>
<div slot="modal"></div>
</ak-modal-button>
${super.renderToolbar()}
`;
}
}