From 8e8058ec6ea7019970d93565a15dee93984545c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Fri, 25 May 2018 12:09:27 -0400 Subject: [PATCH] closes #6497 --- src/privileges/global.js | 2 ++ src/privileges/users.js | 17 ++++++----------- test/categories.js | 2 ++ 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/privileges/global.js b/src/privileges/global.js index 3f2955d5be..49ee66632c 100644 --- a/src/privileges/global.js +++ b/src/privileges/global.js @@ -17,6 +17,7 @@ module.exports = function (privileges) { { name: 'Upload Images' }, { name: 'Upload Files' }, { name: 'Signature' }, + { name: 'Ban' }, ]; privileges.global.userPrivilegeList = [ @@ -24,6 +25,7 @@ module.exports = function (privileges) { 'upload:post:image', 'upload:post:file', 'signature', + 'ban', ]; privileges.global.groupPrivilegeList = privileges.global.userPrivilegeList.map(function (privilege) { diff --git a/src/privileges/users.js b/src/privileges/users.js index c656ab0b8d..ca64e43946 100644 --- a/src/privileges/users.js +++ b/src/privileges/users.js @@ -4,7 +4,6 @@ var async = require('async'); var _ = require('lodash'); -var user = require('../user'); var groups = require('../groups'); var plugins = require('../plugins'); var helpers = require('./helpers'); @@ -156,11 +155,8 @@ module.exports = function (privileges) { async.waterfall([ function (next) { async.parallel({ - isAdmin: function (next) { - privileges.users.isAdministrator(callerUid, next); - }, - isGlobalMod: function (next) { - privileges.users.isGlobalModerator(callerUid, next); + canBan: function (next) { + privileges.global.can('ban', callerUid, next); }, isTargetAdmin: function (next) { privileges.users.isAdministrator(uid, next); @@ -168,7 +164,7 @@ module.exports = function (privileges) { }, next); }, function (results, next) { - results.canBan = !results.isTargetAdmin && (results.isAdmin || results.isGlobalMod); + results.canBan = !results.isTargetAdmin && results.canBan; results.callerUid = callerUid; results.uid = uid; plugins.fireHook('filter:user.canBanUser', results, next); @@ -182,13 +178,12 @@ module.exports = function (privileges) { privileges.users.hasBanPrivilege = function (uid, callback) { async.waterfall([ function (next) { - user.isAdminOrGlobalMod(uid, next); + privileges.global.can('ban', uid, next); }, - function (isAdminOrGlobalMod, next) { + function (canBan, next) { plugins.fireHook('filter:user.hasBanPrivilege', { uid: uid, - isAdminOrGlobalMod: isAdminOrGlobalMod, - canBan: isAdminOrGlobalMod, + canBan: canBan, }, next); }, function (data, next) { diff --git a/test/categories.js b/test/categories.js index d0d446942b..ba6bf248e9 100644 --- a/test/categories.js +++ b/test/categories.js @@ -665,6 +665,7 @@ describe('Categories', function () { privileges.global.userPrivileges(1, function (err, data) { assert.ifError(err); assert.deepEqual(data, { + ban: false, chat: false, 'upload:post:image': false, 'upload:post:file': false, @@ -702,6 +703,7 @@ describe('Categories', function () { privileges.global.groupPrivileges('registered-users', function (err, data) { assert.ifError(err); assert.deepEqual(data, { + 'groups:ban': false, 'groups:chat': true, 'groups:upload:post:image': true, 'groups:upload:post:file': false,