|
|
|
@ -7,61 +7,62 @@ var categories = require('../categories');
|
|
|
|
|
var flags = require('../flags');
|
|
|
|
|
var analytics = require('../analytics');
|
|
|
|
|
|
|
|
|
|
var modsController = {
|
|
|
|
|
flags: {},
|
|
|
|
|
};
|
|
|
|
|
var modsController = module.exports;
|
|
|
|
|
modsController.flags = {};
|
|
|
|
|
|
|
|
|
|
modsController.flags.list = function (req, res, next) {
|
|
|
|
|
async.parallel({
|
|
|
|
|
isAdminOrGlobalMod: async.apply(user.isAdminOrGlobalMod, req.uid),
|
|
|
|
|
moderatedCids: async.apply(user.getModeratedCids, req.uid),
|
|
|
|
|
}, function (err, results) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
} else if (!(results.isAdminOrGlobalMod || !!results.moderatedCids.length)) {
|
|
|
|
|
return next(new Error('[[error:no-privileges]]'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!results.isAdminOrGlobalMod && results.moderatedCids.length) {
|
|
|
|
|
res.locals.cids = results.moderatedCids;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Parse query string params for filters
|
|
|
|
|
var hasFilter = false;
|
|
|
|
|
var valid = ['assignee', 'state', 'reporterId', 'type', 'targetUid', 'cid', 'quick'];
|
|
|
|
|
var filters = valid.reduce(function (memo, cur) {
|
|
|
|
|
if (req.query.hasOwnProperty(cur)) {
|
|
|
|
|
memo[cur] = req.query[cur];
|
|
|
|
|
var filters;
|
|
|
|
|
var hasFilter;
|
|
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
async.parallel({
|
|
|
|
|
isAdminOrGlobalMod: async.apply(user.isAdminOrGlobalMod, req.uid),
|
|
|
|
|
moderatedCids: async.apply(user.getModeratedCids, req.uid),
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function (results, next) {
|
|
|
|
|
if (!(results.isAdminOrGlobalMod || !!results.moderatedCids.length)) {
|
|
|
|
|
return next(new Error('[[error:no-privileges]]'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return memo;
|
|
|
|
|
}, {});
|
|
|
|
|
hasFilter = !!Object.keys(filters).length;
|
|
|
|
|
|
|
|
|
|
if (res.locals.cids) {
|
|
|
|
|
if (!filters.cid) {
|
|
|
|
|
// If mod and no cid filter, add filter for their modded categories
|
|
|
|
|
filters.cid = res.locals.cids;
|
|
|
|
|
} else if (Array.isArray(filters.cid)) {
|
|
|
|
|
// Remove cids they do not moderate
|
|
|
|
|
filters.cid = filters.cid.filter(function (cid) {
|
|
|
|
|
return res.locals.cids.indexOf(String(cid)) !== -1;
|
|
|
|
|
});
|
|
|
|
|
} else if (res.locals.cids.indexOf(String(filters.cid)) === -1) {
|
|
|
|
|
filters.cid = res.locals.cids;
|
|
|
|
|
hasFilter = false;
|
|
|
|
|
if (!results.isAdminOrGlobalMod && results.moderatedCids.length) {
|
|
|
|
|
res.locals.cids = results.moderatedCids;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async.parallel({
|
|
|
|
|
flags: async.apply(flags.list, filters, req.uid),
|
|
|
|
|
analytics: async.apply(analytics.getDailyStatsForSet, 'analytics:flags', Date.now(), 30),
|
|
|
|
|
categories: async.apply(categories.buildForSelect, req.uid),
|
|
|
|
|
}, function (err, data) {
|
|
|
|
|
if (err) {
|
|
|
|
|
return next(err);
|
|
|
|
|
// Parse query string params for filters
|
|
|
|
|
hasFilter = false;
|
|
|
|
|
var valid = ['assignee', 'state', 'reporterId', 'type', 'targetUid', 'cid', 'quick'];
|
|
|
|
|
filters = valid.reduce(function (memo, cur) {
|
|
|
|
|
if (req.query.hasOwnProperty(cur)) {
|
|
|
|
|
memo[cur] = req.query[cur];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return memo;
|
|
|
|
|
}, {});
|
|
|
|
|
hasFilter = !!Object.keys(filters).length;
|
|
|
|
|
|
|
|
|
|
if (res.locals.cids) {
|
|
|
|
|
if (!filters.cid) {
|
|
|
|
|
// If mod and no cid filter, add filter for their modded categories
|
|
|
|
|
filters.cid = res.locals.cids;
|
|
|
|
|
} else if (Array.isArray(filters.cid)) {
|
|
|
|
|
// Remove cids they do not moderate
|
|
|
|
|
filters.cid = filters.cid.filter(function (cid) {
|
|
|
|
|
return res.locals.cids.indexOf(String(cid)) !== -1;
|
|
|
|
|
});
|
|
|
|
|
} else if (res.locals.cids.indexOf(String(filters.cid)) === -1) {
|
|
|
|
|
filters.cid = res.locals.cids;
|
|
|
|
|
hasFilter = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async.parallel({
|
|
|
|
|
flags: async.apply(flags.list, filters, req.uid),
|
|
|
|
|
analytics: async.apply(analytics.getDailyStatsForSet, 'analytics:flags', Date.now(), 30),
|
|
|
|
|
categories: async.apply(categories.buildForSelect, req.uid),
|
|
|
|
|
}, next);
|
|
|
|
|
},
|
|
|
|
|
function (data) {
|
|
|
|
|
// If res.locals.cids is populated, then slim down the categories list
|
|
|
|
|
if (res.locals.cids) {
|
|
|
|
|
data.categories = data.categories.filter(function (category) {
|
|
|
|
@ -92,8 +93,8 @@ modsController.flags.list = function (req, res, next) {
|
|
|
|
|
filters: filters,
|
|
|
|
|
title: '[[pages:flags]]',
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
], next);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
modsController.flags.detail = function (req, res, next) {
|
|
|
|
@ -124,5 +125,3 @@ modsController.flags.detail = function (req, res, next) {
|
|
|
|
|
}));
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = modsController;
|
|
|
|
|