Skip to content

Node.js based forum software built for the modern web

feat: allow mods/admins to see deleted posts on user profile

Barış Soner Uşaklı6e85920cb6e6
diff --git a/src/controllers/accounts/profile.js b/src/controllers/accounts/profile.js
index 9e065b73b8..e1baf1a5ef 100644
--- a/src/controllers/accounts/profile.js
+++ b/src/controllers/accounts/profile.js
@@ -1,6 +1,7 @@
'use strict';
const nconf = require('nconf');
+const _ = require('lodash');
const db = require('../../database');
const user = require('../../user');
@@ -86,6 +87,13 @@ async function getPosts(callerUid, userData, setSuffix) {
let start = 0;
const count = 10;
const postData = [];
+
+ const [isAdmin, isModOfCids] = await Promise.all([
+ user.isAdministrator(callerUid),
+ user.isModerator(callerUid, cids),
+ ]);
+ const cidToIsMod = _.zipObject(cids, isModOfCids);
+
do {
/* eslint-disable no-await-in-loop */
const pids = await db.getSortedSetRevRange(keys, start, start + count - 1);
@@ -94,7 +102,7 @@ async function getPosts(callerUid, userData, setSuffix) {
}
if (pids.length) {
const p = await posts.getPostSummaryByPids(pids, callerUid, { stripTags: false });
- postData.push(...p.filter(p => p && !p.deleted && p.topic && !p.topic.deleted));
+ postData.push(...p.filter(p => p && p.topic && (isAdmin || cidToIsMod[p.topic.cid] || (!p.deleted && !p.topic.deleted))));
}
start += count;
} while (postData.length < count && hasMorePosts);