diff --git a/app/components/Sidebar/components/PersonalDocs.tsx b/app/components/Sidebar/components/PersonalDocs.tsx index 1de0c01167..1f9abd5f74 100644 --- a/app/components/Sidebar/components/PersonalDocs.tsx +++ b/app/components/Sidebar/components/PersonalDocs.tsx @@ -33,11 +33,13 @@ import SidebarAction from "./SidebarAction"; import SidebarContext, { type SidebarContextType } from "./SidebarContext"; import SidebarLink from "./SidebarLink"; -const PersonalDocsList = observer(function PersonalDocsList() { +function PersonalDocs() { const { documents, userMemberships } = useStores(); const { t } = useTranslation(); const history = useHistory(); const user = useCurrentUser(); + const team = useCurrentTeam(); + const can = usePolicy(team); const [isAddingNew, setIsAddingNew, closeAddingNew] = useBoolean(); const newTitleRef = useRef(null); @@ -72,9 +74,10 @@ const PersonalDocsList = observer(function PersonalDocsList() { section: DocumentSection, icon: , keywords: "create personal private", + visible: !!can.createPersonalDocument, perform: setIsAddingNew, }), - [setIsAddingNew] + [can.createPersonalDocument, setIsAddingNew] ); const headerActions = useMemo(() => [newDocAction], [newDocAction]); @@ -126,14 +129,19 @@ const PersonalDocsList = observer(function PersonalDocsList() { ) ); + // Creation can be disabled while existing personal documents remain readable. + if (!can.createPersonalDocument && !personal.length) { + return null; + } + return (
{reorderProps.isDragging && ( @@ -180,7 +188,7 @@ const PersonalDocsList = observer(function PersonalDocsList() { )} - {isAddingNew && ( + {isAddingNew && can.createPersonalDocument && ( true} depth={0} @@ -206,15 +214,6 @@ const PersonalDocsList = observer(function PersonalDocsList() { ); -}); - -function PersonalDocs() { - const team = useCurrentTeam(); - const can = usePolicy(team); - - // The list is a child component so that the documents are only requested - // when the user is able to have personal documents at all. - return can.createPersonalDocument ? : null; } export default observer(PersonalDocs); diff --git a/server/routes/api/documents/documents.test.ts b/server/routes/api/documents/documents.test.ts index b6fe78b31e..abfe72305d 100644 --- a/server/routes/api/documents/documents.test.ts +++ b/server/routes/api/documents/documents.test.ts @@ -10065,6 +10065,22 @@ describe("personal documents when the preference is disabled", () => { expect(policy.abilities.update).toBe(false); }); + it("should still list existing personal documents for the sidebar", async () => { + const { user, document } = await buildFrozen(); + + const res = await server.post("/api/documents.personal", user, { + body: {}, + }); + expect(res.status).toEqual(200); + const body = await res.json(); + expect(body.data.documents).toEqual([ + expect.objectContaining({ id: document.id }), + ]); + expect(body.data.memberships).toEqual([ + expect.objectContaining({ documentId: document.id, userId: user.id }), + ]); + }); + it("should not allow editing", async () => { const { user, document } = await buildFrozen();