diff --git a/src/controllers/groups.js b/src/controllers/groups.js index 111d41a752..c77c2c61ee 100644 --- a/src/controllers/groups.js +++ b/src/controllers/groups.js @@ -133,8 +133,8 @@ groupsController.members = function(req, res, next) { groupsController.uploadCover = function(req, res, next) { var params = JSON.parse(req.body.params); - - groups.updateCover({ + + groups.updateCover(req.uid, { file: req.files.files[0].path, groupName: params.groupName }, function(err, image) { diff --git a/src/controllers/uploads.js b/src/controllers/uploads.js index 4bc4f33eb4..da87ba9316 100644 --- a/src/controllers/uploads.js +++ b/src/controllers/uploads.js @@ -91,8 +91,16 @@ uploadsController.uploadThumb = function(req, res, next) { }, next); }; -uploadsController.uploadGroupCover = function(data, next) { - uploadImage(0, data, next); +uploadsController.uploadGroupCover = function(uid, uploadedFile, callback) { + if (plugins.hasListeners('filter:uploadImage')) { + return plugins.fireHook('filter:uploadImage', {image: uploadedFile, uid: uid}, callback); + } + + if (plugins.hasListeners('filter:uploadFile')) { + return plugins.fireHook('filter:uploadFile', {file: uploadedFile, uid: uid}, callback); + } + + saveFileToLocal(uploadedFile, callback); }; function uploadImage(uid, image, callback) { @@ -132,6 +140,10 @@ function uploadFile(uid, uploadedFile, callback) { } } + saveFileToLocal(uploadedFile, callback); +} + +function saveFileToLocal(uploadedFile, callback) { var filename = uploadedFile.name || 'upload'; filename = Date.now() + '-' + validator.escape(filename).substr(0, 255); diff --git a/src/groups/update.js b/src/groups/update.js index cac4a02781..724f9f2109 100644 --- a/src/groups/update.js +++ b/src/groups/update.js @@ -118,7 +118,7 @@ module.exports = function(Groups) { Groups.setGroupField(groupName, 'cover:position', position, callback); }; - Groups.updateCover = function(data, callback) { + Groups.updateCover = function(uid, data, callback) { var tempPath, md5sum, url; // Position only? That's fine @@ -153,7 +153,7 @@ module.exports = function(Groups) { }, next); }, function(next) { - uploadsController.uploadGroupCover({ + uploadsController.uploadGroupCover(uid, { name: 'groupCover', path: data.file ? data.file : tempPath }, function(err, uploadData) { diff --git a/src/socket.io/groups.js b/src/socket.io/groups.js index 79fc935819..54b569f3fd 100644 --- a/src/socket.io/groups.js +++ b/src/socket.io/groups.js @@ -245,11 +245,11 @@ SocketGroups.cover.update = function(socket, data, callback) { } groups.ownership.isOwner(socket.uid, data.groupName, function(err, isOwner) { - if (!isOwner) { - return callback(new Error('[[error:no-privileges]]')); + if (err || !isOwner) { + return callback(err || new Error('[[error:no-privileges]]')); } - groups.updateCover(data, callback); + groups.updateCover(socket.uid, data, callback); }); }; @@ -259,8 +259,8 @@ SocketGroups.cover.remove = function(socket, data, callback) { } groups.ownership.isOwner(socket.uid, data.groupName, function(err, isOwner) { - if (!isOwner) { - return callback(new Error('[[error:no-privileges]]')); + if (err || !isOwner) { + return callback(err || new Error('[[error:no-privileges]]')); } groups.removeCover(data, callback);