diff --git a/public/language/en_GB/error.json b/public/language/en_GB/error.json index fed0c807c9..7e21a1290a 100644 --- a/public/language/en_GB/error.json +++ b/public/language/en_GB/error.json @@ -66,6 +66,7 @@ "group-already-exists": "Group already exists", "group-name-change-not-allowed": "Group name change not allowed", "group-already-member": "You are already part of this group", + "group-needs-owner": "This group requires at least one owner", "post-already-deleted": "This post has already been deleted", "post-already-restored": "This post has already been restored", diff --git a/public/src/client/groups/details.js b/public/src/client/groups/details.js index b667176ae9..09826fb673 100644 --- a/public/src/client/groups/details.js +++ b/public/src/client/groups/details.js @@ -34,7 +34,7 @@ define('forum/groups/details', ['iconSelect', 'vendor/colorpicker/colorpicker', if (!err) { ownerFlagEl.toggleClass('invisible'); } else { - app.alertError(err); + app.alertError(err.message); } }); break; diff --git a/src/groups.js b/src/groups.js index fbb138dce5..beeddd19a9 100644 --- a/src/groups.js +++ b/src/groups.js @@ -659,8 +659,8 @@ var async = require('async'), Groups.requestMembership = function(groupName, uid, callback) { async.parallel({ - exists: async.apply(Groups.isMember, uid, groupName), - isMember: async.apply(Groups.exists, groupName) + exists: async.apply(Groups.exists, groupName), + isMember: async.apply(Groups.isMember, uid, groupName) }, function(err, checks) { if (!checks.exists) { return callback(new Error('[[error:no-group]]')); @@ -694,7 +694,12 @@ var async = require('async'), Groups.leave = function(groupName, uid, callback) { callback = callback || function() {}; - db.sortedSetRemove('group:' + groupName + ':members', uid, function(err) { + var tasks = [ + async.apply(db.sortedSetRemove, 'group:' + groupName + ':members', uid), + async.apply(db.setRemove, 'group:' + groupName + ':owners', uid) + ]; + + async.parallel(tasks, function(err) { if (err) { return callback(err); } @@ -891,7 +896,15 @@ var async = require('async'), Groups.ownership.rescind = function(toUid, groupName, callback) { // Note: No ownership checking is done here on purpose! - db.setRemove('group:' + groupName + ':owners', toUid, callback); + + // If the owners set only contains one member, error out! + db.setCount('group:' + groupName + ':owners', function(err, numOwners) { + if (numOwners <= 1) { + return callback(new Error('[[error:group-needs-owner]]')); + } + + db.setRemove('group:' + groupName + ':owners', toUid, callback); + }); }; Groups.search = function(query, options, callback) {