Skip to content

Node.js based forum software built for the modern web

check group exists before joining

barisusaklica15b85db96a
diff --git a/src/socket.io/groups.js b/src/socket.io/groups.js
index 30417c5e27..b75e6ba3df 100644
--- a/src/socket.io/groups.js
+++ b/src/socket.io/groups.js
@@ -22,20 +22,30 @@ SocketGroups.join = function(socket, data, callback) {
return callback(new Error('[[error:invalid-uid]]'));
}
- if (meta.config.allowPrivateGroups !== '0') {
+ groups.exists(data.groupName, function(err, exists) {
+ if (err || !exists) {
+ return callback(err || new Error('[[error:no-group]]'));
+ }
+
+ if (parseInt(meta.config.allowPrivateGroups, 10) !== 1) {
+ return groups.join(data.groupName, socket.uid, callback);
+ }
+
async.parallel({
isAdmin: async.apply(user.isAdministrator, socket.uid),
isPrivate: async.apply(groups.isPrivate, data.groupName)
}, function(err, checks) {
+ if (err) {
+ return callback(err);
+ }
+
if (checks.isPrivate && !checks.isAdmin) {
groups.requestMembership(data.groupName, socket.uid, callback);
} else {
groups.join(data.groupName, socket.uid, callback);
}
});
- } else {
- groups.join(data.groupName, socket.uid, callback);
- }
+ });
};
SocketGroups.leave = function(socket, data, callback) {