From 4c31535c4bbd841d9ef37cd70c3ef6b8b90bc080 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Fri, 20 Mar 2015 18:47:08 -0400 Subject: [PATCH 01/10] closes #2799 --- public/src/modules/notifications.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/src/modules/notifications.js b/public/src/modules/notifications.js index 52e4c42c8c..43ba05ed1b 100644 --- a/public/src/modules/notifications.js +++ b/public/src/modules/notifications.js @@ -48,7 +48,7 @@ define('notifications', ['sounds'], function(sound) { }); }); - notifList.on('click', '.mark-all-read', function() { + notifContainer.on('click', '.mark-all-read', function() { socket.emit('notifications.markAllRead', function(err) { if (err) { app.alertError(err.message); From 810d3be5126fd83c753841d932d3f4178d2f9057 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Fri, 20 Mar 2015 19:36:18 -0400 Subject: [PATCH 02/10] closes #2593 --- public/src/utils.js | 12 +++++ src/meta/css.js | 107 +++++++++++++++++++++++++++++++------------- src/meta/js.js | 2 +- 3 files changed, 88 insertions(+), 33 deletions(-) diff --git a/public/src/utils.js b/public/src/utils.js index 0c58817411..b48b4345ae 100644 --- a/public/src/utils.js +++ b/public/src/utils.js @@ -365,6 +365,18 @@ } return i < 0; }; + + String.prototype.endsWith = function(suffix) { + if (this.length < suffix.length) { + return false; + } + var len = this.length; + var suffixLen = suffix.length; + for (var i=1; (i <= suffixLen && this[len - i] === suffix[suffixLen - i]); ++i) { + continue; + } + return i > suffixLen; + }; } if ('undefined' !== typeof window) { diff --git a/src/meta/css.js b/src/meta/css.js index d45b61f280..a8682b1038 100644 --- a/src/meta/css.js +++ b/src/meta/css.js @@ -10,7 +10,8 @@ var winston = require('winston'), plugins = require('../plugins'), emitter = require('../emitter'), - db = require('../database'); + db = require('../database'), + utils = require('../../public/src/utils'); module.exports = function(Meta) { @@ -21,30 +22,46 @@ module.exports = function(Meta) { Meta.css.defaultBranding = {}; Meta.css.minify = function(callback) { - if (nconf.get('isPrimary') === 'true') { - winston.verbose('[meta/css] Minifying LESS/CSS'); - db.getObjectFields('config', ['theme:type', 'theme:id'], function(err, themeData) { - var themeId = (themeData['theme:id'] || 'nodebb-theme-vanilla'), - baseThemePath = path.join(nconf.get('themes_path'), (themeData['theme:type'] && themeData['theme:type'] === 'local' ? themeId : 'nodebb-theme-vanilla')), - paths = [ - baseThemePath, - path.join(__dirname, '../../node_modules'), - path.join(__dirname, '../../public/vendor/fontawesome/less'), - path.join(__dirname, '../../public/vendor/bootstrap/less') - ], - source = '@import "font-awesome";', - acpSource, - x; + callback = callback || function() {}; + if (nconf.get('isPrimary') !== 'true') { + winston.verbose('[meta/css] Cluster worker ' + process.pid + ' skipping LESS/CSS compilation'); + return callback(); + } + winston.verbose('[meta/css] Minifying LESS/CSS'); + db.getObjectFields('config', ['theme:type', 'theme:id'], function(err, themeData) { + if (err) { + return callback(err); + } - plugins.lessFiles = filterMissingFiles(plugins.lessFiles); - for(x=0; x Date: Fri, 20 Mar 2015 19:42:59 -0400 Subject: [PATCH 03/10] fix endsWith if check --- public/src/utils.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/public/src/utils.js b/public/src/utils.js index b48b4345ae..930e03501f 100644 --- a/public/src/utils.js +++ b/public/src/utils.js @@ -365,7 +365,9 @@ } return i < 0; }; + } + if (typeof String.prototype.endsWith != 'function') { String.prototype.endsWith = function(suffix) { if (this.length < suffix.length) { return false; From 4ec43f662c4459abecad8d3d1dc148dc1802c18f Mon Sep 17 00:00:00 2001 From: psychobunny Date: Sat, 21 Mar 2015 13:10:23 -0400 Subject: [PATCH 04/10] don't actually need to restart nodebb to apply skins --- public/src/admin/appearance/skins.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/public/src/admin/appearance/skins.js b/public/src/admin/appearance/skins.js index b67842b1b5..374b88a7b4 100644 --- a/public/src/admin/appearance/skins.js +++ b/public/src/admin/appearance/skins.js @@ -32,12 +32,9 @@ define('admin/appearance/skins', function() { app.alert({ alert_id: 'admin:theme', type: 'info', - title: 'Theme Changed', - message: 'Please restart your NodeBB to fully activate this theme', - timeout: 5000, - clickfn: function() { - socket.emit('admin.restart'); - } + title: 'Skin Updated', + message: themeId + ' skin was successfully applied', + timeout: 5000 }); }); } From 9754dc8be073368bec56357e169db74671efe7b0 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Sat, 21 Mar 2015 15:32:07 -0400 Subject: [PATCH 05/10] open user link in new tab --- src/views/admin/advanced/events.tpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/admin/advanced/events.tpl b/src/views/admin/advanced/events.tpl index d5942f4225..747f9e03db 100644 --- a/src/views/admin/advanced/events.tpl +++ b/src/views/admin/advanced/events.tpl @@ -10,7 +10,7 @@
#{events.eid} {events.type} - {events.user.username} (uid {events.user.uid}) (IP {events.ip}) + {events.user.username} (uid {events.user.uid}) (IP {events.ip}) {events.timestampISO}

{events.jsonString}
From 7c9e76132d3576ca59901b7f6768c8e62e383da9 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Mon, 23 Mar 2015 14:42:17 -0400 Subject: [PATCH 06/10] topic/follow component fix --- public/src/client/topic/threadTools.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/public/src/client/topic/threadTools.js b/public/src/client/topic/threadTools.js index 0d10cd844c..fe8bc1fcfb 100644 --- a/public/src/client/topic/threadTools.js +++ b/public/src/client/topic/threadTools.js @@ -60,7 +60,10 @@ define('forum/topic/threadTools', ['forum/topic/fork', 'forum/topic/move'], func fork.init(); - components.get('topic').on('click', '[component="topic/follow"]', function() { + components.get('topic').on('click', '[component="topic/follow"]', follow); + components.get('topic/follow').off('click').on('click', follow); + + function follow() { socket.emit('topics.toggleFollow', tid, function(err, state) { if(err) { return app.alert({ @@ -83,7 +86,7 @@ define('forum/topic/threadTools', ['forum/topic/fork', 'forum/topic/move'], func }); return false; - }); + } }; function topicCommand(command, tid) { From b268927cf98049cc6a0e6197d87e51981d34798c Mon Sep 17 00:00:00 2001 From: barisusakli Date: Mon, 23 Mar 2015 19:32:32 -0400 Subject: [PATCH 07/10] removedu if from filter:parse,post, parse strip teaser content --- src/postTools.js | 8 ++++---- src/posts.js | 2 +- src/posts/summary.js | 2 +- src/socket.io/posts.js | 4 ++-- src/topics/create.js | 2 +- src/topics/teaser.js | 31 +++++++++++++++++++++---------- 6 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/postTools.js b/src/postTools.js index 647d796841..cb3b1da938 100644 --- a/src/postTools.js +++ b/src/postTools.js @@ -120,7 +120,7 @@ var cache = LRU({ }, postData: function(next) { cache.del(postData.pid); - PostTools.parsePost(postData, data.uid, next); + PostTools.parsePost(postData, next); } }, function(err, results) { if (err) { @@ -176,7 +176,7 @@ var cache = LRU({ if (err) { return callback(err); } - PostTools.parsePost(postData, uid, callback); + PostTools.parsePost(postData, callback); }); } }); @@ -192,7 +192,7 @@ var cache = LRU({ }); }; - PostTools.parsePost = function(postData, uid, callback) { + PostTools.parsePost = function(postData, callback) { postData.content = postData.content || ''; var cachedContent = cache.get(postData.pid); @@ -201,7 +201,7 @@ var cache = LRU({ return callback(null, postData); } - plugins.fireHook('filter:parse.post', {postData: postData, uid: uid}, function(err, data) { + plugins.fireHook('filter:parse.post', {postData: postData}, function(err, data) { if (err) { return callback(err); } diff --git a/src/posts.js b/src/posts.js index 2c7ca82737..53931d75f7 100644 --- a/src/posts.js +++ b/src/posts.js @@ -52,7 +52,7 @@ var async = require('async'), postData.relativeTime = utils.toISOString(postData.timestamp); postData.relativeEditTime = parseInt(postData.edited, 10) !== 0 ? utils.toISOString(postData.edited) : ''; - postTools.parsePost(postData, uid, next); + postTools.parsePost(postData, next); }, function(err, posts) { if (err) { return callback(err); diff --git a/src/posts/summary.js b/src/posts/summary.js index 962a51aaa6..6d098cd829 100644 --- a/src/posts/summary.js +++ b/src/posts/summary.js @@ -86,7 +86,7 @@ module.exports = function(Posts) { return next(null, post); } - postTools.parsePost(post, uid, function(err, post) { + postTools.parsePost(post, function(err, post) { if (err) { return next(err); } diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js index b49e796e7a..94f6be7a37 100644 --- a/src/socket.io/posts.js +++ b/src/socket.io/posts.js @@ -232,7 +232,7 @@ SocketPosts.sendNotificationToPostOwner = function(pid, fromuid, notification) { async.parallel({ username: async.apply(user.getUserField, fromuid, 'username'), topicTitle: async.apply(topics.getTopicField, postData.tid, 'title'), - postObj: async.apply(postTools.parsePost, postData, postData.uid) + postObj: async.apply(postTools.parsePost, postData) }, function(err, results) { if (err) { return; @@ -479,7 +479,7 @@ SocketPosts.flag = function(socket, pid, callback) { function(topic, next) { post.topic = topic; message = '[[notifications:user_flagged_post_in, ' + userName + ', ' + topic.title + ']]'; - postTools.parsePost(post, socket.uid, next); + postTools.parsePost(post, next); }, function(post, next) { async.parallel({ diff --git a/src/topics/create.js b/src/topics/create.js index 5988f637e2..f7af1d0c5e 100644 --- a/src/topics/create.js +++ b/src/topics/create.js @@ -245,7 +245,7 @@ module.exports = function(Topics) { posts.getPidIndex(postData.pid, uid, next); }, content: function(next) { - postTools.parsePost(postData, uid, next); + postTools.parsePost(postData, next); } }, next); }, diff --git a/src/topics/teaser.js b/src/topics/teaser.js index adb4f77b5c..5946eef988 100644 --- a/src/topics/teaser.js +++ b/src/topics/teaser.js @@ -3,11 +3,13 @@ 'use strict'; var async = require('async'), + S = require('string'), db = require('../database'), user = require('../user'), posts = require('../posts'), plugins = require('../plugins'), + postTools = require('../postTools'), utils = require('../../public/src/utils'); @@ -49,21 +51,30 @@ module.exports = function(Topics) { users[user.uid] = user; }); var tidToPost = {}; - postData.forEach(function(post) { + + async.each(postData, function(post, next) { post.user = users[post.uid]; post.timestamp = utils.toISOString(post.timestamp); tidToPost[post.tid] = post; - }); - - var teasers = topics.map(function(topic, index) { - if (tidToPost[topic.tid]) { - tidToPost[topic.tid].index = counts[index]; + postTools.parsePost(post, next); + }, function(err) { + if (err) { + return callback(err); } - return tidToPost[topic.tid]; - }); + var teasers = topics.map(function(topic, index) { + if (tidToPost[topic.tid]) { + tidToPost[topic.tid].index = counts[index]; + if (tidToPost[topic.tid].content) { + var s = S(tidToPost[topic.tid].content); + tidToPost[topic.tid].content = s.stripTags.apply(s, utils.stripTags).s; + } + } + return tidToPost[topic.tid]; + }); - plugins.fireHook('filter:teasers.get', {teasers: teasers}, function(err, data) { - callback(err, data ? data.teasers : null); + plugins.fireHook('filter:teasers.get', {teasers: teasers}, function(err, data) { + callback(err, data ? data.teasers : null); + }); }); }); }); From 06d547a6cba1972595a3f58189f325c692f20e56 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 24 Mar 2015 10:51:32 -0400 Subject: [PATCH 08/10] fixed bug in privilege settings where categories near the end of a list were not having their permissions read properly if earlier categories were disabled, #2887 --- src/privileges/categories.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/privileges/categories.js b/src/privileges/categories.js index 4a623eaa27..ca7542960c 100644 --- a/src/privileges/categories.js +++ b/src/privileges/categories.js @@ -101,18 +101,19 @@ module.exports = function(privileges) { return callback(err); } - cids = cids.filter(function(cid, index) { - return !results.categories[index].disabled; + cids = cids.map(function(cid, index) { + return !results.categories[index].disabled ? cid : null; }); if (results.isAdmin) { - return callback(null, cids); + return callback(null, cids.filter(Boolean)); } - cids = cids.filter(function(cid, index) { - return results.allowedTo[index] || results.isModerators[index]; + cids = cids.map(function(cid, index) { + return (results.allowedTo[index] || results.isModerators[index]) ? cid : null; }); - callback(null, cids); + + callback(null, cids.filter(Boolean)); }); }; From fc28cbf8878d4709c6396848c3ac51c188712c95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 24 Mar 2015 10:59:21 -0400 Subject: [PATCH 09/10] filter cids with a single .filter thanks @julianlam --- src/privileges/categories.js | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/privileges/categories.js b/src/privileges/categories.js index ca7542960c..67d71d1002 100644 --- a/src/privileges/categories.js +++ b/src/privileges/categories.js @@ -101,16 +101,9 @@ module.exports = function(privileges) { return callback(err); } - cids = cids.map(function(cid, index) { - return !results.categories[index].disabled ? cid : null; - }); - - if (results.isAdmin) { - return callback(null, cids.filter(Boolean)); - } - - cids = cids.map(function(cid, index) { - return (results.allowedTo[index] || results.isModerators[index]) ? cid : null; + cids = cids.filter(function(cid, index) { + return !results.categories[index].disabled || + (results.allowedTo[index] || results.isAdmin || results.isModerators[index]); }); callback(null, cids.filter(Boolean)); From 4dbb1c08b6ac979b10b8c1bc43681e4475bc6da0 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 24 Mar 2015 11:08:02 -0400 Subject: [PATCH 10/10] added default host port and db settings for mongo, if not set in config file --- src/database/mongo.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/database/mongo.js b/src/database/mongo.js index f97eeb6651..8d18f94a80 100644 --- a/src/database/mongo.js +++ b/src/database/mongo.js @@ -59,6 +59,17 @@ usernamePassword = nconf.get('mongo:username') + ':' + nconf.get('mongo:password') + '@'; } + // Sensible defaults for Mongo, if not set + if (!nconf.get('mongo:host')) { + nconf.set('mongo:host', '127.0.0.1'); + } + if (!nconf.get('mongo:port')) { + nconf.set('mongo:port', 27017); + } + if (!nconf.get('mongo:database')) { + nconf.set('mongo:database', '0'); + } + var connString = 'mongodb://' + usernamePassword + nconf.get('mongo:host') + ':' + nconf.get('mongo:port') + '/' + nconf.get('mongo:database'); var connOptions = { server: {