Files
Davide Silvestri 89184e9b27 fix: stop editing rows hidden by restricted view filters (#6217)
* fix: stop editing rows hidden by restricted view filters

Cancel edits still queued for a row that the backend reported as hidden,
including pasted values, in grid, gallery, timeline, kanban and calendar,
so they are neither sent nor put back on screen. Close the row modal when
its row gets hidden in a restricted view; other views keep it open.

* test: cover builders and ignore broadcast order in restricted view tests

* test: add e2e tests for restricted view row visibility

Cover creating, editing, pasting and dragging rows in a restricted view
while the HTTP response is held after the server commits, the row modal
closing only in restricted views, and view default values.

* fix: hide rows created with the grid's floating add button when filtered out

createNewRowConfirmed used the single-row endpoint, which doesn't return
hidden_row_ids, so a restricted editor kept a row the view's filters
exclude. Create it through the batch endpoint and report hidden rows like
the other create paths.

* test: expect the batch endpoint for the grid's floating add button

* fix: cancel queued kanban edits when a drag hides the card
2026-10-08 09:23:06 +02:00

54 lines
1.4 KiB
TypeScript

import { getClient } from "../client";
import { User } from "./user";
import { Workspace } from "./workspace";
export type RoleScopeType =
| "workspace"
| "application"
| "database_table"
| "database_view";
export type RoleAssignment = {
scopeType: RoleScopeType;
scopeId: number;
/** A role uid such as "EDITOR" or "NO_ACCESS", or null to remove the role. */
role: string | null;
};
async function getMemberUserId(
admin: User,
workspace: Workspace,
member: User,
): Promise<number> {
const response: any = await getClient(admin).get(
`workspaces/users/workspace/${workspace.id}/`,
);
const workspaceUser = response.data.find(
(candidate: any) =>
candidate.email.toLowerCase() === member.email.toLowerCase(),
);
if (workspaceUser === undefined) {
throw new Error(`${member.email} is not in workspace ${workspace.id}.`);
}
return workspaceUser.user_id;
}
/** Assigns the member's RBAC roles in one batch; needs an enterprise license. */
export async function assignRoles(
admin: User,
workspace: Workspace,
member: User,
assignments: RoleAssignment[],
): Promise<void> {
const memberId = await getMemberUserId(admin, workspace, member);
await getClient(admin).post(`role/${workspace.id}/batch/`, {
items: assignments.map(({ scopeType, scopeId, role }) => ({
subject_id: memberId,
subject_type: "auth.User",
scope_type: scopeType,
scope_id: scopeId,
role,
})),
});
}