mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-09-02 11:46:44 +02:00
Merge branch 'develop' into chat-rewrite
This commit is contained in:
@@ -5,6 +5,7 @@ var async = require('async');
|
||||
var messaging = require('../../messaging');
|
||||
var meta = require('../../meta');
|
||||
var user = require('../../user');
|
||||
var privileges = require('../../privileges');
|
||||
var helpers = require('../helpers');
|
||||
|
||||
var chatsController = module.exports;
|
||||
@@ -26,6 +27,13 @@ chatsController.get = function (req, res, callback) {
|
||||
if (!uid) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
privileges.global.can('chat', req.uid, next);
|
||||
},
|
||||
function (canChat, next) {
|
||||
if (!canChat) {
|
||||
return next(new Error('[[error:no-privileges]]'));
|
||||
}
|
||||
messaging.getRecentChats(req.uid, uid, 0, 19, next);
|
||||
},
|
||||
function (_recentChats, next) {
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
var adminController = {
|
||||
dashboard: require('./admin/dashboard'),
|
||||
categories: require('./admin/categories'),
|
||||
privileges: require('./admin/privileges'),
|
||||
adminsMods: require('./admin/admins-mods'),
|
||||
tags: require('./admin/tags'),
|
||||
postQueue: require('./admin/postqueue'),
|
||||
blacklist: require('./admin/blacklist'),
|
||||
|
||||
50
src/controllers/admin/admins-mods.js
Normal file
50
src/controllers/admin/admins-mods.js
Normal file
@@ -0,0 +1,50 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
|
||||
var groups = require('../../groups');
|
||||
var categories = require('../../categories');
|
||||
|
||||
var AdminsMods = module.exports;
|
||||
|
||||
AdminsMods.get = function (req, res, next) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
async.parallel({
|
||||
admins: function (next) {
|
||||
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) {
|
||||
res.render('admin/manage/admins-mods', results);
|
||||
},
|
||||
], next);
|
||||
};
|
||||
|
||||
function getModeratorsOfCategories(uid, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
categories.buildForSelect(uid, 'find', next);
|
||||
},
|
||||
function (categoryData, next) {
|
||||
async.map(categoryData, function (category, next) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
categories.getModerators(category.cid, next);
|
||||
},
|
||||
function (moderators, next) {
|
||||
category.moderators = moderators;
|
||||
next(null, category);
|
||||
},
|
||||
], next);
|
||||
}, next);
|
||||
},
|
||||
], callback);
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
var async = require('async');
|
||||
|
||||
var categories = require('../../categories');
|
||||
var privileges = require('../../privileges');
|
||||
var analytics = require('../../analytics');
|
||||
var plugins = require('../../plugins');
|
||||
var translator = require('../../translator');
|
||||
@@ -15,7 +14,6 @@ categoriesController.get = function (req, res, callback) {
|
||||
function (next) {
|
||||
async.parallel({
|
||||
category: async.apply(categories.getCategories, [req.params.category_id], req.user.uid),
|
||||
privileges: async.apply(privileges.categories.list, req.params.category_id),
|
||||
allCategories: async.apply(categories.buildForSelect, req.uid, 'read'),
|
||||
}, next);
|
||||
},
|
||||
@@ -36,7 +34,6 @@ categoriesController.get = function (req, res, callback) {
|
||||
req: req,
|
||||
res: res,
|
||||
category: category,
|
||||
privileges: data.privileges,
|
||||
allCategories: data.allCategories,
|
||||
}, next);
|
||||
},
|
||||
@@ -44,7 +41,6 @@ categoriesController.get = function (req, res, callback) {
|
||||
data.category.name = translator.escape(String(data.category.name));
|
||||
res.render('admin/manage/category', {
|
||||
category: data.category,
|
||||
privileges: data.privileges,
|
||||
allCategories: data.allCategories,
|
||||
});
|
||||
},
|
||||
|
||||
39
src/controllers/admin/privileges.js
Normal file
39
src/controllers/admin/privileges.js
Normal file
@@ -0,0 +1,39 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
|
||||
var categories = require('../../categories');
|
||||
var privileges = require('../../privileges');
|
||||
|
||||
var privilegesController = module.exports;
|
||||
|
||||
privilegesController.get = function (req, res, callback) {
|
||||
var cid = req.params.cid ? req.params.cid : 0;
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
async.parallel({
|
||||
privileges: function (next) {
|
||||
if (!cid) {
|
||||
privileges.global.list(next);
|
||||
} else {
|
||||
privileges.categories.list(cid, next);
|
||||
}
|
||||
},
|
||||
allCategories: async.apply(categories.buildForSelect, req.uid, 'read'),
|
||||
}, next);
|
||||
},
|
||||
function (data) {
|
||||
data.allCategories.forEach(function (category) {
|
||||
if (category) {
|
||||
category.selected = parseInt(category.cid, 10) === parseInt(cid, 10);
|
||||
}
|
||||
});
|
||||
|
||||
res.render('admin/manage/privileges', {
|
||||
privileges: data.privileges,
|
||||
allCategories: data.allCategories,
|
||||
cid: cid,
|
||||
});
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
@@ -1,61 +1,56 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var plugins = require('../plugins');
|
||||
var meta = require('../meta');
|
||||
var user = require('../user');
|
||||
var pubsub = require('../pubsub');
|
||||
|
||||
var adminHomePageRoute;
|
||||
var getRoute;
|
||||
|
||||
function configUpdated() {
|
||||
adminHomePageRoute = (meta.config.homePageRoute || meta.config.homePageCustom || '').replace(/^\/+/, '') || 'categories';
|
||||
getRoute = parseInt(meta.config.allowUserHomePage, 10) ? getRouteAllowUserHomePage : getRouteDisableUserHomePage;
|
||||
function adminHomePageRoute() {
|
||||
return (meta.config.homePageRoute || meta.config.homePageCustom || '').replace(/^\/+/, '') || 'categories';
|
||||
}
|
||||
|
||||
function getRouteDisableUserHomePage(uid, next) {
|
||||
next(null, adminHomePageRoute);
|
||||
function getUserHomeRoute(uid, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
user.getSettings(uid, next);
|
||||
},
|
||||
function (settings, next) {
|
||||
var route = adminHomePageRoute();
|
||||
|
||||
if (settings.homePageRoute !== 'undefined' && settings.homePageRoute !== 'none') {
|
||||
route = settings.homePageRoute || route;
|
||||
}
|
||||
|
||||
next(null, route);
|
||||
},
|
||||
], callback);
|
||||
}
|
||||
|
||||
function getRouteAllowUserHomePage(uid, next) {
|
||||
user.getSettings(uid, function (err, settings) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
var route = adminHomePageRoute;
|
||||
|
||||
if (settings.homePageRoute !== 'undefined' && settings.homePageRoute !== 'none') {
|
||||
route = settings.homePageRoute || route;
|
||||
}
|
||||
|
||||
next(null, route);
|
||||
});
|
||||
}
|
||||
|
||||
pubsub.on('config:update', configUpdated);
|
||||
configUpdated();
|
||||
|
||||
function rewrite(req, res, next) {
|
||||
if (req.path !== '/' && req.path !== '/api/' && req.path !== '/api') {
|
||||
return next();
|
||||
}
|
||||
|
||||
getRoute(req.uid, function (err, route) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
if (parseInt(meta.config.allowUserHomePage, 10)) {
|
||||
getUserHomeRoute(req.uid, next);
|
||||
} else {
|
||||
next(null, adminHomePageRoute());
|
||||
}
|
||||
},
|
||||
function (route, next) {
|
||||
var hook = 'action:homepage.get:' + route;
|
||||
|
||||
var hook = 'action:homepage.get:' + route;
|
||||
if (!plugins.hasListeners(hook)) {
|
||||
req.url = req.path + (!req.path.endsWith('/') ? '/' : '') + route;
|
||||
} else {
|
||||
res.locals.homePageRoute = route;
|
||||
}
|
||||
|
||||
if (!plugins.hasListeners(hook)) {
|
||||
req.url = req.path + (!req.path.endsWith('/') ? '/' : '') + route;
|
||||
} else {
|
||||
res.locals.homePageRoute = route;
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
next();
|
||||
},
|
||||
], next);
|
||||
}
|
||||
|
||||
exports.rewrite = rewrite;
|
||||
|
||||
@@ -37,9 +37,6 @@ uploadsController.upload = function (req, res, filesIterator) {
|
||||
|
||||
uploadsController.uploadPost = function (req, res, next) {
|
||||
uploadsController.upload(req, res, function (uploadedFile, next) {
|
||||
if (!parseInt(req.body.cid, 10)) {
|
||||
return next(new Error('[[error:category-not-selected]]'));
|
||||
}
|
||||
var isImage = uploadedFile.type.match(/image./);
|
||||
if (isImage) {
|
||||
uploadAsImage(req, uploadedFile, next);
|
||||
@@ -52,7 +49,7 @@ uploadsController.uploadPost = function (req, res, next) {
|
||||
function uploadAsImage(req, uploadedFile, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
privileges.categories.can('upload:post:image', req.body.cid, req.uid, next);
|
||||
privileges.global.can('upload:post:image', req.uid, next);
|
||||
},
|
||||
function (canUpload, next) {
|
||||
if (!canUpload) {
|
||||
@@ -82,7 +79,7 @@ function uploadAsImage(req, uploadedFile, callback) {
|
||||
function uploadAsFile(req, uploadedFile, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
privileges.categories.can('upload:post:file', req.body.cid, req.uid, next);
|
||||
privileges.global.can('upload:post:file', req.uid, next);
|
||||
},
|
||||
function (canUpload, next) {
|
||||
if (!canUpload) {
|
||||
|
||||
Reference in New Issue
Block a user