From 0c2d2a28ba8c8a678d4818d2da2595c07bca51b6 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Thu, 22 Jan 2015 16:01:17 -0500 Subject: [PATCH] admins can bypass the request step of a group and just join it, and they also become owners when they join a group --- src/groups.js | 21 +++++++++++++++++---- src/socket.io/groups.js | 10 ++++++++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/groups.js b/src/groups.js index beeddd19a9..e7c1eed77b 100644 --- a/src/groups.js +++ b/src/groups.js @@ -631,10 +631,23 @@ var async = require('async'), Groups.exists(groupName, function(err, exists) { if (exists) { - db.sortedSetAdd('group:' + groupName + ':members', Date.now(), uid, callback); - plugins.fireHook('action:group.join', { - groupName: groupName, - uid: uid + var tasks = [ + async.apply(db.sortedSetAdd, 'group:' + groupName + ':members', Date.now(), uid) + ]; + + user.isAdministrator(uid, function(err, isAdmin) { + if (isAdmin) { + tasks.push(async.apply(db.setAdd, 'group:' + groupName + ':owners', uid)); + } + + async.parallel(tasks, function(err) { + plugins.fireHook('action:group.join', { + groupName: groupName, + uid: uid + }); + + callback(); + }); }); } else { Groups.create({ diff --git a/src/socket.io/groups.js b/src/socket.io/groups.js index e51c2f6062..d85640e9fa 100644 --- a/src/socket.io/groups.js +++ b/src/socket.io/groups.js @@ -2,6 +2,9 @@ var groups = require('../groups'), meta = require('../meta'), + user = require('../user'), + + async = require('async'), SocketGroups = {}; @@ -11,8 +14,11 @@ SocketGroups.join = function(socket, data, callback) { } if (meta.config.allowPrivateGroups !== '0') { - groups.isPrivate(data.groupName, function(err, isPrivate) { - if (isPrivate) { + async.parallel({ + isAdmin: async.apply(user.isAdministrator, socket.uid), + isPrivate: async.apply(groups.isPrivate, data.groupName) + }, function(err, checks) { + if (checks.isPrivate && !checks.isAdmin) { groups.requestMembership(data.groupName, socket.uid, callback); } else { groups.join(data.groupName, socket.uid, callback);