diff --git a/src/socket.io/groups.js b/src/socket.io/groups.js index 5bff7ba944..ba274f32fb 100644 --- a/src/socket.io/groups.js +++ b/src/socket.io/groups.js @@ -1,6 +1,6 @@ "use strict"; -var async = require('async'); +var async = require('async'); var groups = require('../groups'); var meta = require('../meta'); @@ -77,7 +77,7 @@ function isOwner(next) { isAdmin: async.apply(user.isAdministrator, socket.uid), isOwner: async.apply(groups.ownership.isOwner, socket.uid, data.groupName) }, function (err, results) { - if (err || (!isOwner && !results.isAdmin)) { + if (err || (!results.isOwner && !results.isAdmin)) { return callback(err || new Error('[[error:no-privileges]]')); } next(socket, data, callback); diff --git a/test/groups.js b/test/groups.js index ff9ad3b013..a6dda5b887 100644 --- a/test/groups.js +++ b/test/groups.js @@ -536,17 +536,93 @@ describe('Groups', function () { }); }); - it('should accept membership of user', function (done) { - socketGroups.accept({uid: adminUid}, {groupName: 'PrivateCanJoin', toUid: testUid}, function (err) { + it('should reject membership of user', function (done) { + socketGroups.reject({uid: adminUid}, {groupName: 'PrivateCanJoin', toUid: testUid}, function (err) { assert.ifError(err); - Groups.isMember(testUid, 'PrivateCanJoin', function (err, isMember) { + Groups.isInvited(testUid, 'PrivateCanJoin', function (err, invited) { assert.ifError(err); - assert(isMember); + assert.equal(invited, false); done(); }); }); }); + it('should error if not owner or admin', function (done) { + socketGroups.accept({uid: 0}, {groupName: 'PrivateCanJoin', toUid: testUid}, function (err) { + assert.equal(err.message, '[[error:no-privileges]]'); + done(); + }); + }); + + it('should accept membership of user', function (done) { + socketGroups.join({uid: testUid}, {groupName: 'PrivateCanJoin'}, function (err) { + assert.ifError(err); + socketGroups.accept({uid: adminUid}, {groupName: 'PrivateCanJoin', toUid: testUid}, function (err) { + assert.ifError(err); + Groups.isMember(testUid, 'PrivateCanJoin', function (err, isMember) { + assert.ifError(err); + assert(isMember); + done(); + }); + }); + }); + }); + + it('should reject/accept all memberships requests', function (done) { + function requestMembership(uids, callback) { + async.series([ + function (next) { + socketGroups.join({uid: uids.uid1}, {groupName: 'PrivateCanJoin'}, next); + }, + function (next) { + socketGroups.join({uid: uids.uid2}, {groupName: 'PrivateCanJoin'}, next); + } + ], function (err) { + callback(err); + }); + } + var uids; + async.waterfall([ + function (next) { + async.parallel({ + uid1: function (next) { + User.create({username: 'groupuser1'}, next); + }, + uid2: function (next) { + User.create({username: 'groupuser2'}, next); + } + }, next); + }, + function (results, next) { + uids = results; + requestMembership(results, next); + }, + function (next) { + socketGroups.rejectAll({uid: adminUid}, {groupName: 'PrivateCanJoin'}, next); + }, + function (next) { + Groups.getPending('PrivateCanJoin', next); + }, + function (pending, next) { + assert.equal(pending.length, 0); + requestMembership(uids, next); + }, + function (next) { + socketGroups.acceptAll({uid: adminUid}, {groupName: 'PrivateCanJoin'}, next); + }, + function (next) { + Groups.isMembers([uids.uid1, uids.uid2], 'PrivateCanJoin', next); + }, + function (isMembers, next) { + assert(isMembers[0]); + assert(isMembers[1]); + next(); + } + ], function (err) { + done(err); + }); + }); + it('should grant ownership to user', function (done) { socketGroups.grant({uid: adminUid}, {groupName: 'PrivateCanJoin', toUid: testUid}, function (err) { assert.ifError(err); @@ -580,6 +656,8 @@ describe('Groups', function () { }); }); + + }); describe('admin socket methods', function () {