A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search
fix(trpc): hide highlight notes from shared-list collaborators (#3284)
Mohamed Bassem9a40dfdab483
diff --git a/packages/trpc/models/highlights.service.ts b/packages/trpc/models/highlights.service.tsindex b972a05e..9921efc0 100644--- a/packages/trpc/models/highlights.service.ts+++ b/packages/trpc/models/highlights.service.ts@@ -40,8 +40,15 @@ export class HighlightsService {return await this.repo.create(actorUserId(actor), input);}- async getForBookmark(bookmarkId: string): Promise<Highlight[]> {- return await this.repo.getForBookmark(bookmarkId);+ async getForBookmark(actor: Actor, bookmarkId: string): Promise<Highlight[]> {+ const highlights = await this.repo.getForBookmark(bookmarkId);+ const userId = actorUserId(actor);+ // Collaborators on a shared list can see the highlighted text, but the+ // note is the author's personal annotation, like a bookmark's note (see+ // Bookmark.asZBookmark), so only its author gets it.+ return highlights.map((highlight) =>+ highlight.userId === userId ? highlight : { ...highlight, note: null },+ );}async getAll(diff --git a/packages/trpc/routers/highlights.ts b/packages/trpc/routers/highlights.tsindex 139cbe51..414c68d4 100644--- a/packages/trpc/routers/highlights.ts+++ b/packages/trpc/routers/highlights.ts@@ -64,6 +64,7 @@ export const highlightsAppRouter = router({.use(ensureBookmarkAccess).query(async ({ ctx }) => {const highlights = await ctx.highlightsService.getForBookmark(+ ctx.actor,ctx.bookmark.id,);return { highlights };diff --git a/packages/trpc/routers/sharedLists.test.ts b/packages/trpc/routers/sharedLists.test.tsindex 5f571813..9d86c0e2 100644--- a/packages/trpc/routers/sharedLists.test.ts+++ b/packages/trpc/routers/sharedLists.test.ts@@ -713,6 +713,55 @@ describe("Shared Lists", () => {expect(collaboratorBookmark?.note).toBeNull();});+ test<CustomTestContext>("should hide the owner's highlight notes from collaborators", async ({+ apiCallers,+ }) => {+ const ownerApi = apiCallers[0];+ const collaboratorApi = apiCallers[1];++ const list = await ownerApi.lists.create({+ name: "Shared List",+ icon: "📚",+ type: "manual",+ });+ const bookmark = await ownerApi.bookmarks.createBookmark({+ type: BookmarkTypes.TEXT,+ text: "Shared bookmark with a highlight",+ });+ await ownerApi.highlights.create({+ bookmarkId: bookmark.id,+ startOffset: 0,+ endOffset: 6,+ color: "yellow",+ text: "Shared",+ note: "Private highlight note",+ });+ await ownerApi.lists.addToList({+ listId: list.id,+ bookmarkId: bookmark.id,+ });+ await addAndAcceptCollaborator(+ ownerApi,+ collaboratorApi,+ list.id,+ "viewer",+ );++ const ownerView = await ownerApi.highlights.getForBookmark({+ bookmarkId: bookmark.id,+ });+ expect(ownerView.highlights).toHaveLength(1);+ expect(ownerView.highlights[0].note).toBe("Private highlight note");++ // The highlighted text stays visible; only the personal note is hidden.+ const collaboratorView = await collaboratorApi.highlights.getForBookmark({+ bookmarkId: bookmark.id,+ });+ expect(collaboratorView.highlights).toHaveLength(1);+ expect(collaboratorView.highlights[0].text).toBe("Shared");+ expect(collaboratorView.highlights[0].note).toBeNull();+ });+// Note: Asset handling for shared bookmarks is tested via the REST API in e2e tests// This is because tRPC tests don't have easy access to file upload functionality