v1.18.x
barisusakli 9 years ago
parent 32466d8bb1
commit 86d70eca74

@ -52,7 +52,7 @@ define('admin/manage/users', ['admin/modules/selectable'], function(selectable)
bootbox.confirm('Do you really want to ban?', function(confirm) { bootbox.confirm('Do you really want to ban?', function(confirm) {
if (confirm) { if (confirm) {
socket.emit('admin.user.banUsers', uids, done('User(s) banned!', '.ban', true)); socket.emit('user.banUsers', uids, done('User(s) banned!', '.ban', true));
} }
}); });
return false; return false;
@ -64,7 +64,7 @@ define('admin/manage/users', ['admin/modules/selectable'], function(selectable)
return; return;
} }
socket.emit('admin.user.unbanUsers', uids, done('User(s) unbanned!', '.ban', false)); socket.emit('user.unbanUsers', uids, done('User(s) unbanned!', '.ban', false));
return false; return false;
}); });

@ -103,7 +103,7 @@ define('forum/account/header', [
if (!confirm) { if (!confirm) {
return; return;
} }
socket.emit('admin.user.banUsers', [ajaxify.data.theirid], function(err) { socket.emit('user.banUsers', [ajaxify.data.theirid], function(err) {
if (err) { if (err) {
return app.alertError(err.message); return app.alertError(err.message);
} }
@ -115,7 +115,7 @@ define('forum/account/header', [
} }
function unbanAccount() { function unbanAccount() {
socket.emit('admin.user.unbanUsers', [ajaxify.data.theirid], function(err) { socket.emit('user.unbanUsers', [ajaxify.data.theirid], function(err) {
if (err) { if (err) {
return app.alertError(err.message); return app.alertError(err.message);
} }

@ -32,6 +32,9 @@ helpers.getUserDataByUserSlug = function(userslug, callerUID, callback) {
isAdmin : function(next) { isAdmin : function(next) {
user.isAdministrator(callerUID, next); user.isAdministrator(callerUID, next);
}, },
isGlobalModerator: function(next) {
user.isGlobalModerator(callerUID, next);
},
ips: function(next) { ips: function(next) {
user.getIPs(uid, 4, next); user.getIPs(uid, 4, next);
}, },
@ -78,6 +81,8 @@ helpers.getUserDataByUserSlug = function(userslug, callerUID, callback) {
userData.yourid = callerUID; userData.yourid = callerUID;
userData.theirid = userData.uid; userData.theirid = userData.uid;
userData.isAdmin = isAdmin; userData.isAdmin = isAdmin;
userData.isGlobalModerator = results.isGlobalModerator;
userData.canBan = isAdmin || results.isGlobalModerator;
userData.isSelf = self; userData.isSelf = self;
userData.showHidden = self || isAdmin; userData.showHidden = self || isAdmin;
userData.groups = Array.isArray(results.groups) && results.groups.length ? results.groups[0] : []; userData.groups = Array.isArray(results.groups) && results.groups.length ? results.groups[0] : [];

@ -9,7 +9,7 @@ var async = require('async'),
module.exports = function(Groups) { module.exports = function(Groups) {
Groups.create = function(data, callback) { Groups.create = function(data, callback) {
var system = data.name === 'administrators' || data.name === 'registered-users' || Groups.isPrivilegeGroup(data.name); var system = data.name === 'administrators' || data.name === 'registered-users' || data.name === 'Global Moderators' || Groups.isPrivilegeGroup(data.name);
var groupData; var groupData;
var timestamp = data.timestamp || Date.now(); var timestamp = data.timestamp || Date.now();
@ -26,6 +26,7 @@ module.exports = function(Groups) {
} }
var memberCount = data.hasOwnProperty('ownerUid') ? 1 : 0; var memberCount = data.hasOwnProperty('ownerUid') ? 1 : 0;
var isPrivate = data.hasOwnProperty('private') ? parseInt(data.private, 10) : 1;
var slug = utils.slugify(data.name); var slug = utils.slugify(data.name);
groupData = { groupData = {
name: data.name, name: data.name,
@ -34,10 +35,11 @@ module.exports = function(Groups) {
userTitle: data.name, userTitle: data.name,
description: data.description || '', description: data.description || '',
memberCount: memberCount, memberCount: memberCount,
deleted: '0', deleted: 0,
hidden: data.hidden || '0', hidden: parseInt(data.hidden, 10) === 1 ? 1 : 0,
system: system ? '1' : '0', system: system ? 1 : 0,
private: data.private || '1' private: isPrivate,
disableJoinRequests: parseInt(data.disableJoinRequests, 10) === 1 ? 1 : 0
}; };
plugins.fireHook('filter:group.create', {group: groupData, data: data}, next); plugins.fireHook('filter:group.create', {group: groupData, data: data}, next);
}, },

@ -330,6 +330,31 @@ function createAdmin(callback) {
} }
} }
function createGlobalModeratorsGroup(next) {
var groups = require('./groups');
async.waterfall([
function (next) {
groups.exists('Global Moderators', next);
},
function (exists, next) {
if (exists) {
winston.info('Global Moderators group found, skipping creation!');
return next();
}
groups.create({
name: 'Global Moderators',
description: 'Forum wide moderators',
hidden: 0,
private: 1,
disableJoinRequests: 1
}, next);
},
function (groupData, next) {
groups.show('Global Moderators', next);
}
], next);
}
function createCategories(next) { function createCategories(next) {
var Categories = require('./categories'); var Categories = require('./categories');
@ -476,6 +501,7 @@ install.setup = function (callback) {
enableDefaultTheme, enableDefaultTheme,
createCategories, createCategories,
createAdministrator, createAdministrator,
createGlobalModeratorsGroup,
createMenuItems, createMenuItems,
createWelcomePost, createWelcomePost,
enableDefaultPlugins, enableDefaultPlugins,

@ -1,16 +1,13 @@
'use strict'; 'use strict';
var async = require('async'), var async = require('async');
winston = require('winston'),
var topics = require('../topics');
db = require('../database'), var user = require('../user');
topics = require('../topics'), var helpers = require('./helpers');
user = require('../user'), var categories = require('../categories');
helpers = require('./helpers'), var plugins = require('../plugins');
groups = require('../groups'),
categories = require('../categories'),
plugins = require('../plugins');
module.exports = function(privileges) { module.exports = function(privileges) {

@ -1,16 +1,10 @@
'use strict'; 'use strict';
var async = require('async'), var async = require('async');
winston = require('winston'),
db = require('../database'), var groups = require('../groups');
topics = require('../topics'), var plugins = require('../plugins');
user = require('../user'),
helpers = require('./helpers'),
groups = require('../groups'),
categories = require('../categories'),
plugins = require('../plugins');
module.exports = function(privileges) { module.exports = function(privileges) {
@ -24,6 +18,14 @@ module.exports = function(privileges) {
} }
}; };
privileges.users.isGlobalModerator = function(uid, callback) {
if (Array.isArray(uid)) {
groups.isMembers(uid, 'Global Moderators', callback);
} else {
groups.isMember(uid, 'Global Moderators', callback);
}
};
privileges.users.isModerator = function(uid, cid, callback) { privileges.users.isModerator = function(uid, cid, callback) {
if (Array.isArray(cid)) { if (Array.isArray(cid)) {
isModeratorOfCategories(cid, uid, callback); isModeratorOfCategories(cid, uid, callback);
@ -41,14 +43,24 @@ module.exports = function(privileges) {
return filterIsModerator(cids, uid, cids.map(function() {return false;}), callback); return filterIsModerator(cids, uid, cids.map(function() {return false;}), callback);
} }
privileges.users.isGlobalModerator(uid, function(err, isGlobalModerator) {
if (err) {
return callback(err);
}
if (isGlobalModerator) {
return filterIsModerator(cids, uid, cids.map(function() {return true;}), callback);
}
var uniqueCids = cids.filter(function(cid, index, array) { var uniqueCids = cids.filter(function(cid, index, array) {
return array.indexOf(cid) === index; return array.indexOf(cid) === index;
}); });
var groupNames = uniqueCids.map(function(cid) { var groupNames = uniqueCids.map(function(cid) {
return 'cid:' + cid + ':privileges:mods'; // At some point we should *probably* change this to "moderate" as well return 'cid:' + cid + ':privileges:mods'; // At some point we should *probably* change this to "moderate" as well
}), });
groupListNames = uniqueCids.map(function(cid) {
var groupListNames = uniqueCids.map(function(cid) {
return 'cid:' + cid + ':privileges:groups:moderate'; return 'cid:' + cid + ':privileges:groups:moderate';
}); });
@ -75,10 +87,12 @@ module.exports = function(privileges) {
filterIsModerator(cids, uid, isModerator, callback); filterIsModerator(cids, uid, isModerator, callback);
}); });
});
} }
function isModeratorsOfCategory(cid, uids, callback) { function isModeratorsOfCategory(cid, uids, callback) {
async.parallel([ 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:mods'),
async.apply(groups.isMembersOfGroupList, uids, 'cid:' + cid + ':privileges:groups:moderate') async.apply(groups.isMembersOfGroupList, uids, 'cid:' + cid + ':privileges:groups:moderate')
], function(err, checks) { ], function(err, checks) {
@ -87,7 +101,7 @@ module.exports = function(privileges) {
} }
var isModerator = checks[0].map(function(isMember, idx) { var isModerator = checks[0].map(function(isMember, idx) {
return isMember || checks[1][idx]; return isMember || checks[1][idx] || checks[2][idx];
}); });
filterIsModerator(cid, uids, isModerator, callback); filterIsModerator(cid, uids, isModerator, callback);
@ -96,6 +110,7 @@ module.exports = function(privileges) {
function isModeratorOfCategory(cid, uid, callback) { function isModeratorOfCategory(cid, uid, callback) {
async.parallel([ 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:mods'),
async.apply(groups.isMemberOfGroupList, uid, 'cid:' + cid + ':privileges:groups:moderate') async.apply(groups.isMemberOfGroupList, uid, 'cid:' + cid + ':privileges:groups:moderate')
], function(err, checks) { ], function(err, checks) {
@ -103,7 +118,7 @@ module.exports = function(privileges) {
return callback(err); return callback(err);
} }
var isModerator = checks[0] || checks[1]; var isModerator = checks[0] || checks[1] || checks[2];
filterIsModerator(cid, uid, isModerator, callback); filterIsModerator(cid, uid, isModerator, callback);
}); });
} }

@ -1,15 +1,14 @@
"use strict"; "use strict";
var async = require('async'), var async = require('async');
db = require('../../database'), var db = require('../../database');
groups = require('../../groups'), var groups = require('../../groups');
user = require('../../user'), var user = require('../../user');
events = require('../../events'), var events = require('../../events');
meta = require('../../meta'), var meta = require('../../meta');
websockets = require('../index'),
User = {};
var User = {};
User.makeAdmins = function(socket, uids, callback) { User.makeAdmins = function(socket, uids, callback) {
if(!Array.isArray(uids)) { if(!Array.isArray(uids)) {
@ -60,38 +59,6 @@ User.createUser = function(socket, userData, callback) {
user.create(userData, callback); user.create(userData, callback);
}; };
User.banUsers = function(socket, uids, callback) {
toggleBan(uids, User.banUser, callback);
};
User.unbanUsers = function(socket, uids, callback) {
toggleBan(uids, user.unban, callback);
};
function toggleBan(uids, method, callback) {
if(!Array.isArray(uids)) {
return callback(new Error('[[error:invalid-data]]'));
}
async.each(uids, method, callback);
}
User.banUser = function(uid, callback) {
user.isAdministrator(uid, function(err, isAdmin) {
if (err || isAdmin) {
return callback(err || new Error('[[error:cant-ban-other-admins]]'));
}
user.ban(uid, function(err) {
if (err) {
return callback(err);
}
websockets.in('uid_' + uid).emit('event:banned');
callback();
});
});
};
User.resetLockouts = function(socket, uids, callback) { User.resetLockouts = function(socket, uids, callback) {
if (!Array.isArray(uids)) { if (!Array.isArray(uids)) {

@ -8,7 +8,6 @@ var topics = require('../topics');
var notifications = require('../notifications'); var notifications = require('../notifications');
var messaging = require('../messaging'); var messaging = require('../messaging');
var plugins = require('../plugins'); var plugins = require('../plugins');
var websockets = require('./index');
var meta = require('../meta'); var meta = require('../meta');
var events = require('../events'); var events = require('../events');
var emailer = require('../emailer'); var emailer = require('../emailer');
@ -16,11 +15,11 @@ var db = require('../database');
var SocketUser = {}; var SocketUser = {};
require('./user/profile')(SocketUser); require('./user/profile')(SocketUser);
require('./user/search')(SocketUser); require('./user/search')(SocketUser);
require('./user/status')(SocketUser); require('./user/status')(SocketUser);
require('./user/picture')(SocketUser); require('./user/picture')(SocketUser);
require('./user/ban')(SocketUser);
SocketUser.exists = function(socket, data, callback) { SocketUser.exists = function(socket, data, callback) {
if (data && data.username) { if (data && data.username) {

@ -0,0 +1,70 @@
'use strict';
var async = require('async');
var user = require('../../user');
var websockets = require('../index');
var events = require('../../events');
module.exports = function(SocketUser) {
SocketUser.banUsers = function(socket, uids, callback) {
toggleBan(socket.uid, uids, SocketUser.banUser, function(err) {
if (err) {
return callback(err);
}
async.each(uids, function(uid, next) {
events.log({
type: 'user-ban',
uid: socket.uid,
targetUid: uid,
ip: socket.ip
}, next);
}, callback);
});
};
SocketUser.unbanUsers = function(socket, uids, callback) {
toggleBan(socket.uid, uids, user.unban, callback);
};
function toggleBan(uid, uids, method, callback) {
if (!Array.isArray(uids)) {
return callback(new Error('[[error:invalid-data]]'));
}
async.waterfall([
function (next) {
async.parallel({
isAdmin: async.apply(user.isAdministrator, uid),
isGlobalMod: async.apply(user.isGlobalModerator, uid)
}, next);
},
function (results, next) {
if (!results.isAdmin && !results.isGlobalMod) {
return next(new Error('[[error:no-privileges]]'));
}
async.each(uids, method, next);
}
], callback);
}
SocketUser.banUser = function(uid, callback) {
async.waterfall([
function (next) {
user.isAdministrator(uid, next);
},
function (isAdmin, next) {
if (isAdmin) {
return next(new Error('[[error:cant-ban-other-admins]]'));
}
user.ban(uid, next);
},
function (next) {
websockets.in('uid_' + uid).emit('event:banned');
next();
}
], callback);
};
};

@ -10,7 +10,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(2016, 0, 20); latestSchema = Date.UTC(2016, 0, 23);
Upgrade.check = function(callback) { Upgrade.check = function(callback) {
db.get('schemaDate', function(err, value) { db.get('schemaDate', function(err, value) {
@ -369,6 +369,46 @@ Upgrade.upgrade = function(callback) {
winston.info('[2016/01/20] Creating users:notvalidated skipped!'); winston.info('[2016/01/20] Creating users:notvalidated skipped!');
next(); next();
} }
},
function(next) {
thisSchemaDate = Date.UTC(2016, 0, 23);
if (schemaDate < thisSchemaDate) {
updatesMade = true;
winston.info('[2016/01/23] Creating Global moderators group');
var groups = require('./groups');
async.waterfall([
function (next) {
groups.exists('Global Moderators', next);
},
function (exists, next) {
if (exists) {
return next();
}
groups.create({
name: 'Global Moderators',
description: 'Forum wide moderators',
hidden: 0,
private: 1,
disableJoinRequests: 1
}, next);
},
function (groupData, next) {
groups.show('Global Moderators', next);
}
], function(err) {
if (err) {
return next(err);
}
winston.info('[2016/01/23] Creating Global moderators group done!');
Upgrade.update(thisSchemaDate, next);
});
} else {
winston.info('[2016/01/23] Creating Global moderators group skipped!');
next();
}
} }
// Add new schema updates here // Add new schema updates here
// IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 24!!! // IMPORTANT: REMEMBER TO UPDATE VALUE OF latestSchema IN LINE 24!!!

@ -230,6 +230,10 @@ var async = require('async'),
privileges.users.isAdministrator(uid, callback); privileges.users.isAdministrator(uid, callback);
}; };
User.isGlobalModerator = function(uid, callback) {
privileges.users.isGlobalModerator(uid, callback);
};
User.isAdminOrSelf = function(callerUid, uid, callback) { User.isAdminOrSelf = function(callerUid, uid, callback) {
if (parseInt(callerUid, 10) === parseInt(uid, 10)) { if (parseInt(callerUid, 10) === parseInt(uid, 10)) {
return callback(); return callback();

Loading…
Cancel
Save