fix: regression that caused new notes to have undefined cid and fail privilege check

This commit is contained in:
Julian Lam
2024-06-25 11:04:40 -04:00
parent 89dd2fb04a
commit a371c9fceb

View File

@@ -51,14 +51,11 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => {
let { pid: mainPid, tid, uid: authorId, timestamp, name, content, _activitypub } = mainPost; let { pid: mainPid, tid, uid: authorId, timestamp, name, content, _activitypub } = mainPost;
const hasTid = !!tid; const hasTid = !!tid;
// Update category if currently uncategorized const cid = hasTid ? await topics.getTopicField(tid, 'cid') : options.cid || -1;
if (hasTid) {
const cid = await topics.getTopicField(tid, 'cid');
if (options.cid && cid === -1) { if (options.cid && cid === -1) {
// Move topic // Move topic if currently uncategorized
await topics.tools.move(tid, { cid: options.cid, uid: 'system' }); await topics.tools.move(tid, { cid: options.cid, uid: 'system' });
} }
}
const members = await db.isSortedSetMembers(`tid:${tid}:posts`, chain.slice(0, -1).map(p => p.pid)); const members = await db.isSortedSetMembers(`tid:${tid}:posts`, chain.slice(0, -1).map(p => p.pid));
members.push(await posts.exists(mainPid)); members.push(await posts.exists(mainPid));
@@ -69,7 +66,6 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => {
return { tid, count: 0 }; return { tid, count: 0 };
} }
let cid;
let title; let title;
if (hasTid) { if (hasTid) {
mainPid = await topics.getTopicField(tid, 'mainPid'); mainPid = await topics.getTopicField(tid, 'mainPid');
@@ -87,7 +83,6 @@ Notes.assert = async (uid, input, options = { skipChecks: false }) => {
} }
// mainPid ok to leave as-is // mainPid ok to leave as-is
cid = options.cid || -1;
title = name || activitypub.helpers.generateTitle(utils.decodeHTMLEntities(content)); title = name || activitypub.helpers.generateTitle(utils.decodeHTMLEntities(content));
} }
mainPid = utils.isNumber(mainPid) ? parseInt(mainPid, 10) : mainPid; mainPid = utils.isNumber(mainPid) ? parseInt(mainPid, 10) : mainPid;