Update hivegrid-cloud reference to latest main
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e98d38e716
commit
7b21524c86
3781 files changed
+373484
-225607
No files matched your search
+48
@@ -0,0 +1,48 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildGroupsDetailVM, filterGroupMemberRows, type GroupsDetailInputUser } from "../index.js";
|
||||
|
||||
function user(id: string, firstName: string | null, email: string): GroupsDetailInputUser {
|
||||
return { userId: id, firstName, lastName: null, email };
|
||||
}
|
||||
|
||||
const GROUP = { id: "g1", name: "Montage Nord", description: "Bautrupp" };
|
||||
|
||||
describe("buildGroupsDetailVM", () => {
|
||||
it("splits members and candidates without overlap", () => {
|
||||
const vm = buildGroupsDetailVM({
|
||||
group: GROUP,
|
||||
memberUsers: [user("u1", "Ada", "ada@example.com")],
|
||||
tenantUsers: [user("u1", "Ada", "ada@example.com"), user("u2", "Grace", "grace@example.com"), user("u3", null, "linus@example.com")],
|
||||
canManage: true,
|
||||
});
|
||||
expect(vm.status).toBe("ready");
|
||||
const data = vm.data!;
|
||||
expect(data.memberRows.map((r) => r.userId)).toEqual(["u1"]);
|
||||
expect(data.candidateRows.map((r) => r.userId)).toEqual(["u2", "u3"]);
|
||||
expect(data.memberCount).toBe(1);
|
||||
expect(data.emptyCandidatesKey).toBe("settings.members.groups.bulk.emptyCandidates");
|
||||
});
|
||||
|
||||
it("derives display name and initials with email fallback", () => {
|
||||
const vm = buildGroupsDetailVM({ group: GROUP, memberUsers: [user("u3", null, "linus@example.com")], tenantUsers: [], canManage: false });
|
||||
const row = vm.data!.memberRows[0];
|
||||
expect(row.name).toBe("linus@example.com");
|
||||
expect(row.initials).toBe("L");
|
||||
expect(vm.data!.canManage).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("filterGroupMemberRows", () => {
|
||||
const rows = buildGroupsDetailVM({
|
||||
group: GROUP,
|
||||
memberUsers: [user("u1", "Ada", "ada@example.com"), user("u2", "Grace", "grace@example.com")],
|
||||
tenantUsers: [],
|
||||
canManage: true,
|
||||
}).data!.memberRows;
|
||||
|
||||
it("matches name or email, empty query returns all", () => {
|
||||
expect(filterGroupMemberRows(rows, "grace").map((r) => r.userId)).toEqual(["u2"]);
|
||||
expect(filterGroupMemberRows(rows, "example.com").length).toBe(2);
|
||||
expect(filterGroupMemberRows(rows, "").length).toBe(2);
|
||||
});
|
||||
});
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
import type { VMState } from "../index.js";
|
||||
|
||||
/**
|
||||
* Group members bulk view-model (R-P2b, interim UI per AD-28 — David parked
|
||||
* groups for RBAC V2, so this screen is a `~/ui` preview with an open
|
||||
* design-nachzug). Pure function, no React/Prisma/app imports.
|
||||
*
|
||||
* Backs the bulk add/remove dialog on top of the idempotent
|
||||
* `addUsersToGroup`/`removeUsersFromGroup` backend ops.
|
||||
*/
|
||||
|
||||
export type GroupMemberRow = {
|
||||
readonly userId: string;
|
||||
readonly name: string;
|
||||
readonly email: string;
|
||||
readonly initials: string;
|
||||
};
|
||||
|
||||
export interface GroupsDetailData {
|
||||
readonly groupId: string;
|
||||
readonly name: string;
|
||||
readonly description: string;
|
||||
/** Users currently in the group (bulk-remove candidates). */
|
||||
readonly memberRows: readonly GroupMemberRow[];
|
||||
/** Tenant members not yet in the group (bulk-add candidates). */
|
||||
readonly candidateRows: readonly GroupMemberRow[];
|
||||
readonly memberCount: number;
|
||||
readonly canManage: boolean;
|
||||
readonly emptyMembersKey: string;
|
||||
readonly emptyCandidatesKey: string;
|
||||
}
|
||||
|
||||
export type GroupsDetailVM = VMState<GroupsDetailData>;
|
||||
|
||||
export interface GroupsDetailInputUser {
|
||||
readonly userId: string;
|
||||
readonly firstName: string | null;
|
||||
readonly lastName: string | null;
|
||||
readonly email: string;
|
||||
}
|
||||
|
||||
export interface BuildGroupsDetailVMInput {
|
||||
readonly group: { readonly id: string; readonly name: string; readonly description: string };
|
||||
readonly memberUsers: readonly GroupsDetailInputUser[];
|
||||
/** All (active) tenant users — candidates are derived as "not yet member". */
|
||||
readonly tenantUsers: readonly GroupsDetailInputUser[];
|
||||
readonly canManage: boolean;
|
||||
}
|
||||
|
||||
function toRow(user: GroupsDetailInputUser): GroupMemberRow {
|
||||
const name =
|
||||
[user.firstName, user.lastName]
|
||||
.map((part) => (part ?? "").trim())
|
||||
.filter(Boolean)
|
||||
.join(" ") || user.email;
|
||||
const initials =
|
||||
`${(user.firstName ?? "").trim().charAt(0)}${(user.lastName ?? "").trim().charAt(0)}`.toUpperCase() || user.email.charAt(0).toUpperCase();
|
||||
return { userId: user.userId, name, email: user.email, initials };
|
||||
}
|
||||
|
||||
export function buildGroupsDetailVM(input: BuildGroupsDetailVMInput): GroupsDetailVM {
|
||||
const memberIds = new Set(input.memberUsers.map((user) => user.userId));
|
||||
const memberRows = input.memberUsers.map(toRow);
|
||||
const candidateRows = input.tenantUsers.filter((user) => !memberIds.has(user.userId)).map(toRow);
|
||||
|
||||
return {
|
||||
status: "ready",
|
||||
data: {
|
||||
groupId: input.group.id,
|
||||
name: input.group.name,
|
||||
description: input.group.description,
|
||||
memberRows,
|
||||
candidateRows,
|
||||
memberCount: memberRows.length,
|
||||
canManage: input.canManage,
|
||||
emptyMembersKey: "settings.members.groups.bulk.emptyMembers",
|
||||
emptyCandidatesKey: "settings.members.groups.bulk.emptyCandidates",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/** Search across name/email — shared by both pick lists in the bulk dialog. */
|
||||
export function filterGroupMemberRows(rows: readonly GroupMemberRow[], query: string): GroupMemberRow[] {
|
||||
const normalized = query.trim().toUpperCase();
|
||||
if (!normalized) return [...rows];
|
||||
return rows.filter((row) => `${row.name} ${row.email}`.toUpperCase().includes(normalized));
|
||||
}
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
buildMembersListVM,
|
||||
deriveMemberInitials,
|
||||
deriveMemberName,
|
||||
filterMembersRows,
|
||||
toMembersListModel,
|
||||
EMPTY_MEMBERS_FILTER,
|
||||
type MembersListInputRow,
|
||||
} from "../index.js";
|
||||
|
||||
function inputRow(overrides: Partial<MembersListInputRow> = {}): MembersListInputRow {
|
||||
return {
|
||||
tenantUserId: "tu1",
|
||||
userId: "u1",
|
||||
firstName: "Ada",
|
||||
lastName: "Lovelace",
|
||||
email: "ada@example.com",
|
||||
phone: "+49 123",
|
||||
status: "active",
|
||||
mfaEnabled: true,
|
||||
roles: [{ id: "r1", name: "Monteur", description: "" }],
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
function buildVM(rows: MembersListInputRow[], currentUserId = "me") {
|
||||
return buildMembersListVM({
|
||||
rows,
|
||||
pendingInvitations: [],
|
||||
assignableRoles: [{ id: "r1", name: "Monteur", description: "" }],
|
||||
currentUserId,
|
||||
canInvite: true,
|
||||
canEditRoles: true,
|
||||
canManageMembers: true,
|
||||
});
|
||||
}
|
||||
|
||||
describe("deriveMemberName / deriveMemberInitials", () => {
|
||||
it("joins names and falls back to email", () => {
|
||||
expect(deriveMemberName("Ada", "Lovelace", "ada@example.com")).toBe("Ada Lovelace");
|
||||
expect(deriveMemberName(null, null, "ada@example.com")).toBe("ada@example.com");
|
||||
expect(deriveMemberInitials("Ada", "Lovelace", "ada@example.com")).toBe("AL");
|
||||
expect(deriveMemberInitials(null, null, "ada@example.com")).toBe("A");
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildMembersListVM", () => {
|
||||
it("maps rows with status label keys and capabilities", () => {
|
||||
const vm = buildVM([inputRow(), inputRow({ tenantUserId: "tu2", userId: "u2", status: "inactive", mfaEnabled: false })]);
|
||||
expect(vm.status).toBe("ready");
|
||||
const [active, inactive] = vm.data!.rows;
|
||||
expect(active.statusLabelKey).toBe("settings.members.status.active");
|
||||
expect(active.canDeactivate).toBe(true);
|
||||
expect(active.canReactivate).toBe(false);
|
||||
expect(inactive.statusLabelKey).toBe("settings.members.status.deactivated");
|
||||
expect(inactive.canDeactivate).toBe(false);
|
||||
expect(inactive.canReactivate).toBe(true);
|
||||
});
|
||||
|
||||
it("never offers self-deactivation (server guards last-admin anyway)", () => {
|
||||
const vm = buildVM([inputRow({ userId: "me" })], "me");
|
||||
const row = vm.data!.rows[0];
|
||||
expect(row.isSelf).toBe(true);
|
||||
expect(row.canDeactivate).toBe(false);
|
||||
});
|
||||
|
||||
it("drops manage capabilities without permission", () => {
|
||||
const vm = buildMembersListVM({
|
||||
rows: [inputRow()],
|
||||
pendingInvitations: [],
|
||||
assignableRoles: [],
|
||||
currentUserId: "me",
|
||||
canInvite: false,
|
||||
canEditRoles: false,
|
||||
canManageMembers: false,
|
||||
});
|
||||
expect(vm.data!.rows[0].canDeactivate).toBe(false);
|
||||
expect(vm.data!.canInvite).toBe(false);
|
||||
});
|
||||
|
||||
it("normalizes empty phone to null and keeps invited status", () => {
|
||||
const vm = buildVM([inputRow({ phone: " ", status: "invited" })]);
|
||||
const row = vm.data!.rows[0];
|
||||
expect(row.phone).toBeNull();
|
||||
expect(row.statusLabelKey).toBe("settings.members.status.invited");
|
||||
});
|
||||
});
|
||||
|
||||
describe("filterMembersRows", () => {
|
||||
const rows = buildVM([
|
||||
inputRow(),
|
||||
inputRow({ tenantUserId: "tu2", userId: "u2", firstName: "Grace", lastName: "Hopper", email: "grace@example.com", phone: null, mfaEnabled: false, roles: [] }),
|
||||
inputRow({ tenantUserId: "tu3", userId: "u3", firstName: "Linus", lastName: null, email: "linus@example.com", status: "inactive" }),
|
||||
]).data!.rows;
|
||||
|
||||
it("searches across name, email and phone", () => {
|
||||
expect(filterMembersRows(rows, { ...EMPTY_MEMBERS_FILTER, query: "grace" }).map((r) => r.userId)).toEqual(["u2"]);
|
||||
expect(filterMembersRows(rows, { ...EMPTY_MEMBERS_FILTER, query: "+49" }).length).toBe(2);
|
||||
});
|
||||
|
||||
it("filters by role, status and 2FA", () => {
|
||||
expect(filterMembersRows(rows, { ...EMPTY_MEMBERS_FILTER, roleId: "r1" }).length).toBe(2);
|
||||
expect(filterMembersRows(rows, { ...EMPTY_MEMBERS_FILTER, status: "inactive" }).map((r) => r.userId)).toEqual(["u3"]);
|
||||
expect(filterMembersRows(rows, { ...EMPTY_MEMBERS_FILTER, mfa: false }).map((r) => r.userId)).toEqual(["u2"]);
|
||||
});
|
||||
|
||||
it("returns everything for the empty filter", () => {
|
||||
expect(filterMembersRows(rows, EMPTY_MEMBERS_FILTER).length).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe("toMembersListModel", () => {
|
||||
it("normalizes rows for the hot-swap renderers", () => {
|
||||
const model = toMembersListModel(buildVM([inputRow()]).data!);
|
||||
expect(model.titleKey).toBe("settings.members.title");
|
||||
expect(model.rowCount).toBe(1);
|
||||
expect(model.rows[0]).toMatchObject({ name: "Ada Lovelace", roleNames: ["Monteur"], canDeactivate: true });
|
||||
});
|
||||
});
|
||||
+220
@@ -0,0 +1,220 @@
|
||||
import type { VMState } from "../index.js";
|
||||
|
||||
/**
|
||||
* Members admin list view-model (R-P2b, David's D-P2 `WF-P2 Admin RBAC` S01).
|
||||
* Pure function: the loader builds it once server-side, the UI only renders.
|
||||
* No React, no Prisma, no app imports (DoD A.3).
|
||||
*
|
||||
* Role display names need the app-side `roleDisplayName(t)` resolver, so rows
|
||||
* carry raw role refs ({ id, name, description }) and the screen resolves the
|
||||
* labels — the builder stays locale- and app-agnostic.
|
||||
*/
|
||||
|
||||
/** Normalized membership status (route maps the numeric TenantUserStatus enum). */
|
||||
export type MemberStatus = "active" | "inactive" | "invited";
|
||||
|
||||
export type MemberRoleRef = {
|
||||
readonly id: string;
|
||||
readonly name: string;
|
||||
readonly description: string;
|
||||
};
|
||||
|
||||
export type MembersListRow = {
|
||||
readonly tenantUserId: string;
|
||||
readonly userId: string;
|
||||
/** Display name (first/last name, falls back to email). */
|
||||
readonly name: string;
|
||||
readonly email: string;
|
||||
readonly phone: string | null;
|
||||
/** Avatar initials derived from name/email. */
|
||||
readonly initials: string;
|
||||
readonly status: MemberStatus;
|
||||
/** i18n key for the status badge label. */
|
||||
readonly statusLabelKey: string;
|
||||
readonly mfaEnabled: boolean;
|
||||
/** Roles assigned in this tenant (screen resolves display labels). */
|
||||
readonly roles: readonly MemberRoleRef[];
|
||||
readonly isSelf: boolean;
|
||||
/** Row menu capability: deactivate (M03) — active members that are not you. */
|
||||
readonly canDeactivate: boolean;
|
||||
/** Row menu capability: reactivate — inactive members. */
|
||||
readonly canReactivate: boolean;
|
||||
};
|
||||
|
||||
export type MembersListFilterState = {
|
||||
readonly query: string;
|
||||
/** Role id filter, null = all. */
|
||||
readonly roleId: string | null;
|
||||
readonly status: MemberStatus | null;
|
||||
/** 2FA filter: true = enabled only, false = disabled only, null = all. */
|
||||
readonly mfa: boolean | null;
|
||||
};
|
||||
|
||||
export const EMPTY_MEMBERS_FILTER: MembersListFilterState = {
|
||||
query: "",
|
||||
roleId: null,
|
||||
status: null,
|
||||
mfa: null,
|
||||
};
|
||||
|
||||
export type PendingInvitationRow = {
|
||||
readonly id: string;
|
||||
readonly email: string;
|
||||
readonly name: string;
|
||||
readonly createdAtIso: string | null;
|
||||
};
|
||||
|
||||
export interface MembersListData {
|
||||
readonly rows: readonly MembersListRow[];
|
||||
readonly pendingInvitations: readonly PendingInvitationRow[];
|
||||
/** Roles available for the inline role dropdown (D01) and the role filter. */
|
||||
readonly assignableRoles: readonly MemberRoleRef[];
|
||||
readonly canInvite: boolean;
|
||||
readonly canEditRoles: boolean;
|
||||
readonly canManageMembers: boolean;
|
||||
readonly emptyHeadlineKey: string;
|
||||
readonly emptyBodyKey: string;
|
||||
readonly noMatchesKey: string;
|
||||
}
|
||||
|
||||
export type MembersListVM = VMState<MembersListData>;
|
||||
|
||||
/** Raw member row the loader passes in (already read from the DB, framework-free). */
|
||||
export interface MembersListInputRow {
|
||||
readonly tenantUserId: string;
|
||||
readonly userId: string;
|
||||
readonly firstName: string | null;
|
||||
readonly lastName: string | null;
|
||||
readonly email: string;
|
||||
readonly phone: string | null;
|
||||
readonly status: MemberStatus;
|
||||
readonly mfaEnabled: boolean;
|
||||
readonly roles: readonly MemberRoleRef[];
|
||||
}
|
||||
|
||||
export interface BuildMembersListVMInput {
|
||||
readonly rows: readonly MembersListInputRow[];
|
||||
readonly pendingInvitations: readonly PendingInvitationRow[];
|
||||
readonly assignableRoles: readonly MemberRoleRef[];
|
||||
readonly currentUserId: string;
|
||||
readonly canInvite: boolean;
|
||||
readonly canEditRoles: boolean;
|
||||
readonly canManageMembers: boolean;
|
||||
}
|
||||
|
||||
const STATUS_LABEL_KEYS: Readonly<Record<MemberStatus, string>> = {
|
||||
active: "settings.members.status.active",
|
||||
inactive: "settings.members.status.deactivated",
|
||||
invited: "settings.members.status.invited",
|
||||
};
|
||||
|
||||
export function deriveMemberName(firstName: string | null, lastName: string | null, email: string): string {
|
||||
const name = [firstName, lastName]
|
||||
.map((part) => (part ?? "").trim())
|
||||
.filter(Boolean)
|
||||
.join(" ");
|
||||
return name || email;
|
||||
}
|
||||
|
||||
export function deriveMemberInitials(firstName: string | null, lastName: string | null, email: string): string {
|
||||
const initials = `${(firstName ?? "").trim().charAt(0)}${(lastName ?? "").trim().charAt(0)}`.toUpperCase();
|
||||
return initials || email.charAt(0).toUpperCase();
|
||||
}
|
||||
|
||||
export function buildMembersListVM(input: BuildMembersListVMInput): MembersListVM {
|
||||
const rows: MembersListRow[] = input.rows.map((row) => {
|
||||
const isSelf = row.userId === input.currentUserId;
|
||||
return {
|
||||
tenantUserId: row.tenantUserId,
|
||||
userId: row.userId,
|
||||
name: deriveMemberName(row.firstName, row.lastName, row.email),
|
||||
email: row.email,
|
||||
phone: row.phone && row.phone.trim().length > 0 ? row.phone.trim() : null,
|
||||
initials: deriveMemberInitials(row.firstName, row.lastName, row.email),
|
||||
status: row.status,
|
||||
statusLabelKey: STATUS_LABEL_KEYS[row.status],
|
||||
mfaEnabled: row.mfaEnabled,
|
||||
roles: row.roles,
|
||||
isSelf,
|
||||
// Server enforces the last-admin guard again (V01) — these flags only shape the menu.
|
||||
canDeactivate: input.canManageMembers && row.status === "active" && !isSelf,
|
||||
canReactivate: input.canManageMembers && row.status === "inactive",
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
status: "ready",
|
||||
data: {
|
||||
rows,
|
||||
pendingInvitations: input.pendingInvitations,
|
||||
assignableRoles: input.assignableRoles,
|
||||
canInvite: input.canInvite,
|
||||
canEditRoles: input.canEditRoles,
|
||||
canManageMembers: input.canManageMembers,
|
||||
emptyHeadlineKey: "settings.members.empty.headline",
|
||||
emptyBodyKey: "settings.members.empty.body",
|
||||
noMatchesKey: "settings.members.empty.noMatches",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Client-side filter for S01 (search across name/email/phone + role/status/2FA
|
||||
* selects). Pure so it is unit-testable and shared between renderers.
|
||||
*/
|
||||
export function filterMembersRows(rows: readonly MembersListRow[], filter: MembersListFilterState): MembersListRow[] {
|
||||
const query = filter.query.trim().toUpperCase();
|
||||
return rows.filter((row) => {
|
||||
if (query) {
|
||||
const haystack = [row.name, row.email, row.phone ?? ""].join(" ").toUpperCase();
|
||||
if (!haystack.includes(query)) return false;
|
||||
}
|
||||
if (filter.roleId && !row.roles.some((role) => role.id === filter.roleId)) return false;
|
||||
if (filter.status && row.status !== filter.status) return false;
|
||||
if (filter.mfa !== null && row.mfaEnabled !== filter.mfa) return false;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
// --- Hot-swap component model (M015/M017) ---
|
||||
|
||||
/** Normalized row model shared by the Subframe and mock renderers. */
|
||||
export interface MembersListModelRow {
|
||||
readonly tenantUserId: string;
|
||||
readonly name: string;
|
||||
readonly email: string;
|
||||
readonly statusLabelKey: string;
|
||||
readonly mfaEnabled: boolean;
|
||||
readonly roleNames: readonly string[];
|
||||
readonly canDeactivate: boolean;
|
||||
readonly canReactivate: boolean;
|
||||
}
|
||||
|
||||
export interface MembersListModel {
|
||||
readonly titleKey: string;
|
||||
readonly emptyHeadlineKey: string;
|
||||
readonly emptyBodyKey: string;
|
||||
readonly canInvite: boolean;
|
||||
readonly rows: readonly MembersListModelRow[];
|
||||
readonly rowCount: number;
|
||||
}
|
||||
|
||||
export function toMembersListModel(data: MembersListData): MembersListModel {
|
||||
return {
|
||||
titleKey: "settings.members.title",
|
||||
emptyHeadlineKey: data.emptyHeadlineKey,
|
||||
emptyBodyKey: data.emptyBodyKey,
|
||||
canInvite: data.canInvite,
|
||||
rows: data.rows.map((row) => ({
|
||||
tenantUserId: row.tenantUserId,
|
||||
name: row.name,
|
||||
email: row.email,
|
||||
statusLabelKey: row.statusLabelKey,
|
||||
mfaEnabled: row.mfaEnabled,
|
||||
roleNames: row.roles.map((role) => role.name),
|
||||
canDeactivate: row.canDeactivate,
|
||||
canReactivate: row.canReactivate,
|
||||
})),
|
||||
rowCount: data.rows.length,
|
||||
};
|
||||
}
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
buildRoleEditorVM,
|
||||
deriveRoleEditorSectionId,
|
||||
filterRoleEditorSections,
|
||||
parsePermissionScope,
|
||||
togglePermission,
|
||||
ROLE_EDITOR_SECTION_IDS,
|
||||
type RoleEditorInputPermission,
|
||||
} from "../index.js";
|
||||
|
||||
const CATALOG: RoleEditorInputPermission[] = [
|
||||
{ name: "app.dashboard.view", description: "Default permission app.dashboard.view" },
|
||||
{ name: "app.settings.members.view", description: "Default permission app.settings.members.view" },
|
||||
{ name: "app.settings.members.update", description: "Default permission app.settings.members.update" },
|
||||
{ name: "app.settings.groups.full", description: "Default permission app.settings.groups.full" },
|
||||
{ name: "app.settings.roles.set", description: "Default permission app.settings.roles.set" },
|
||||
{ name: "app.settings.subscription.update", description: "Default permission app.settings.subscription.update" },
|
||||
{ name: "app.settings.subscription.invoices.view", description: "Default permission app.settings.subscription.invoices.view" },
|
||||
{ name: "app.settings.auditTrails.view", description: "Default permission app.settings.auditTrails.view" },
|
||||
{ name: "privacy.user_export.self", description: "Default permission privacy.user_export.self" },
|
||||
{ name: "app.settings.apiKeys.view", description: "Default permission app.settings.apiKeys.view" },
|
||||
{ name: "integrations.connect", description: "Default permission integrations.connect" },
|
||||
{ name: "files.read_all", description: "Default permission files.read_all" },
|
||||
{ name: "tasks.write", description: "Default permission tasks.write" },
|
||||
{ name: "crm.read_all", description: "Default permission crm.read_all" },
|
||||
];
|
||||
|
||||
describe("parsePermissionScope / deriveRoleEditorSectionId", () => {
|
||||
it("strips the trailing action", () => {
|
||||
expect(parsePermissionScope("app.settings.members.view")).toBe("app.settings.members");
|
||||
expect(parsePermissionScope("files.read_all")).toBe("files");
|
||||
expect(parsePermissionScope("weird")).toBe("weird");
|
||||
});
|
||||
|
||||
it("maps scopes to David's M02 sections with longest-prefix precedence", () => {
|
||||
expect(deriveRoleEditorSectionId("app.dashboard.view")).toBe("general");
|
||||
expect(deriveRoleEditorSectionId("app.settings.members.update")).toBe("members");
|
||||
expect(deriveRoleEditorSectionId("app.settings.groups.full")).toBe("members");
|
||||
expect(deriveRoleEditorSectionId("app.settings.roles.set")).toBe("roles");
|
||||
expect(deriveRoleEditorSectionId("app.settings.subscription.invoices.view")).toBe("billing");
|
||||
expect(deriveRoleEditorSectionId("app.settings.auditTrails.view")).toBe("auditSecurity");
|
||||
expect(deriveRoleEditorSectionId("privacy.user_export.self")).toBe("auditSecurity");
|
||||
expect(deriveRoleEditorSectionId("app.settings.apiKeys.view")).toBe("integrations");
|
||||
expect(deriveRoleEditorSectionId("files.read_all")).toBe("files");
|
||||
expect(deriveRoleEditorSectionId("tasks.write")).toBe("tasks");
|
||||
});
|
||||
|
||||
it("sends unknown scopes to otherModules instead of hiding them", () => {
|
||||
expect(deriveRoleEditorSectionId("crm.read_all")).toBe("otherModules");
|
||||
expect(deriveRoleEditorSectionId("automation.run")).toBe("otherModules");
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildRoleEditorVM", () => {
|
||||
it("groups the catalog into ordered sections with enabled state", () => {
|
||||
const vm = buildRoleEditorVM({
|
||||
role: { id: "r1", name: "Monteur", description: "SHK" },
|
||||
appPermissions: CATALOG,
|
||||
assignedPermissionNames: ["app.dashboard.view", "tasks.write"],
|
||||
});
|
||||
expect(vm.status).toBe("ready");
|
||||
const data = vm.data!;
|
||||
expect(data.roleId).toBe("r1");
|
||||
const ids = data.sections.map((s) => s.id);
|
||||
// Order must follow ROLE_EDITOR_SECTION_IDS (David's sidebar order).
|
||||
expect(ids).toEqual(ROLE_EDITOR_SECTION_IDS.filter((id) => ids.includes(id)));
|
||||
expect(ids).toContain("otherModules");
|
||||
const general = data.sections.find((s) => s.id === "general")!;
|
||||
expect(general.labelKey).toBe("settings.rolesAndPermissions.editor.sections.general");
|
||||
expect(general.enabledCount).toBe(1);
|
||||
expect(data.enabledTotal).toBe(2);
|
||||
expect(data.permissionTotal).toBe(CATALOG.length);
|
||||
});
|
||||
|
||||
it("supports the create (M04A) and duplicate (M04B) entries", () => {
|
||||
const created = buildRoleEditorVM({ role: null, appPermissions: CATALOG, assignedPermissionNames: [] });
|
||||
expect(created.data!.roleId).toBeNull();
|
||||
expect(created.data!.name).toBe("");
|
||||
|
||||
const duplicated = buildRoleEditorVM({
|
||||
role: null,
|
||||
duplicatedFromName: "Monteur",
|
||||
appPermissions: CATALOG,
|
||||
assignedPermissionNames: ["files.read_all"],
|
||||
});
|
||||
expect(duplicated.data!.duplicatedFromName).toBe("Monteur");
|
||||
expect(duplicated.data!.enabledTotal).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("filterRoleEditorSections", () => {
|
||||
const sections = buildRoleEditorVM({ role: null, appPermissions: CATALOG, assignedPermissionNames: ["tasks.write"] }).data!.sections;
|
||||
|
||||
it("filters permissions across sections and drops empty sections", () => {
|
||||
const filtered = filterRoleEditorSections(sections, "subscription");
|
||||
expect(filtered.map((s) => s.id)).toEqual(["billing"]);
|
||||
expect(filtered[0].permissions.length).toBe(2);
|
||||
});
|
||||
|
||||
it("recomputes enabledCount and passes through on empty query", () => {
|
||||
expect(filterRoleEditorSections(sections, "tasks")[0].enabledCount).toBe(1);
|
||||
expect(filterRoleEditorSections(sections, " ").length).toBe(sections.length);
|
||||
});
|
||||
});
|
||||
|
||||
describe("togglePermission", () => {
|
||||
it("adds and removes without mutating the source set", () => {
|
||||
const base = new Set(["a"]);
|
||||
const withB = togglePermission(base, "b", true);
|
||||
expect([...withB].sort()).toEqual(["a", "b"]);
|
||||
const withoutA = togglePermission(withB, "a", false);
|
||||
expect([...withoutA]).toEqual(["b"]);
|
||||
expect([...base]).toEqual(["a"]);
|
||||
});
|
||||
});
|
||||
+179
@@ -0,0 +1,179 @@
|
||||
import type { VMState } from "../index.js";
|
||||
|
||||
/**
|
||||
* Role editor view-model (R-P2b, David's D-P2 `WF-P2 Admin RBAC` M02/M04A/M04B).
|
||||
* Pure function, no React/Prisma/app imports.
|
||||
*
|
||||
* The big editor groups the existing app permission catalog into David's
|
||||
* sidebar sections purely by permission-name scope (the part before the last
|
||||
* dot) — NO new permission keys and no schema change. Unknown scopes fall into
|
||||
* the "Weitere Module" section so nothing becomes invisible when new modules
|
||||
* land their permissions.
|
||||
*/
|
||||
|
||||
export type RoleEditorPermissionRow = {
|
||||
readonly name: string;
|
||||
/** Raw catalog description (screen upgrades it via permissionDisplayName(t)). */
|
||||
readonly description: string;
|
||||
readonly enabled: boolean;
|
||||
};
|
||||
|
||||
export type RoleEditorSection = {
|
||||
readonly id: string;
|
||||
/** i18n key: `settings.rolesAndPermissions.editor.sections.<id>` */
|
||||
readonly labelKey: string;
|
||||
readonly permissions: readonly RoleEditorPermissionRow[];
|
||||
readonly enabledCount: number;
|
||||
};
|
||||
|
||||
export interface RoleEditorData {
|
||||
/** null = creating a new role (M04A) — the editor posts to the create action. */
|
||||
readonly roleId: string | null;
|
||||
readonly name: string;
|
||||
readonly description: string;
|
||||
/** Duplicated-from source (M04B) shown in the hint block, null otherwise. */
|
||||
readonly duplicatedFromName: string | null;
|
||||
readonly sections: readonly RoleEditorSection[];
|
||||
readonly enabledTotal: number;
|
||||
readonly permissionTotal: number;
|
||||
}
|
||||
|
||||
export type RoleEditorVM = VMState<RoleEditorData>;
|
||||
|
||||
export interface RoleEditorInputPermission {
|
||||
readonly name: string;
|
||||
readonly description: string;
|
||||
}
|
||||
|
||||
export interface BuildRoleEditorVMInput {
|
||||
readonly role: { readonly id: string; readonly name: string; readonly description: string } | null;
|
||||
readonly duplicatedFromName?: string | null;
|
||||
readonly appPermissions: readonly RoleEditorInputPermission[];
|
||||
readonly assignedPermissionNames: readonly string[];
|
||||
}
|
||||
|
||||
/** Ordered section ids — mirrors David's M02 sidebar order. */
|
||||
export const ROLE_EDITOR_SECTION_IDS = [
|
||||
"general",
|
||||
"members",
|
||||
"roles",
|
||||
"workspace",
|
||||
"billing",
|
||||
"auditSecurity",
|
||||
"integrations",
|
||||
"files",
|
||||
"tasks",
|
||||
"otherModules",
|
||||
] as const;
|
||||
|
||||
export type RoleEditorSectionId = (typeof ROLE_EDITOR_SECTION_IDS)[number];
|
||||
|
||||
/**
|
||||
* scope (permission name without the trailing action) → section id. Longest
|
||||
* prefix wins so `app.settings.subscription.invoices` beats `app.settings`.
|
||||
*/
|
||||
const SCOPE_SECTIONS: ReadonlyArray<readonly [string, RoleEditorSectionId]> = [
|
||||
["app.dashboard", "general"],
|
||||
["dashboard", "general"],
|
||||
["search", "general"],
|
||||
["app.settings.members", "members"],
|
||||
["app.settings.groups", "members"],
|
||||
["app.settings.roles", "roles"],
|
||||
["app.settings.account", "workspace"],
|
||||
["app.settings.accounts", "workspace"],
|
||||
["app.plugins", "workspace"],
|
||||
["app.onboarding", "workspace"],
|
||||
["app.settings.subscription", "billing"],
|
||||
["app.settings.auditTrails", "auditSecurity"],
|
||||
["privacy", "auditSecurity"],
|
||||
["app.settings.apiKeys", "integrations"],
|
||||
["integrations", "integrations"],
|
||||
["email.domain", "integrations"],
|
||||
["files", "files"],
|
||||
["tasks", "tasks"],
|
||||
];
|
||||
|
||||
/** Splits a permission name into scope + trailing action (pure re-implementation). */
|
||||
export function parsePermissionScope(name: string): string {
|
||||
const parts = name.split(".");
|
||||
return parts.length < 2 ? name : parts.slice(0, -1).join(".");
|
||||
}
|
||||
|
||||
export function deriveRoleEditorSectionId(permissionName: string): RoleEditorSectionId {
|
||||
const scope = parsePermissionScope(permissionName);
|
||||
let match: RoleEditorSectionId | null = null;
|
||||
let matchLength = -1;
|
||||
for (const [prefix, sectionId] of SCOPE_SECTIONS) {
|
||||
if ((scope === prefix || scope.startsWith(`${prefix}.`)) && prefix.length > matchLength) {
|
||||
match = sectionId;
|
||||
matchLength = prefix.length;
|
||||
}
|
||||
}
|
||||
return match ?? "otherModules";
|
||||
}
|
||||
|
||||
export function buildRoleEditorVM(input: BuildRoleEditorVMInput): RoleEditorVM {
|
||||
const assigned = new Set(input.assignedPermissionNames);
|
||||
const grouped = new Map<RoleEditorSectionId, RoleEditorPermissionRow[]>();
|
||||
for (const permission of input.appPermissions) {
|
||||
const sectionId = deriveRoleEditorSectionId(permission.name);
|
||||
const rows = grouped.get(sectionId) ?? [];
|
||||
rows.push({
|
||||
name: permission.name,
|
||||
description: permission.description,
|
||||
enabled: assigned.has(permission.name),
|
||||
});
|
||||
grouped.set(sectionId, rows);
|
||||
}
|
||||
|
||||
const sections: RoleEditorSection[] = ROLE_EDITOR_SECTION_IDS.filter((id) => grouped.has(id)).map((id) => {
|
||||
const permissions = grouped.get(id) ?? [];
|
||||
return {
|
||||
id,
|
||||
labelKey: `settings.rolesAndPermissions.editor.sections.${id}`,
|
||||
permissions,
|
||||
enabledCount: permissions.filter((row) => row.enabled).length,
|
||||
};
|
||||
});
|
||||
|
||||
const permissionTotal = sections.reduce((sum, section) => sum + section.permissions.length, 0);
|
||||
const enabledTotal = sections.reduce((sum, section) => sum + section.enabledCount, 0);
|
||||
|
||||
return {
|
||||
status: "ready",
|
||||
data: {
|
||||
roleId: input.role?.id ?? null,
|
||||
name: input.role?.name ?? "",
|
||||
description: input.role?.description ?? "",
|
||||
duplicatedFromName: input.duplicatedFromName ?? null,
|
||||
sections,
|
||||
enabledTotal,
|
||||
permissionTotal,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Editor search (M02): filters permission rows by a normalized query across the
|
||||
* raw name and description; sections without matches disappear. Display-label
|
||||
* search happens screen-side (needs `t`) — this pure filter covers the
|
||||
* name/description base so the behaviour is unit-testable.
|
||||
*/
|
||||
export function filterRoleEditorSections(sections: readonly RoleEditorSection[], query: string): RoleEditorSection[] {
|
||||
const normalized = query.trim().toUpperCase();
|
||||
if (!normalized) return [...sections];
|
||||
return sections
|
||||
.map((section) => {
|
||||
const permissions = section.permissions.filter((row) => `${row.name} ${row.description}`.toUpperCase().includes(normalized));
|
||||
return { ...section, permissions, enabledCount: permissions.filter((row) => row.enabled).length };
|
||||
})
|
||||
.filter((section) => section.permissions.length > 0);
|
||||
}
|
||||
|
||||
/** Applies a toggle to the (screen-held) enabled-set — pure helper for tests. */
|
||||
export function togglePermission(enabledNames: ReadonlySet<string>, permissionName: string, enabled: boolean): Set<string> {
|
||||
const next = new Set(enabledNames);
|
||||
if (enabled) next.add(permissionName);
|
||||
else next.delete(permissionName);
|
||||
return next;
|
||||
}
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
buildRolesListVM,
|
||||
deriveRoleTypeKey,
|
||||
filterRolesRows,
|
||||
toRolesListModel,
|
||||
EMPTY_ROLES_FILTER,
|
||||
type RolesListInputRow,
|
||||
} from "../index.js";
|
||||
|
||||
const TENANT = "t1";
|
||||
|
||||
function inputRow(overrides: Partial<RolesListInputRow> = {}): RolesListInputRow {
|
||||
return {
|
||||
id: "r1",
|
||||
name: "Monteur",
|
||||
description: "SHK Monteur",
|
||||
isDefault: false,
|
||||
tenantId: TENANT,
|
||||
memberCount: 0,
|
||||
permissionCount: 4,
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
function buildVM(rows: RolesListInputRow[], canManageRoles = true) {
|
||||
return buildRolesListVM({ rows, tenantId: TENANT, canManageRoles });
|
||||
}
|
||||
|
||||
describe("deriveRoleTypeKey", () => {
|
||||
it("marks defaults and foreign/shared roles as system", () => {
|
||||
expect(deriveRoleTypeKey({ isDefault: true, tenantId: null }, TENANT)).toBe("system");
|
||||
expect(deriveRoleTypeKey({ isDefault: false, tenantId: null }, TENANT)).toBe("system");
|
||||
expect(deriveRoleTypeKey({ isDefault: false, tenantId: "other" }, TENANT)).toBe("system");
|
||||
expect(deriveRoleTypeKey({ isDefault: false, tenantId: TENANT }, TENANT)).toBe("custom");
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildRolesListVM", () => {
|
||||
it("protects system roles and enables custom-role actions", () => {
|
||||
const vm = buildVM([inputRow({ id: "sys", name: "SuperUser", isDefault: true, tenantId: null }), inputRow()]);
|
||||
const [system, custom] = vm.data!.rows;
|
||||
expect(system.typeKey).toBe("system");
|
||||
expect(system.typeLabelKey).toBe("settings.rolesAndPermissions.type.system");
|
||||
expect(system.canEdit).toBe(false);
|
||||
expect(system.canDelete).toBe(false);
|
||||
expect(custom.typeKey).toBe("custom");
|
||||
expect(custom.canEdit).toBe(true);
|
||||
expect(custom.canDelete).toBe(true);
|
||||
expect(custom.deleteBlockedInUse).toBe(false);
|
||||
});
|
||||
|
||||
it("blocks delete when members are assigned (D03)", () => {
|
||||
const vm = buildVM([inputRow({ memberCount: 3 })]);
|
||||
const row = vm.data!.rows[0];
|
||||
expect(row.canDelete).toBe(true);
|
||||
expect(row.deleteBlockedInUse).toBe(true);
|
||||
});
|
||||
|
||||
it("removes all mutations without the manage permission", () => {
|
||||
const vm = buildVM([inputRow()], false);
|
||||
const row = vm.data!.rows[0];
|
||||
expect(row.canEdit).toBe(false);
|
||||
expect(row.canDuplicate).toBe(false);
|
||||
expect(row.canDelete).toBe(false);
|
||||
expect(vm.data!.canCreate).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("filterRolesRows", () => {
|
||||
const rows = buildVM([
|
||||
inputRow({ id: "sys", name: "SuperUser", description: "Has all app permissions", isDefault: true, tenantId: null, memberCount: 2 }),
|
||||
inputRow(),
|
||||
inputRow({ id: "r2", name: "Verwaltung", description: "Backoffice", memberCount: 1 }),
|
||||
]).data!.rows;
|
||||
|
||||
it("searches name and description", () => {
|
||||
expect(filterRolesRows(rows, { ...EMPTY_ROLES_FILTER, query: "backoffice" }).map((r) => r.id)).toEqual(["r2"]);
|
||||
});
|
||||
|
||||
it("filters by type and in-use", () => {
|
||||
expect(filterRolesRows(rows, { ...EMPTY_ROLES_FILTER, type: "system" }).map((r) => r.id)).toEqual(["sys"]);
|
||||
expect(filterRolesRows(rows, { ...EMPTY_ROLES_FILTER, inUse: true }).map((r) => r.id)).toEqual(["sys", "r2"]);
|
||||
expect(filterRolesRows(rows, { ...EMPTY_ROLES_FILTER, inUse: false }).map((r) => r.id)).toEqual(["r1"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("toRolesListModel", () => {
|
||||
it("normalizes rows for the hot-swap renderers", () => {
|
||||
const model = toRolesListModel(buildVM([inputRow({ memberCount: 2 })]).data!);
|
||||
expect(model.titleKey).toBe("settings.members.tabs.rolesAndPermissions");
|
||||
expect(model.rows[0]).toMatchObject({ name: "Monteur", memberCount: 2, deleteBlockedInUse: true });
|
||||
expect(model.rowCount).toBe(1);
|
||||
});
|
||||
});
|
||||
+165
@@ -0,0 +1,165 @@
|
||||
import type { VMState } from "../index.js";
|
||||
|
||||
/**
|
||||
* Roles & permissions admin list view-model (R-P2b, David's D-P2
|
||||
* `WF-P2 Admin RBAC` S02). Pure function, no React/Prisma/app imports.
|
||||
*
|
||||
* "System" rows are the seeded default roles (tenant-less, immutable per
|
||||
* `getTenantMutableAppRole`); everything the tenant owns is "custom" and can
|
||||
* be edited/duplicated/deleted. Deleting a role that still has members is
|
||||
* blocked (D03 dialog) — reassign flows are Backlog/V2 by design decision.
|
||||
*/
|
||||
|
||||
export type RoleTypeKey = "system" | "custom";
|
||||
|
||||
export type RolesListRow = {
|
||||
readonly id: string;
|
||||
readonly name: string;
|
||||
readonly description: string;
|
||||
readonly typeKey: RoleTypeKey;
|
||||
/** i18n key for the type column badge. */
|
||||
readonly typeLabelKey: string;
|
||||
readonly memberCount: number;
|
||||
readonly permissionCount: number;
|
||||
readonly canEdit: boolean;
|
||||
readonly canDuplicate: boolean;
|
||||
/** Delete visible at all (custom roles only). */
|
||||
readonly canDelete: boolean;
|
||||
/** Delete visible but blocked because members are assigned (D03). */
|
||||
readonly deleteBlockedInUse: boolean;
|
||||
};
|
||||
|
||||
export type RolesListFilterState = {
|
||||
readonly query: string;
|
||||
readonly type: RoleTypeKey | null;
|
||||
/** true = only roles with members, false = only unused, null = all. */
|
||||
readonly inUse: boolean | null;
|
||||
};
|
||||
|
||||
export const EMPTY_ROLES_FILTER: RolesListFilterState = {
|
||||
query: "",
|
||||
type: null,
|
||||
inUse: null,
|
||||
};
|
||||
|
||||
export interface RolesListData {
|
||||
readonly rows: readonly RolesListRow[];
|
||||
readonly canCreate: boolean;
|
||||
readonly emptyHeadlineKey: string;
|
||||
readonly emptyBodyKey: string;
|
||||
readonly noMatchesKey: string;
|
||||
}
|
||||
|
||||
export type RolesListVM = VMState<RolesListData>;
|
||||
|
||||
/** Raw role row the loader passes in. */
|
||||
export interface RolesListInputRow {
|
||||
readonly id: string;
|
||||
readonly name: string;
|
||||
readonly description: string;
|
||||
readonly isDefault: boolean;
|
||||
/** Owning tenant id, null for shared/seeded defaults. */
|
||||
readonly tenantId: string | null;
|
||||
readonly memberCount: number;
|
||||
readonly permissionCount: number;
|
||||
}
|
||||
|
||||
export interface BuildRolesListVMInput {
|
||||
readonly rows: readonly RolesListInputRow[];
|
||||
readonly tenantId: string;
|
||||
readonly canManageRoles: boolean;
|
||||
}
|
||||
|
||||
export function deriveRoleTypeKey(row: Pick<RolesListInputRow, "isDefault" | "tenantId">, tenantId: string): RoleTypeKey {
|
||||
return row.isDefault || row.tenantId === null || row.tenantId !== tenantId ? "system" : "custom";
|
||||
}
|
||||
|
||||
export function buildRolesListVM(input: BuildRolesListVMInput): RolesListVM {
|
||||
const rows: RolesListRow[] = input.rows.map((row) => {
|
||||
const typeKey = deriveRoleTypeKey(row, input.tenantId);
|
||||
const mutable = typeKey === "custom" && input.canManageRoles;
|
||||
return {
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
description: row.description,
|
||||
typeKey,
|
||||
typeLabelKey: `settings.rolesAndPermissions.type.${typeKey}`,
|
||||
memberCount: row.memberCount,
|
||||
permissionCount: row.permissionCount,
|
||||
canEdit: mutable,
|
||||
// System roles are read-only sources; duplicating them is allowed except for
|
||||
// protected defaults — David only protects the admin system role, but every
|
||||
// duplicate lands as a tenant-owned custom role anyway, so copying is safe.
|
||||
canDuplicate: input.canManageRoles,
|
||||
canDelete: mutable,
|
||||
deleteBlockedInUse: mutable && row.memberCount > 0,
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
status: "ready",
|
||||
data: {
|
||||
rows,
|
||||
canCreate: input.canManageRoles,
|
||||
emptyHeadlineKey: "settings.rolesAndPermissions.empty.title",
|
||||
emptyBodyKey: "settings.rolesAndPermissions.empty.description",
|
||||
noMatchesKey: "settings.rolesAndPermissions.empty.noMatches",
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/** Client-side filter for S02 (search on name/description + type/in-use selects). */
|
||||
export function filterRolesRows(rows: readonly RolesListRow[], filter: RolesListFilterState): RolesListRow[] {
|
||||
const query = filter.query.trim().toUpperCase();
|
||||
return rows.filter((row) => {
|
||||
if (query) {
|
||||
const haystack = `${row.name} ${row.description}`.toUpperCase();
|
||||
if (!haystack.includes(query)) return false;
|
||||
}
|
||||
if (filter.type && row.typeKey !== filter.type) return false;
|
||||
if (filter.inUse !== null && row.memberCount > 0 !== filter.inUse) return false;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
// --- Hot-swap component model (M015/M017) ---
|
||||
|
||||
export interface RolesListModelRow {
|
||||
readonly id: string;
|
||||
readonly name: string;
|
||||
readonly typeLabelKey: string;
|
||||
readonly memberCount: number;
|
||||
readonly permissionCount: number;
|
||||
readonly canEdit: boolean;
|
||||
readonly canDelete: boolean;
|
||||
readonly deleteBlockedInUse: boolean;
|
||||
}
|
||||
|
||||
export interface RolesListModel {
|
||||
readonly titleKey: string;
|
||||
readonly emptyHeadlineKey: string;
|
||||
readonly emptyBodyKey: string;
|
||||
readonly canCreate: boolean;
|
||||
readonly rows: readonly RolesListModelRow[];
|
||||
readonly rowCount: number;
|
||||
}
|
||||
|
||||
export function toRolesListModel(data: RolesListData): RolesListModel {
|
||||
return {
|
||||
titleKey: "settings.members.tabs.rolesAndPermissions",
|
||||
emptyHeadlineKey: data.emptyHeadlineKey,
|
||||
emptyBodyKey: data.emptyBodyKey,
|
||||
canCreate: data.canCreate,
|
||||
rows: data.rows.map((row) => ({
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
typeLabelKey: row.typeLabelKey,
|
||||
memberCount: row.memberCount,
|
||||
permissionCount: row.permissionCount,
|
||||
canEdit: row.canEdit,
|
||||
canDelete: row.canDelete,
|
||||
deleteBlockedInUse: row.deleteBlockedInUse,
|
||||
})),
|
||||
rowCount: data.rows.length,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user