From 6e85920cb6e620188ae8fd8c085c8b43efbd27d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Mon, 2 Nov 2020 12:03:21 -0500 Subject: [PATCH] feat: allow mods/admins to see deleted posts on user profile --- src/controllers/accounts/profile.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/controllers/accounts/profile.js b/src/controllers/accounts/profile.js index 9e065b73b8a8..e1baf1a5eff0 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);