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
Jens Langhammer 1b496dd472 web/admin: use new group form for create
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
2021-03-29 12:02:58 +02:00

107 lines
3.3 KiB
TypeScript

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";
import "../../elements/buttons/ModalButton";
import "../../elements/buttons/SpinnerButton";
import { TableColumn } from "../../elements/table/Table";
import { PAGE_SIZE } from "../../constants";
import { CoreApi, Group } from "authentik-api";
import { DEFAULT_CONFIG } from "../../api/Config";
import "../../elements/forms/ModalForm";
import "./GroupForm";
@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";
}
@property()
order = "slug";
apiEndpoint(page: number): Promise<AKResponse<Group>> {
return new CoreApi(DEFAULT_CONFIG).coreGroupsList({
ordering: this.order,
page: page,
pageSize: PAGE_SIZE,
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"}`,
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">
${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">
${gettext("Delete")}
</button>
</ak-forms-delete>`,
];
}
renderToolbar(): TemplateResult {
return html`
<ak-forms-modal>
<span slot="submit">
${gettext("Create")}
</span>
<span slot="header">
${gettext("Create Group")}
</span>
<ak-group-form slot="form">
</ak-group-form>
<button slot="trigger" class="pf-c-button pf-m-primary">
${gettext("Create")}
</button>
</ak-forms-modal>
${super.renderToolbar()}
`;
}
}