Node.js based forum software built for the modern web
fix: move post restoration earlier in the chain of events for `inbox.update`, because post editing is not allowed if a post is deleted
Julian Lamfae9946c2485
diff --git a/src/activitypub/inbox.js b/src/activitypub/inbox.jsindex d50a22ab9b..65e0a1eeff 100644--- a/src/activitypub/inbox.js+++ b/src/activitypub/inbox.js@@ -228,10 +228,16 @@ inbox.update = async (req) => {switch (true) {case isNote: {const cid = await posts.getCidByPid(object.id);- const allowed = await privileges.categories.can('posts:edit', cid, activitypub._constants.uid);+ const [allowed, isDeleted] = await Promise.all([+ privileges.categories.can('posts:edit', cid, activitypub._constants.uid),+ posts.getPostField(object.id, 'deleted'),+ ]);if (!allowed) {throw new Error('[[error:no-privileges]]');}+ if (isDeleted) { // fediverse users can't edit deleted posts+ await api.posts.restore({ uid: actor }, { pid: object.id });+ }const postData = await activitypub.mocks.post(object);postData.tags = await activitypub.notes._normalizeTags(postData._activitypub.tag, postData.cid);@@ -243,10 +249,6 @@ inbox.update = async (req) => {await topics.setTopicField(tid, 'title', newTitle);await topics.setTopicField(tid, 'slug', `${tid}/${slugify(newTitle) || 'topic'}`);}- const isDeleted = await posts.getPostField(object.id, 'deleted');- if (isDeleted) {- await api.posts.restore({ uid: actor }, { pid: object.id });- }break;}