mirror of
https://github.com/outline/outline.git
synced 2026-11-24 23:00:18 +03:00
fix: Create sidebar memberships for personal documents moved to the root
This commit is contained in:
2 files changed
+59
-8
No files matched your search
@@ -563,6 +563,20 @@ class Document extends ArchivableModel<
|
||||
@AfterCreate
|
||||
@AfterUpdate
|
||||
static async cascadePersonalOwner(model: Document, ctx: HookContext) {
|
||||
// A child moved to the root needs its own sidebar record even when it
|
||||
// stays in the same personal space.
|
||||
if (
|
||||
model.personalOwnerId &&
|
||||
!model.parentDocumentId &&
|
||||
(model.changed("personalOwnerId") || model.changed("parentDocumentId"))
|
||||
) {
|
||||
await UserMembership.findOrCreateForPersonalDocument(
|
||||
model,
|
||||
model.personalOwnerId,
|
||||
ctx
|
||||
);
|
||||
}
|
||||
|
||||
if (!model.changed("personalOwnerId")) {
|
||||
return;
|
||||
}
|
||||
@@ -585,14 +599,6 @@ class Document extends ArchivableModel<
|
||||
);
|
||||
}
|
||||
|
||||
if (personalOwnerId && !model.parentDocumentId) {
|
||||
await UserMembership.findOrCreateForPersonalDocument(
|
||||
model,
|
||||
personalOwnerId,
|
||||
ctx
|
||||
);
|
||||
}
|
||||
|
||||
const previousOwnerId = model.previous("personalOwnerId");
|
||||
if (previousOwnerId && previousOwnerId !== personalOwnerId) {
|
||||
// the sidebar membership would otherwise linger once the document has
|
||||
|
||||
@@ -9629,6 +9629,51 @@ describe("#documents.documents - personal", () => {
|
||||
});
|
||||
|
||||
describe("#documents.move - personal", () => {
|
||||
it("should create a sidebar membership when a personal child moves to the root", async () => {
|
||||
const user = await buildUser();
|
||||
const parent = await buildPersonalDocument({
|
||||
teamId: user.teamId,
|
||||
userId: user.id,
|
||||
});
|
||||
const child = await buildPersonalDocument({
|
||||
teamId: user.teamId,
|
||||
userId: user.id,
|
||||
parentDocumentId: parent.id,
|
||||
});
|
||||
const grandchild = await buildPersonalDocument({
|
||||
teamId: user.teamId,
|
||||
userId: user.id,
|
||||
parentDocumentId: child.id,
|
||||
});
|
||||
|
||||
const res = await server.post("/api/documents.move", user, {
|
||||
body: { id: child.id, personalOwnerId: user.id },
|
||||
});
|
||||
expect(res.status).toEqual(200);
|
||||
|
||||
const membership = await UserMembership.findOne({
|
||||
where: { documentId: child.id, userId: user.id, sourceId: null },
|
||||
rejectOnEmpty: true,
|
||||
});
|
||||
expect(membership.index).toBeTruthy();
|
||||
|
||||
const list = await server.post("/api/documents.personal", user, {
|
||||
body: {},
|
||||
});
|
||||
const body = await list.json();
|
||||
expect(body.data.memberships).toEqual(
|
||||
expect.arrayContaining([expect.objectContaining({ id: membership.id })])
|
||||
);
|
||||
|
||||
const tree = await server.post("/api/documents.documents", user, {
|
||||
body: { id: child.id },
|
||||
});
|
||||
const treeBody = await tree.json();
|
||||
expect(treeBody.data.children).toEqual([
|
||||
expect.objectContaining({ id: grandchild.id }),
|
||||
]);
|
||||
});
|
||||
|
||||
it("should move a published document and its children into the personal space", async () => {
|
||||
const user = await buildUser();
|
||||
const collection = await buildCollection({
|
||||
|
||||
Reference in new issue
Block a user