Skip to content

Commit

Permalink
feat: allow mods/admins to see deleted posts on user profile
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Nov 2, 2020
1 parent 841cbcc commit 6e85920
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion 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');
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 6e85920

Please sign in to comment.