reference #258 show open reports on account page after a very subtle hint from https://fatchan.org/t/manage/thread/1.html#346

merge-requests/208/head
Thomas Lynch 4 years ago
parent b8ce46719a
commit 3ed44ffa2d
  1. 30
      db/posts.js
  2. 27
      models/pages/account.js
  3. 6
      views/pages/account.pug

@ -474,6 +474,36 @@ module.exports = {
},
getBoardReportCounts: (boards) => {
return db.aggregate([
{
'$match': {
'board': {
'$in': boards
},
'reports.0': {
'$exists': true
},
}
}, {
'$group': {
'_id': '$board',
'count': {
'$sum': 1
}
}
}
]).toArray();
},
getGlobalReportsCount: () => {
return db.countDocuments({
'globalreports.0': {
'$exists': true
}
})
},
getReports: (board) => {
return db.find({
'reports.0': {

@ -1,12 +1,39 @@
'use strict';
const Posts = require(__dirname+'/../../db/posts.js');
module.exports = async (req, res, next) => {
const userBoards = res.locals.user.ownedBoards.concat(res.locals.user.modBoards);
let boardReportCountMap = {};
let globalReportCount = 0;
if (userBoards.length > 0) {
let boardReportCounts;
try {
([boardReportCounts, globalReportCount] = await Promise.all([
Posts.getBoardReportCounts(userBoards),
res.locals.user.authLevel <= 1 ? Posts.getGlobalReportsCount() : 0
]));
} catch (err) {
return next(err)
}
if (boardReportCounts && boardReportCounts.length > 0) {
boardReportCountMap = boardReportCounts.reduce((acc, val) => {
acc[val._id] = val.count;
return acc;
}, boardReportCountMap);
}
}
res
.set('Cache-Control', 'private, max-age=5')
.render('account', {
csrf: req.csrfToken(),
user: res.locals.user,
boardReportCountMap,
globalReportCount,
});
}

@ -16,6 +16,8 @@ block content
a(href='/globalmanage/recent.html') Global management
| -
a(href=`/globalmanage/reports.html`) Reports
if globalReportCount > 0
b (#{globalReportCount})
| ,
a(href=`/globalmanage/bans.html`) Bans
| ,
@ -52,6 +54,8 @@ block content
a(href=`/${b}/manage/recent.html`) Recent
| ,
a(href=`/${b}/manage/reports.html`) Reports
if boardReportCountMap[b]
b (#{boardReportCountMap[b]})
| ,
a(href=`/${b}/manage/bans.html`) Bans
| ,
@ -77,6 +81,8 @@ block content
a(href=`/${b}/manage/recent.html`) Recent
| ,
a(href=`/${b}/manage/reports.html`) Reports
if boardReportCountMap[b]
b (#{boardReportCountMap[b]})
| ,
a(href=`/${b}/manage/bans.html`) Bans
| ,

Loading…
Cancel
Save