mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-12 17:05:51 +01:00
upgrading privilege sets to be system groups, so they're not in the way
This commit is contained in:
@@ -327,8 +327,8 @@ adminController.extend.rewards = function(req, res, next) {
|
|||||||
adminController.groups.get = function(req, res, next) {
|
adminController.groups.get = function(req, res, next) {
|
||||||
groups.list({
|
groups.list({
|
||||||
expand: true,
|
expand: true,
|
||||||
showSystemGroups: true,
|
truncateUserList: true,
|
||||||
truncateUserList: true
|
isAdmin: true
|
||||||
}, function(err, groups) {
|
}, function(err, groups) {
|
||||||
groups = groups.filter(function(group) {
|
groups = groups.filter(function(group) {
|
||||||
return group.name !== 'registered-users' && group.name !== 'guests';
|
return group.name !== 'registered-users' && group.name !== 'guests';
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ var async = require('async'),
|
|||||||
if (!group) {
|
if (!group) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (group.deleted || (group.hidden && !group.system && !group.isMember) || (!options.showSystemGroups && group.system)) {
|
if (group.deleted || (group.hidden && !group.system && !group.isMember && !options.isAdmin) || (!options.showSystemGroups && group.system)) {
|
||||||
return false;
|
return false;
|
||||||
} else if (options.removeEphemeralGroups && ephemeralGroups.indexOf(group.name) !== -1) {
|
} else if (options.removeEphemeralGroups && ephemeralGroups.indexOf(group.name) !== -1) {
|
||||||
return false;
|
return false;
|
||||||
@@ -62,15 +62,7 @@ var async = require('async'),
|
|||||||
|
|
||||||
return groups;
|
return groups;
|
||||||
},
|
},
|
||||||
applyWithName: function(method, args) {
|
isPrivilegeGroup: /^cid:\d+:privileges:[\w:]+$/
|
||||||
// This method takes a slug and reapplies the passed-in call with the proper group name
|
|
||||||
Groups.getGroupNameByGroupSlug(args[0], function(err, groupName) { // Assuming slug is the first argument
|
|
||||||
// As there is no good way of determining whether the last argument is the callback,
|
|
||||||
// if getGroupNameByGroupSlug fails, we continue assuming the group name is the same as the slug
|
|
||||||
if (!err) { Array.prototype.splice.call(args, 0, 1, groupName); }
|
|
||||||
method.apply(Groups, args);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Groups.list = function(options, callback) {
|
Groups.list = function(options, callback) {
|
||||||
@@ -80,10 +72,17 @@ var async = require('async'),
|
|||||||
}
|
}
|
||||||
groupNames = groupNames.concat(ephemeralGroups);
|
groupNames = groupNames.concat(ephemeralGroups);
|
||||||
|
|
||||||
async.map(groupNames, function (groupName, next) {
|
async.parallel({
|
||||||
|
groups: async.apply(async.map, groupNames, function (groupName, next) {
|
||||||
Groups.get(groupName, options, next);
|
Groups.get(groupName, options, next);
|
||||||
}, function (err, groups) {
|
}),
|
||||||
callback(err, internals.filterGroups(groups, options));
|
isAdmin: function(next) {
|
||||||
|
if (!options.uid || parseInt(options.uid, 10) === 0) { return next(null, false); }
|
||||||
|
user.isAdministrator(parseInt(options.uid, 10), next);
|
||||||
|
}
|
||||||
|
}, function (err, data) {
|
||||||
|
options.isAdmin = options.isAdmin || data.isAdmin;
|
||||||
|
callback(err, internals.filterGroups(data.groups, options));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -454,7 +453,7 @@ var async = require('async'),
|
|||||||
return callback(new Error('[[error:group-name-too-short]]'));
|
return callback(new Error('[[error:group-name-too-short]]'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.name === 'administrators' || data.name === 'registered-users') {
|
if (data.name === 'administrators' || data.name === 'registered-users' || internals.isPrivilegeGroup.test(data.name)) {
|
||||||
var system = true;
|
var system = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ var db = require('./database'),
|
|||||||
schemaDate, thisSchemaDate,
|
schemaDate, thisSchemaDate,
|
||||||
|
|
||||||
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
|
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema
|
||||||
latestSchema = Date.UTC(2015, 1, 24);
|
latestSchema = Date.UTC(2015, 1, 24, 1);
|
||||||
|
|
||||||
Upgrade.check = function(callback) {
|
Upgrade.check = function(callback) {
|
||||||
db.get('schemaDate', function(err, value) {
|
db.get('schemaDate', function(err, value) {
|
||||||
@@ -914,6 +914,33 @@ Upgrade.upgrade = function(callback) {
|
|||||||
winston.info('[2015/02/24] Upgrading plugins:active to sorted set skipped');
|
winston.info('[2015/02/24] Upgrading plugins:active to sorted set skipped');
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
function(next) {
|
||||||
|
thisSchemaDate = Date.UTC(2015, 1, 24, 1);
|
||||||
|
if (schemaDate < thisSchemaDate) {
|
||||||
|
updatesMade = true;
|
||||||
|
winston.info('[2015/02/24] Upgrading privilege groups to system groups');
|
||||||
|
|
||||||
|
var isPrivilegeGroup = /^cid:\d+:privileges:[\w:]+$/;
|
||||||
|
db.getSortedSetRange('groups:createtime', 0, -1, function (err, groupNames) {
|
||||||
|
groupNames = groupNames.filter(function(name) {
|
||||||
|
return isPrivilegeGroup.test(name);
|
||||||
|
});
|
||||||
|
|
||||||
|
async.eachLimit(groupNames, 5, function(groupName, next) {
|
||||||
|
db.setObjectField('group:' + groupName, 'system', '1', next);
|
||||||
|
}, function(err) {
|
||||||
|
if (err) {
|
||||||
|
return next(err);
|
||||||
|
}
|
||||||
|
winston.info('[2015/02/24] Upgrading privilege groups to system groups done');
|
||||||
|
Upgrade.update(thisSchemaDate, next);
|
||||||
|
})
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
winston.info('[2015/02/24] Upgrading privilege groups to system groups skipped');
|
||||||
|
next();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add new schema updates here
|
// Add new schema updates here
|
||||||
|
|||||||
Reference in New Issue
Block a user