diff --git a/src/categories/create.js b/src/categories/create.js index c00f510e0e..6a5d9c075f 100644 --- a/src/categories/create.js +++ b/src/categories/create.js @@ -41,6 +41,7 @@ module.exports = function (Categories) { numRecentReplies: 1, class: (data.class ? data.class : 'col-md-3 col-xs-6'), imageClass: 'cover', + isSection: 0, }; if (data.backgroundImage) { diff --git a/src/controllers/category.js b/src/controllers/category.js index 9aec649ec3..e99c95bc5d 100644 --- a/src/controllers/category.js +++ b/src/controllers/category.js @@ -52,7 +52,7 @@ categoryController.get = function (req, res, callback) { userPrivileges = results.privileges; rssToken = results.rssToken; - if (!results.categoryData.slug || (results.categoryData && parseInt(results.categoryData.disabled, 10) === 1)) { + if (!results.categoryData.slug || (results.categoryData && results.categoryData.disabled)) { return callback(); } diff --git a/src/controllers/helpers.js b/src/controllers/helpers.js index 9f445e3aa4..f482f98b15 100644 --- a/src/controllers/helpers.js +++ b/src/controllers/helpers.js @@ -164,7 +164,7 @@ helpers.buildCategoryBreadcrumbs = function (cid, callback) { return next(err); } - if (!parseInt(data.disabled, 10) && !parseInt(data.isSection, 10)) { + if (!data.disabled && !data.isSection) { breadcrumbs.unshift({ text: validator.escape(String(data.name)), url: nconf.get('relative_path') + '/category/' + data.slug, diff --git a/src/database.js b/src/database.js index 0924fffbaf..f4b0a8b854 100644 --- a/src/database.js +++ b/src/database.js @@ -13,7 +13,7 @@ var primaryDB = require('./database/' + databaseName); primaryDB.parseIntField = function (data, field) { if (data.hasOwnProperty(field)) { - data[field] = parseInt(data[field], 10); + data[field] = parseInt(data[field], 10) || 0; } }; diff --git a/src/privileges/categories.js b/src/privileges/categories.js index 60822c4e46..860a56d8c2 100644 --- a/src/privileges/categories.js +++ b/src/privileges/categories.js @@ -108,7 +108,7 @@ module.exports = function (privileges) { categories.getCategoryField(cid, 'disabled', next); }, function (disabled, next) { - if (parseInt(disabled, 10) === 1) { + if (disabled) { return callback(null, false); } helpers.some([ diff --git a/src/privileges/topics.js b/src/privileges/topics.js index 0a5960178a..b3366e2185 100644 --- a/src/privileges/topics.js +++ b/src/privileges/topics.js @@ -15,6 +15,7 @@ module.exports = function (privileges) { privileges.topics = {}; privileges.topics.get = function (tid, uid, callback) { + uid = parseInt(uid, 10); var topic; var privs = ['topics:reply', 'topics:read', 'topics:tag', 'topics:delete', 'posts:edit', 'posts:history', 'posts:delete', 'posts:view_deleted', 'read', 'purge']; async.waterfall([ @@ -30,23 +31,20 @@ module.exports = function (privileges) { }, function (results, next) { var privData = _.zipObject(privs, results.privileges); - var disabled = parseInt(results.disabled, 10) === 1; - var locked = parseInt(topic.locked, 10) === 1; - var deleted = parseInt(topic.deleted, 10) === 1; - var isOwner = !!parseInt(uid, 10) && parseInt(uid, 10) === parseInt(topic.uid, 10); + var isOwner = uid > 0 && uid === topic.uid; var isAdminOrMod = results.isAdministrator || results.isModerator; var editable = isAdminOrMod; var deletable = isAdminOrMod || (isOwner && privData['topics:delete']); var purge = results.isAdministrator || privData.purge; plugins.fireHook('filter:privileges.topics.get', { - 'topics:reply': (privData['topics:reply'] && !locked && !deleted) || isAdminOrMod, + 'topics:reply': (privData['topics:reply'] && !topic.locked && !topic.deleted) || isAdminOrMod, 'topics:read': privData['topics:read'] || isAdminOrMod, 'topics:tag': privData['topics:tag'] || isAdminOrMod, 'topics:delete': (isOwner && privData['topics:delete']) || isAdminOrMod, - 'posts:edit': (privData['posts:edit'] && !locked) || isAdminOrMod, + 'posts:edit': (privData['posts:edit'] && !topic.locked) || isAdminOrMod, 'posts:history': privData['posts:history'] || isAdminOrMod, - 'posts:delete': (privData['posts:delete'] && !locked) || isAdminOrMod, + 'posts:delete': (privData['posts:delete'] && !topic.locked) || isAdminOrMod, 'posts:view_deleted': privData['posts:view_deleted'] || isAdminOrMod, read: privData.read || isAdminOrMod, view_thread_tools: editable || deletable, @@ -55,7 +53,7 @@ module.exports = function (privileges) { purge: purge, view_deleted: isAdminOrMod || isOwner, isAdminOrMod: isAdminOrMod, - disabled: disabled, + disabled: results.disabled, tid: tid, uid: uid, }, next); @@ -146,8 +144,8 @@ module.exports = function (privileges) { }, function (results, next) { uids = uids.filter(function (uid, index) { - return parseInt(results.disabled, 10) !== 1 && - ((results.allowedTo[index] && parseInt(topicData.deleted, 10) !== 1) || results.isAdmins[index] || results.isModerators[index]); + return !results.disabled && + ((results.allowedTo[index] && !topicData.deleted) || results.isAdmins[index] || results.isModerators[index]); }); next(null, uids); diff --git a/test/categories.js b/test/categories.js index 3f7468d24d..644c9258ee 100644 --- a/test/categories.js +++ b/test/categories.js @@ -62,6 +62,7 @@ describe('Categories', function () { assert(categoryData); assert.equal(categoryObj.name, categoryData.name); assert.equal(categoryObj.description, categoryData.description); + assert.strictEqual(categoryObj.disabled, 0); done(); });