diff --git a/src/categories.js b/src/categories.js index 217541081c..706e29448c 100644 --- a/src/categories.js +++ b/src/categories.js @@ -120,7 +120,7 @@ Categories.getCategoriesByPrivilege = function (set, uid, privilege, callback) { Categories.getModerators = function (cid, callback) { async.waterfall([ function (next) { - Groups.getMembers('cid:' + cid + ':privileges:mods', 0, -1, next); + Groups.getMembers('cid:' + cid + ':privileges:moderate', 0, -1, next); }, function (uids, next) { if (!Array.isArray(uids) || !uids.length) { diff --git a/src/flags.js b/src/flags.js index 03c810794b..f752f9d4ea 100644 --- a/src/flags.js +++ b/src/flags.js @@ -616,7 +616,7 @@ Flags.notify = function (flagObj, uid, callback) { async.waterfall([ async.apply(posts.getCidByPid, flagObj.targetId), function (cid, next) { - groups.getMembers('cid:' + cid + ':privileges:mods', 0, -1, next); + groups.getMembers('cid:' + cid + ':privileges:moderate', 0, -1, next); }, ], next); }, diff --git a/src/privileges.js b/src/privileges.js index cccbd089d6..63bae570e1 100644 --- a/src/privileges.js +++ b/src/privileges.js @@ -14,23 +14,12 @@ privileges.userPrivilegeList = [ 'upload:post:image', 'upload:post:file', 'purge', - 'mods', + 'moderate', ]; -privileges.groupPrivilegeList = [ - 'groups:find', - 'groups:read', - 'groups:topics:read', - 'groups:topics:create', - 'groups:topics:reply', - 'groups:posts:edit', - 'groups:posts:delete', - 'groups:topics:delete', - 'groups:upload:post:image', - 'groups:upload:post:file', - 'groups:purge', - 'groups:moderate', -]; +privileges.groupPrivilegeList = privileges.userPrivilegeList.map(function (privilege) { + return 'groups:' + privilege; +}); privileges.privilegeList = privileges.userPrivilegeList.concat(privileges.groupPrivilegeList); diff --git a/src/privileges/users.js b/src/privileges/users.js index 9731a9f37d..4b04b3ccd2 100644 --- a/src/privileges/users.js +++ b/src/privileges/users.js @@ -6,6 +6,7 @@ var async = require('async'); var user = require('../user'); var groups = require('../groups'); var plugins = require('../plugins'); +var helpers = require('./helpers'); module.exports = function (privileges) { privileges.users = {}; @@ -54,27 +55,13 @@ module.exports = function (privileges) { return array.indexOf(cid) === index; }); - var groupNames = uniqueCids.map(function (cid) { - return 'cid:' + cid + ':privileges:mods'; // At some point we should *probably* change this to "moderate" as well - }); - - var groupListNames = uniqueCids.map(function (cid) { - return 'cid:' + cid + ':privileges:groups:moderate'; - }); - - async.parallel({ - user: async.apply(groups.isMemberOfGroups, uid, groupNames), - group: async.apply(groups.isMemberOfGroupsList, uid, groupListNames), - }, next); + helpers.isUserAllowedTo('moderate', uid, uniqueCids, next); }, - function (checks, next) { - var isMembers = checks.user.map(function (isMember, idx) { - return isMember || checks.group[idx]; - }); + function (isAllowed, next) { var map = {}; uniqueCids.forEach(function (cid, index) { - map[cid] = isMembers[index]; + map[cid] = isAllowed[index]; }); var isModerator = cids.map(function (cid) { @@ -91,7 +78,7 @@ module.exports = function (privileges) { function (next) { async.parallel([ async.apply(privileges.users.isGlobalModerator, uids), - async.apply(groups.isMembers, uids, 'cid:' + cid + ':privileges:mods'), + async.apply(groups.isMembers, uids, 'cid:' + cid + ':privileges:moderate'), async.apply(groups.isMembersOfGroupList, uids, 'cid:' + cid + ':privileges:groups:moderate'), ], next); }, @@ -110,7 +97,7 @@ module.exports = function (privileges) { function (next) { async.parallel([ async.apply(privileges.users.isGlobalModerator, uid), - async.apply(groups.isMember, uid, 'cid:' + cid + ':privileges:mods'), + async.apply(groups.isMember, uid, 'cid:' + cid + ':privileges:moderate'), async.apply(groups.isMemberOfGroupList, uid, 'cid:' + cid + ':privileges:groups:moderate'), ], next); }, diff --git a/src/socket.io/posts/edit.js b/src/socket.io/posts/edit.js index 5ab6973ce1..513f3f55dc 100644 --- a/src/socket.io/posts/edit.js +++ b/src/socket.io/posts/edit.js @@ -64,7 +64,7 @@ module.exports = function (SocketPosts) { groups.getMembersOfGroups([ 'administrators', 'Global Moderators', - 'cid:' + result.topic.cid + ':privileges:mods', + 'cid:' + result.topic.cid + ':privileges:moderate', 'cid:' + result.topic.cid + ':privileges:groups:moderate', ], next); }, diff --git a/src/upgrades/1.5.1/rename_mods_group.js b/src/upgrades/1.5.1/rename_mods_group.js new file mode 100644 index 0000000000..516074eb57 --- /dev/null +++ b/src/upgrades/1.5.1/rename_mods_group.js @@ -0,0 +1,33 @@ +'use strict'; + +var async = require('async'); +var winston = require('winston'); + +var batch = require('../../batch'); +var groups = require('../../groups'); + + +module.exports = { + name: 'rename user mod privileges group', + timestamp: Date.UTC(2017, 4, 26), + method: function (callback) { + var progress = this.progress; + batch.processSortedSet('categories:cid', function (cids, next) { + async.eachSeries(cids, function (cid, next) { + var groupName = 'cid:' + cid + ':privileges:mods'; + var newName = 'cid:' + cid + ':privileges:moderate'; + groups.exists(groupName, function (err, exists) { + if (err || !exists) { + progress.incr(); + return next(err); + } + winston.info('renaming ' + groupName + ' to ' + newName); + progress.incr(); + groups.renameGroup(groupName, newName, next); + }); + }, next); + }, { + progress: progress, + }, callback); + }, +}; diff --git a/src/user.js b/src/user.js index d521b77f0d..6e32a973c5 100644 --- a/src/user.js +++ b/src/user.js @@ -280,7 +280,7 @@ User.getModeratorUids = function (callback) { async.apply(db.getSortedSetRange, 'categories:cid', 0, -1), function (cids, next) { var groupNames = cids.map(function (cid) { - return 'cid:' + cid + ':privileges:mods'; + return 'cid:' + cid + ':privileges:moderate'; }); groups.getMembersOfGroups(groupNames, next); diff --git a/test/controllers-admin.js b/test/controllers-admin.js index 0d2549ba0f..a10b9dc5cc 100644 --- a/test/controllers-admin.js +++ b/test/controllers-admin.js @@ -494,7 +494,7 @@ describe('Admin Controllers', function () { assert.ifError(err); moderatorJar = _jar; - groups.join('cid:' + cid + ':privileges:mods', moderatorUid, done); + groups.join('cid:' + cid + ':privileges:moderate', moderatorUid, done); }); });