Node.js based forum software built for the modern web
added .before to socket.io/groups.js
barisusaklic4b258c7472d
diff --git a/src/socket.io/admin.js b/src/socket.io/admin.jsindex 9a247cc1b7..9f12596723 100644--- a/src/socket.io/admin.js+++ b/src/socket.io/admin.js@@ -38,7 +38,7 @@ var async = require('async'),logs: {}};-SocketAdmin.before = function(socket, method, next) {+SocketAdmin.before = function(socket, method, data, next) {if (!socket.uid) {return;}diff --git a/src/socket.io/groups.js b/src/socket.io/groups.jsindex 7ee8d59b0b..7cdb066653 100644--- a/src/socket.io/groups.js+++ b/src/socket.io/groups.js@@ -9,11 +9,15 @@ var async = require('async'),SocketGroups = {};-SocketGroups.join = function(socket, data, callback) {++SocketGroups.before = function(socket, method, data, next) {if (!data) {- return callback(new Error('[[error:invalid-data]]'));+ return next(new Error('[[error:invalid-data]]'));}+ next();+};+SocketGroups.join = function(socket, data, callback) {if (!parseInt(socket.uid, 10)) {return callback(new Error('[[error:invalid-uid]]'));}@@ -35,10 +39,6 @@ SocketGroups.join = function(socket, data, callback) {};SocketGroups.leave = function(socket, data, callback) {- if (!data) {- return callback(new Error('[[error:invalid-data]]'));- }-if (!parseInt(socket.uid, 10)) {return callback(new Error('[[error:invalid-uid]]'));}@@ -51,10 +51,6 @@ SocketGroups.leave = function(socket, data, callback) {};SocketGroups.grant = function(socket, data, callback) {- if (!data) {- return callback(new Error('[[error:invalid-data]]'));- }-groups.ownership.isOwner(socket.uid, data.groupName, function(err, isOwner) {if (!isOwner) {return callback(new Error('[[error:no-privileges]]'));@@ -65,10 +61,6 @@ SocketGroups.grant = function(socket, data, callback) {};SocketGroups.rescind = function(socket, data, callback) {- if (!data) {- return callback(new Error('[[error:invalid-data]]'));- }-groups.ownership.isOwner(socket.uid, data.groupName, function(err, isOwner) {if (!isOwner) {return callback(new Error('[[error:no-privileges]]'));@@ -79,10 +71,6 @@ SocketGroups.rescind = function(socket, data, callback) {};SocketGroups.accept = function(socket, data, callback) {- if (!data) {- return callback(new Error('[[error:invalid-data]]'));- }-groups.ownership.isOwner(socket.uid, data.groupName, function(err, isOwner) {if (!isOwner) {return callback(new Error('[[error:no-privileges]]'));@@ -93,10 +81,6 @@ SocketGroups.accept = function(socket, data, callback) {};SocketGroups.reject = function(socket, data, callback) {- if (!data) {- return callback(new Error('[[error:invalid-data]]'));- }-groups.ownership.isOwner(socket.uid, data.groupName, function(err, isOwner) {if (!isOwner) {return callback(new Error('[[error:no-privileges]]'));@@ -115,10 +99,6 @@ SocketGroups.rejectAll = function(socket, data, callback) {};function acceptRejectAll(type, socket, data, callback) {- if (!data) {- return callback(new Error('[[error:invalid-data]]'));- }-groups.ownership.isOwner(socket.uid, data.groupName, function(err, isOwner) {if (err || !isOwner) {return callback(err || new Error('[[error:no-privileges]]'));@@ -138,10 +118,6 @@ function acceptRejectAll(type, socket, data, callback) {}SocketGroups.issueInvite = function(socket, data, callback) {- if (!data) {- return callback(new Error('[[error:invalid-data]]'));- }-groups.ownership.isOwner(socket.uid, data.groupName, function(err, isOwner) {if (err || !isOwner) {return callback(err || new Error('[[error:no-privileges]]'));@@ -152,10 +128,6 @@ SocketGroups.issueInvite = function(socket, data, callback) {};SocketGroups.rescindInvite = function(socket, data, callback) {- if (!data) {- return callback(new Error('[[error:invalid-data]]'));- }-groups.ownership.isOwner(socket.uid, data.groupName, function(err, isOwner) {if (err || !isOwner) {return callback(err || new Error('[[error:no-privileges]]'));@@ -166,10 +138,6 @@ SocketGroups.rescindInvite = function(socket, data, callback) {};SocketGroups.acceptInvite = function(socket, data, callback) {- if (!data) {- return callback(new Error('[[error:invalid-data]]'));- }-groups.isInvited(socket.uid, data.groupName, function(err, invited) {if (err || !invited) {return callback(err || new Error('[[error:no-privileges]]'));@@ -180,10 +148,6 @@ SocketGroups.acceptInvite = function(socket, data, callback) {};SocketGroups.rejectInvite = function(socket, data, callback) {- if (!data) {- return callback(new Error('[[error:invalid-data]]'));- }-groups.isInvited(socket.uid, data.groupName, function(err, invited) {if (err || !invited) {return callback(err || new Error('[[error:no-privileges]]'));@@ -194,10 +158,6 @@ SocketGroups.rejectInvite = function(socket, data, callback) {};SocketGroups.update = function(socket, data, callback) {- if (!data) {- return callback(new Error('[[error:invalid-data]]'));- }-groups.ownership.isOwner(socket.uid, data.groupName, function(err, isOwner) {if (err || !isOwner) {return callback(err || new Error('[[error:no-privileges]]'));@@ -208,9 +168,7 @@ SocketGroups.update = function(socket, data, callback) {};SocketGroups.create = function(socket, data, callback) {- if (!data) {- return callback(new Error('[[error:invalid-data]]'));- } else if (socket.uid === 0) {+ if (!socket.uid) {return callback(new Error('[[error:no-privileges]]'));} else if (parseInt(meta.config.allowGroupCreation, 10) !== 1) {return callback(new Error('[[error:group-creation-disabled]]'));@@ -222,10 +180,6 @@ SocketGroups.create = function(socket, data, callback) {};SocketGroups.delete = function(socket, data, callback) {- if (!data) {- return callback(new Error('[[error:invalid-data]]'));- }-if (data.groupName === 'administrators' || data.groupName === 'registered-users') {return callback(new Error('[[error:not-allowed]]'));}@@ -248,10 +202,8 @@ SocketGroups.delete = function(socket, data, callback) {};SocketGroups.search = function(socket, data, callback) {- if (!data) {- return callback(null, []);- }data.options = data.options || {};+if (!data.query) {var groupsPerPage = 15;groupsController.getGroupsFromSet(socket.uid, data.options.sort, 0, groupsPerPage - 1, function(err, data) {@@ -264,7 +216,7 @@ SocketGroups.search = function(socket, data, callback) {};SocketGroups.loadMore = function(socket, data, callback) {- if (!data || !data.sort || !data.after) {+ if (!data.sort || !data.after) {return callback();}@@ -275,16 +227,12 @@ SocketGroups.loadMore = function(socket, data, callback) {};SocketGroups.searchMembers = function(socket, data, callback) {- if (!data) {- return callback(null, []);- }-data.uid = socket.uid;groups.searchMembers(data, callback);};SocketGroups.loadMoreMembers = function(socket, data, callback) {- if (!data || !data.groupName || !parseInt(data.after, 10)) {+ if (!data.groupName || !parseInt(data.after, 10)) {return callback(new Error('[[error:invalid-data]]'));}data.after = parseInt(data.after, 10);@@ -298,10 +246,6 @@ SocketGroups.loadMoreMembers = function(socket, data, callback) {};SocketGroups.kick = function(socket, data, callback) {- if (!data) {- return callback(new Error('[[error:invalid-data]]'));- }-groups.ownership.isOwner(socket.uid, data.groupName, function(err, isOwner) {if (!isOwner) {return callback(new Error('[[error:no-privileges]]'));@@ -318,9 +262,7 @@ SocketGroups.cover.get = function(socket, data, callback) {};SocketGroups.cover.update = function(socket, data, callback) {- if (!data) {- return callback(new Error('[[error:invalid-data]]'));- } else if (socket.uid === 0) {+ if (!socket.uid) {return callback(new Error('[[error:no-privileges]]'));}diff --git a/src/socket.io/index.js b/src/socket.io/index.jsindex 345f14dc43..055349ba77 100644--- a/src/socket.io/index.js+++ b/src/socket.io/index.js@@ -142,7 +142,10 @@ function onMessage(socket, payload) {}if (Namespaces[namespace].before) {- Namespaces[namespace].before(socket, eventName, function() {+ Namespaces[namespace].before(socket, eventName, params, function(err) {+ if (err) {+ return callback({message: err.message});+ }callMethod(methodToCall, socket, params, callback);});} else {