feat: async/await admin/controllers
parent
216eba6847
commit
72590b3462
@ -1,52 +1,31 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async');
|
const groups = require('../../groups');
|
||||||
|
const categories = require('../../categories');
|
||||||
|
const privileges = require('../../privileges');
|
||||||
|
|
||||||
var groups = require('../../groups');
|
const AdminsMods = module.exports;
|
||||||
var categories = require('../../categories');
|
|
||||||
var privileges = require('../../privileges');
|
|
||||||
|
|
||||||
var AdminsMods = module.exports;
|
AdminsMods.get = async function (req, res) {
|
||||||
|
const [admins, globalMods, categories] = await Promise.all([
|
||||||
|
groups.get('administrators', { uid: req.uid }),
|
||||||
|
groups.get('Global Moderators', { uid: req.uid }),
|
||||||
|
getModeratorsOfCategories(req.uid),
|
||||||
|
]);
|
||||||
|
|
||||||
AdminsMods.get = function (req, res, next) {
|
res.render('admin/manage/admins-mods', {
|
||||||
async.waterfall([
|
admins: admins,
|
||||||
function (next) {
|
globalMods: globalMods,
|
||||||
async.parallel({
|
categories: categories,
|
||||||
admins: function (next) {
|
allPrivileges: privileges.userPrivilegeList,
|
||||||
groups.get('administrators', { uid: req.uid }, next);
|
});
|
||||||
},
|
|
||||||
globalMods: function (next) {
|
|
||||||
groups.get('Global Moderators', { uid: req.uid }, next);
|
|
||||||
},
|
|
||||||
categories: function (next) {
|
|
||||||
getModeratorsOfCategories(req.uid, next);
|
|
||||||
},
|
|
||||||
}, next);
|
|
||||||
},
|
|
||||||
function (results) {
|
|
||||||
results.allPrivileges = privileges.userPrivilegeList;
|
|
||||||
res.render('admin/manage/admins-mods', results);
|
|
||||||
},
|
|
||||||
], next);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function getModeratorsOfCategories(uid, callback) {
|
async function getModeratorsOfCategories(uid) {
|
||||||
async.waterfall([
|
const categoryData = await categories.buildForSelect(uid, 'find');
|
||||||
function (next) {
|
const moderators = await Promise.all(categoryData.map(c => categories.getModerators(c.cid)));
|
||||||
categories.buildForSelect(uid, 'find', next);
|
categoryData.forEach((c, index) => {
|
||||||
},
|
c.moderators = moderators[index];
|
||||||
function (categoryData, next) {
|
});
|
||||||
async.map(categoryData, function (category, next) {
|
return categoryData;
|
||||||
async.waterfall([
|
|
||||||
function (next) {
|
|
||||||
categories.getModerators(category.cid, next);
|
|
||||||
},
|
|
||||||
function (moderators, next) {
|
|
||||||
category.moderators = moderators;
|
|
||||||
next(null, category);
|
|
||||||
},
|
|
||||||
], next);
|
|
||||||
}, next);
|
|
||||||
},
|
|
||||||
], callback);
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var appearanceController = module.exports;
|
const appearanceController = module.exports;
|
||||||
|
|
||||||
appearanceController.get = function (req, res) {
|
appearanceController.get = function (req, res) {
|
||||||
var term = req.params.term ? req.params.term : 'themes';
|
const term = req.params.term ? req.params.term : 'themes';
|
||||||
|
|
||||||
res.render('admin/appearance/' + term, {});
|
res.render('admin/appearance/' + term, {});
|
||||||
};
|
};
|
||||||
|
@ -1,22 +1,18 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var async = require('async');
|
const meta = require('../../meta');
|
||||||
var meta = require('../../meta');
|
const analytics = require('../../analytics');
|
||||||
var analytics = require('../../analytics');
|
|
||||||
|
|
||||||
var blacklistController = module.exports;
|
const blacklistController = module.exports;
|
||||||
|
|
||||||
blacklistController.get = function (req, res, next) {
|
blacklistController.get = async function (req, res) {
|
||||||
async.parallel({
|
const [rules, analyticsData] = await Promise.all([
|
||||||
rules: async.apply(meta.blacklist.get),
|
meta.blacklist.get(),
|
||||||
analytics: async.apply(analytics.getBlacklistAnalytics),
|
analytics.getBlacklistAnalytics(),
|
||||||
}, function (err, data) {
|
]);
|
||||||
if (err) {
|
res.render('admin/manage/ip-blacklist', {
|
||||||
return next(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
res.render('admin/manage/ip-blacklist', Object.assign(data, {
|
|
||||||
title: '[[pages:ip-blacklist]]',
|
title: '[[pages:ip-blacklist]]',
|
||||||
}));
|
rules: rules,
|
||||||
|
analytics: analyticsData,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue