Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/server/access/collections.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { describe, expect, it, vi } from "vitest";

vi.mock("@/lib/prisma", () => ({
prisma: {},
}));

import { canRenameOrDeleteCollection } from "./collections";

describe("canRenameOrDeleteCollection", () => {
it("allows owners and creators", () => {
expect(canRenameOrDeleteCollection({ kind: "owner" })).toBe(true);
expect(canRenameOrDeleteCollection({ kind: "creator" })).toBe(true);
});

it("denies granted users and non-members", () => {
expect(canRenameOrDeleteCollection({ kind: "grant" })).toBe(false);
expect(canRenameOrDeleteCollection({ kind: "none" })).toBe(false);
});
});
3 changes: 2 additions & 1 deletion src/server/access/collections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export type CollectionAccessState =
export function canRenameOrDeleteCollection(
state: CollectionAccessState,
): boolean {
return state.kind !== "none";
// Restrict destructive collection-level operations to owner/creator.
return state.kind === "owner" || state.kind === "creator";
}

export async function loadCollectionAccessState(params: {
Expand Down
Loading