Removal of non-collaborative editing code paths (#4210)
This commit is contained in:
@@ -220,46 +220,3 @@ describe("documents.delete", () => {
|
||||
expect(backlinks.length).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("documents.title_change", () => {
|
||||
test("should update titles in backlinked documents", async () => {
|
||||
const newTitle = "test";
|
||||
const document = await buildDocument();
|
||||
const otherDocument = await buildDocument();
|
||||
const previousTitle = otherDocument.title;
|
||||
// create a doc with a link back
|
||||
document.text = `[${otherDocument.title}](${otherDocument.url})`;
|
||||
await document.save();
|
||||
// ensure the backlinks are created
|
||||
const processor = new BacklinksProcessor();
|
||||
await processor.perform({
|
||||
name: "documents.update",
|
||||
documentId: document.id,
|
||||
collectionId: document.collectionId,
|
||||
teamId: document.teamId,
|
||||
actorId: document.createdById,
|
||||
createdAt: new Date().toISOString(),
|
||||
data: { title: document.title, autosave: false, done: true },
|
||||
ip,
|
||||
});
|
||||
// change the title of the linked doc
|
||||
otherDocument.title = newTitle;
|
||||
await otherDocument.save();
|
||||
// does the text get updated with the new title
|
||||
await processor.perform({
|
||||
name: "documents.title_change",
|
||||
documentId: otherDocument.id,
|
||||
collectionId: otherDocument.collectionId,
|
||||
teamId: otherDocument.teamId,
|
||||
actorId: otherDocument.createdById,
|
||||
createdAt: new Date().toISOString(),
|
||||
data: {
|
||||
previousTitle,
|
||||
title: newTitle,
|
||||
},
|
||||
ip,
|
||||
});
|
||||
await document.reload();
|
||||
expect(document.text).toBe(`[${newTitle}](${otherDocument.url})`);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
import { Op } from "sequelize";
|
||||
import { Document, Backlink, Team } from "@server/models";
|
||||
import { Document, Backlink } from "@server/models";
|
||||
import { Event, DocumentEvent, RevisionEvent } from "@server/types";
|
||||
import parseDocumentIds from "@server/utils/parseDocumentIds";
|
||||
import slugify from "@server/utils/slugify";
|
||||
import BaseProcessor from "./BaseProcessor";
|
||||
|
||||
export default class BacklinksProcessor extends BaseProcessor {
|
||||
static applicableEvents: Event["name"][] = [
|
||||
"documents.publish",
|
||||
"documents.update",
|
||||
"documents.title_change",
|
||||
//"documents.title_change",
|
||||
"documents.delete",
|
||||
];
|
||||
|
||||
@@ -98,49 +97,7 @@ export default class BacklinksProcessor extends BaseProcessor {
|
||||
break;
|
||||
}
|
||||
|
||||
const document = await Document.findByPk(event.documentId);
|
||||
if (!document) {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Handle re-writing of titles into CRDT
|
||||
const team = await Team.findByPk(document.teamId);
|
||||
|
||||
if (team?.collaborativeEditing) {
|
||||
break;
|
||||
}
|
||||
|
||||
// update any link titles in documents that lead to this one
|
||||
const backlinks = await Backlink.findAll({
|
||||
where: {
|
||||
documentId: event.documentId,
|
||||
},
|
||||
include: [
|
||||
{
|
||||
model: Document,
|
||||
as: "reverseDocument",
|
||||
},
|
||||
],
|
||||
});
|
||||
await Promise.all(
|
||||
backlinks.map(async (backlink) => {
|
||||
const previousUrl = `/doc/${slugify(previousTitle)}-${
|
||||
document.urlId
|
||||
}`;
|
||||
|
||||
// find links in the other document that lead to this one and have
|
||||
// the old title as anchor text. Go ahead and update those to the
|
||||
// new title automatically
|
||||
backlink.reverseDocument.text = backlink.reverseDocument.text.replace(
|
||||
`[${previousTitle}](${previousUrl})`,
|
||||
`[${title}](${document.url})`
|
||||
);
|
||||
await backlink.reverseDocument.save({
|
||||
silent: true,
|
||||
hooks: false,
|
||||
});
|
||||
})
|
||||
);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user