add new hook to allow plugins to modify list of valid filters

v1.18.x
Julian Lam 8 years ago
parent 48cce70f78
commit 8a7950bfd5

@ -6,6 +6,7 @@ var user = require('../user');
var categories = require('../categories');
var flags = require('../flags');
var analytics = require('../analytics');
var plugins = require('../plugins');
var modsController = module.exports;
modsController.flags = {};
@ -13,6 +14,7 @@ modsController.flags = {};
modsController.flags.list = function (req, res, next) {
var filters;
var hasFilter;
var validFilters = ['assignee', 'state', 'reporterId', 'type', 'targetUid', 'cid', 'quick'];
async.waterfall([
function (next) {
async.parallel({
@ -20,6 +22,16 @@ modsController.flags.list = function (req, res, next) {
moderatedCids: async.apply(user.getModeratedCids, req.uid),
}, next);
},
function (results, next) {
plugins.fireHook('filter:flags.validateFilters', { filters: validFilters }, function (err, data) {
if (err) {
return next(err);
}
validFilters = data.filters;
next(null, results);
});
},
function (results, next) {
if (!(results.isAdminOrGlobalMod || !!results.moderatedCids.length)) {
return next(new Error('[[error:no-privileges]]'));
@ -31,8 +43,8 @@ modsController.flags.list = function (req, res, next) {
// Parse query string params for filters
hasFilter = false;
var valid = ['assignee', 'state', 'reporterId', 'type', 'targetUid', 'cid', 'quick'];
filters = valid.reduce(function (memo, cur) {
filters = validFilters.reduce(function (memo, cur) {
if (req.query.hasOwnProperty(cur)) {
memo[cur] = req.query[cur];
}

Loading…
Cancel
Save