Node.js based forum software built for the modern web
upgrading privilege sets to be system groups, so they're not in the way
Julian Lam8262c38ac8d7
diff --git a/src/controllers/admin.js b/src/controllers/admin.jsindex 2725dd2c26..33e86a383a 100644--- a/src/controllers/admin.js+++ b/src/controllers/admin.js@@ -327,8 +327,8 @@ adminController.extend.rewards = function(req, res, next) {adminController.groups.get = function(req, res, next) {groups.list({expand: true,- showSystemGroups: true,- truncateUserList: true+ truncateUserList: true,+ isAdmin: true}, function(err, groups) {groups = groups.filter(function(group) {return group.name !== 'registered-users' && group.name !== 'guests';diff --git a/src/groups.js b/src/groups.jsindex 70916f4eb5..177d194fff 100644--- a/src/groups.js+++ b/src/groups.js@@ -31,7 +31,7 @@ var async = require('async'),if (!group) {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;} else if (options.removeEphemeralGroups && ephemeralGroups.indexOf(group.name) !== -1) {return false;@@ -62,15 +62,7 @@ var async = require('async'),return groups;},- applyWithName: function(method, args) {- // 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);- });- }+ isPrivilegeGroup: /^cid:\d+:privileges:[\w:]+$/};Groups.list = function(options, callback) {@@ -80,10 +72,17 @@ var async = require('async'),}groupNames = groupNames.concat(ephemeralGroups);- async.map(groupNames, function (groupName, next) {- Groups.get(groupName, options, next);- }, function (err, groups) {- callback(err, internals.filterGroups(groups, options));+ async.parallel({+ groups: async.apply(async.map, groupNames, function (groupName, next) {+ Groups.get(groupName, options, next);+ }),+ 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]]'));}- if (data.name === 'administrators' || data.name === 'registered-users') {+ if (data.name === 'administrators' || data.name === 'registered-users' || internals.isPrivilegeGroup.test(data.name)) {var system = true;}diff --git a/src/upgrade.js b/src/upgrade.jsindex 2ef1f3efd7..13484b124e 100644--- a/src/upgrade.js+++ b/src/upgrade.js@@ -21,7 +21,7 @@ var db = require('./database'),schemaDate, thisSchemaDate,// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema- latestSchema = Date.UTC(2015, 1, 24);+ latestSchema = Date.UTC(2015, 1, 24, 1);Upgrade.check = function(callback) {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');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