mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-10 16:05:49 +01:00
on category creation give defaults privs to admins and registered users
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
var async = require('async'),
|
||||
db = require('../database'),
|
||||
privileges = require('../privileges'),
|
||||
utils = require('../../public/src/utils');
|
||||
|
||||
module.exports = function(Categories) {
|
||||
@@ -33,9 +34,13 @@ module.exports = function(Categories) {
|
||||
imageClass: 'auto'
|
||||
};
|
||||
|
||||
var defaultPrivileges = ['find', 'read', 'topics:create', 'topics:reply'];
|
||||
|
||||
async.series([
|
||||
async.apply(db.setObject, 'category:' + cid, category),
|
||||
async.apply(db.sortedSetAdd, 'categories:cid', data.order, cid)
|
||||
async.apply(db.sortedSetAdd, 'categories:cid', data.order, cid),
|
||||
async.apply(privileges.categories.give, defaultPrivileges, cid, 'administrators'),
|
||||
async.apply(privileges.categories.give, defaultPrivileges, cid, 'registered-users')
|
||||
], function(err) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
|
||||
@@ -398,34 +398,6 @@ function createCategories(next) {
|
||||
});
|
||||
}
|
||||
|
||||
function setupPrivileges(next) {
|
||||
function givePrivileges(privileges, cid, groupName, next) {
|
||||
async.each(privileges, function(privilege, next) {
|
||||
Groups.join('cid:' + cid + ':privileges:groups:' + privilege, groupName, next);
|
||||
}, next);
|
||||
}
|
||||
|
||||
var Groups = require('./groups');
|
||||
var db = require('./database');
|
||||
|
||||
db.getSortedSetRange('categories:cid', 0, -1, function(err, cids) {
|
||||
if (err) {
|
||||
return next(err);
|
||||
}
|
||||
|
||||
async.each(cids, function(cid, next) {
|
||||
async.parallel([
|
||||
function(next) {
|
||||
givePrivileges(['find', 'read', 'topics:create', 'topics:reply'], cid, 'administrators', next);
|
||||
},
|
||||
function(next) {
|
||||
givePrivileges(['find', 'read', 'topics:create', 'topics:reply'], cid, 'registered-users', next);
|
||||
}
|
||||
], next);
|
||||
}, next);
|
||||
});
|
||||
}
|
||||
|
||||
function createWelcomePost(next) {
|
||||
var db = require('./database'),
|
||||
Topics = require('./topics');
|
||||
@@ -478,7 +450,6 @@ install.setup = function (callback) {
|
||||
enableDefaultTheme,
|
||||
createAdministrator,
|
||||
createCategories,
|
||||
setupPrivileges,
|
||||
createWelcomePost,
|
||||
enableDefaultPlugins,
|
||||
setCopyrightWidget,
|
||||
|
||||
@@ -135,6 +135,12 @@ module.exports = function(privileges) {
|
||||
});
|
||||
};
|
||||
|
||||
privileges.categories.give = function(privileges, cid, groupName, callback) {
|
||||
async.each(privileges, function(privilege, next) {
|
||||
groups.join('cid:' + cid + ':privileges:groups:' + privilege, groupName, next);
|
||||
}, callback);
|
||||
};
|
||||
|
||||
privileges.categories.isAdminOrMod = function(cids, uid, callback) {
|
||||
async.parallel({
|
||||
isModerators: function(next) {
|
||||
|
||||
Reference in New Issue
Block a user