mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-11 16:35:47 +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'),
|
var async = require('async'),
|
||||||
db = require('../database'),
|
db = require('../database'),
|
||||||
|
privileges = require('../privileges'),
|
||||||
utils = require('../../public/src/utils');
|
utils = require('../../public/src/utils');
|
||||||
|
|
||||||
module.exports = function(Categories) {
|
module.exports = function(Categories) {
|
||||||
@@ -33,9 +34,13 @@ module.exports = function(Categories) {
|
|||||||
imageClass: 'auto'
|
imageClass: 'auto'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var defaultPrivileges = ['find', 'read', 'topics:create', 'topics:reply'];
|
||||||
|
|
||||||
async.series([
|
async.series([
|
||||||
async.apply(db.setObject, 'category:' + cid, category),
|
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) {
|
], function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return callback(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) {
|
function createWelcomePost(next) {
|
||||||
var db = require('./database'),
|
var db = require('./database'),
|
||||||
Topics = require('./topics');
|
Topics = require('./topics');
|
||||||
@@ -478,7 +450,6 @@ install.setup = function (callback) {
|
|||||||
enableDefaultTheme,
|
enableDefaultTheme,
|
||||||
createAdministrator,
|
createAdministrator,
|
||||||
createCategories,
|
createCategories,
|
||||||
setupPrivileges,
|
|
||||||
createWelcomePost,
|
createWelcomePost,
|
||||||
enableDefaultPlugins,
|
enableDefaultPlugins,
|
||||||
setCopyrightWidget,
|
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) {
|
privileges.categories.isAdminOrMod = function(cids, uid, callback) {
|
||||||
async.parallel({
|
async.parallel({
|
||||||
isModerators: function(next) {
|
isModerators: function(next) {
|
||||||
|
|||||||
Reference in New Issue
Block a user