From 3fb7f9fce5f70ce51fc0610999be593722662e68 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Thu, 26 Jan 2017 22:18:16 +0300 Subject: [PATCH] closes #5398 --- src/categories/create.js | 2 +- src/categories/delete.js | 2 +- src/controllers/authentication.js | 2 +- src/groups/create.js | 2 +- src/groups/delete.js | 3 +-- src/plugins/install.js | 4 ++-- src/posts.js | 4 ++-- src/socket.io/admin.js | 3 ++- src/topics/create.js | 7 +++--- src/topics/tools.js | 37 ++++++++++++------------------- src/user/create.js | 2 +- 11 files changed, 30 insertions(+), 38 deletions(-) diff --git a/src/categories/create.js b/src/categories/create.js index cebcbcd82b..ba12fc31b0 100644 --- a/src/categories/create.js +++ b/src/categories/create.js @@ -73,7 +73,7 @@ module.exports = function (Categories) { next(null, category); }, function (category, next) { - plugins.fireHook('action:category.create', category); + plugins.fireHook('action:category.create', {category: category}); next(null, category); } ], callback); diff --git a/src/categories/delete.js b/src/categories/delete.js index 06d4931132..cb0d30a09d 100644 --- a/src/categories/delete.js +++ b/src/categories/delete.js @@ -31,7 +31,7 @@ module.exports = function (Categories) { purgeCategory(cid, next); }, function (next) { - plugins.fireHook('action:category.delete', cid); + plugins.fireHook('action:category.delete', {cid: cid, uid: uid}); next(); } ], callback); diff --git a/src/controllers/authentication.js b/src/controllers/authentication.js index 90a1715cbb..4aa1b028f6 100644 --- a/src/controllers/authentication.js +++ b/src/controllers/authentication.js @@ -332,7 +332,7 @@ authenticationController.onSuccessfulLogin = function (req, uid, callback) { // Force session check for all connected socket.io clients with the same session id sockets.in('sess_' + req.sessionID).emit('checkSession', uid); - plugins.fireHook('action:user.loggedIn', uid); + plugins.fireHook('action:user.loggedIn', {uid: uid, req: req}); callback(); }); }; diff --git a/src/groups/create.js b/src/groups/create.js index a59567afe6..e4533e1ab0 100644 --- a/src/groups/create.js +++ b/src/groups/create.js @@ -70,7 +70,7 @@ module.exports = function (Groups) { async.series(tasks, next); }, function (results, next) { - plugins.fireHook('action:group.create', groupData); + plugins.fireHook('action:group.create', {group: groupData}); next(null, groupData); } ], callback); diff --git a/src/groups/delete.js b/src/groups/delete.js index 0838dd2407..3c2e02ae73 100644 --- a/src/groups/delete.js +++ b/src/groups/delete.js @@ -17,8 +17,6 @@ module.exports = function (Groups) { } var groupObj = groupsData[0]; - plugins.fireHook('action:group.destroy', groupObj); - async.parallel([ async.apply(db.delete, 'group:' + groupName), async.apply(db.sortedSetRemove, 'groups:createtime', groupName), @@ -45,6 +43,7 @@ module.exports = function (Groups) { return callback(err); } Groups.resetCache(); + plugins.fireHook('action:group.destroy', {group: groupObj}); callback(); }); }); diff --git a/src/plugins/install.js b/src/plugins/install.js index a914a09ca6..5c6e4dddac 100644 --- a/src/plugins/install.js +++ b/src/plugins/install.js @@ -50,7 +50,7 @@ module.exports = function (Plugins) { }, function (next) { meta.reloadRequired = true; - Plugins.fireHook(isActive ? 'action:plugin.deactivate' : 'action:plugin.activate', id); + Plugins.fireHook(isActive ? 'action:plugin.deactivate' : 'action:plugin.activate', {id: id}); next(); } ], function (err) { @@ -95,7 +95,7 @@ module.exports = function (Plugins) { Plugins.get(id, next); }, function (pluginData, next) { - Plugins.fireHook('action:plugin.' + type, id); + Plugins.fireHook('action:plugin.' + type, {id: id, version: version}); next(null, pluginData); } ], callback); diff --git a/src/posts.js b/src/posts.js index ed22e51ed1..b8eb93fa1a 100644 --- a/src/posts.js +++ b/src/posts.js @@ -156,7 +156,7 @@ var plugins = require('./plugins'); pid: pid }; data[field] = value; - plugins.fireHook('action:post.setFields', data); + plugins.fireHook('action:post.setFields', {data: data}); callback(); }); }; @@ -167,7 +167,7 @@ var plugins = require('./plugins'); return callback(err); } data.pid = pid; - plugins.fireHook('action:post.setFields', data); + plugins.fireHook('action:post.setFields', {data: data}); callback(); }); }; diff --git a/src/socket.io/admin.js b/src/socket.io/admin.js index b16bafa296..320832e363 100644 --- a/src/socket.io/admin.js +++ b/src/socket.io/admin.js @@ -168,10 +168,11 @@ SocketAdmin.config.setMultiple = function (socket, data, callback) { key: field, value: data[field] }; - plugins.fireHook('action:config.set', setting); + logger.monitorConfig({io: index.server}, setting); } } + plugins.fireHook('action:config.set', {settings: data}); setImmediate(next); } ], callback); diff --git a/src/topics/create.js b/src/topics/create.js index bf62266ecf..2026f006da 100644 --- a/src/topics/create.js +++ b/src/topics/create.js @@ -2,6 +2,7 @@ 'use strict'; var async = require('async'); +var _ = require('underscore'); var validator = require('validator'); var S = require('string'); var db = require('../database'); @@ -82,7 +83,7 @@ module.exports = function (Topics) { ], next); }, function (results, next) { - plugins.fireHook('action:topic.save', topicData); + plugins.fireHook('action:topic.save', {topic: _.clone(topicData)}); next(null, topicData.tid); } ], callback); @@ -174,7 +175,7 @@ module.exports = function (Topics) { data.postData.index = 0; analytics.increment(['topics', 'topics:byCid:' + data.topicData.cid]); - plugins.fireHook('action:topic.post', data.topicData); + plugins.fireHook('action:topic.post', {topic: data.topicData, post: data.postData}); if (parseInt(uid, 10)) { user.notifications.sendTopicNotificationToFollowers(uid, data.topicData, data.postData); @@ -269,7 +270,7 @@ module.exports = function (Topics) { Topics.notifyFollowers(postData, uid); analytics.increment(['posts', 'posts:byCid:' + cid]); - plugins.fireHook('action:topic.reply', postData); + plugins.fireHook('action:topic.reply', {post: _.clone(postData)}); next(null, postData); } diff --git a/src/topics/tools.js b/src/topics/tools.js index a8c00e08c0..295e2a028b 100644 --- a/src/topics/tools.js +++ b/src/topics/tools.js @@ -114,18 +114,18 @@ module.exports = function (Topics) { function toggleLock(tid, uid, lock, callback) { callback = callback || function () {}; - var cid; + var topicData; async.waterfall([ function (next) { - Topics.getTopicField(tid, 'cid', next); + Topics.getTopicFields(tid, ['tid', 'uid', 'cid'], next); }, - function (_cid, next) { - cid = _cid; - if (!cid) { + function (_topicData, next) { + topicData = _topicData; + if (!topicData || !topicData.cid) { return next(new Error('[[error:no-topic]]')); } - privileges.categories.isAdminOrMod(cid, uid, next); + privileges.categories.isAdminOrMod(topicData.cid, uid, next); }, function (isAdminOrMod, next) { if (!isAdminOrMod) { @@ -135,16 +135,11 @@ module.exports = function (Topics) { Topics.setTopicField(tid, 'locked', lock ? 1 : 0, next); }, function (next) { - var data = { - tid: tid, - isLocked: lock, - uid: uid, - cid: cid - }; + topicData.isLocked = lock; - plugins.fireHook('action:topic.lock', data); + plugins.fireHook('action:topic.lock', {topic: _.clone(topicData), uid: uid}); - next(null, data); + next(null, topicData); } ], callback); } @@ -167,7 +162,7 @@ module.exports = function (Topics) { if (!exists) { return callback(new Error('[[error:no-topic]]')); } - Topics.getTopicFields(tid, ['cid', 'lastposttime', 'postcount'], next); + Topics.getTopicFields(tid, ['uid', 'tid', 'cid', 'lastposttime', 'postcount'], next); }, function (_topicData, next) { topicData = _topicData; @@ -198,16 +193,12 @@ module.exports = function (Topics) { ], next); }, function (results, next) { - var data = { - tid: tid, - isPinned: pin, - uid: uid, - cid: topicData.cid - }; - plugins.fireHook('action:topic.pin', data); + topicData.isPinned = pin; - next(null, data); + plugins.fireHook('action:topic.pin', {topic: _.clone(topicData), uid: uid}); + + next(null, topicData); } ], callback); } diff --git a/src/user/create.js b/src/user/create.js index 67d6baf3cd..c6cd92460a 100644 --- a/src/user/create.js +++ b/src/user/create.js @@ -141,7 +141,7 @@ module.exports = function (User) { if (userNameChanged) { User.notifications.sendNameChangeNotification(userData.uid, userData.username); } - plugins.fireHook('action:user.create', userData); + plugins.fireHook('action:user.create', {user: userData}); next(null, userData.uid); } ], callback);