Skip to content

Node.js based forum software built for the modern web

Parse int (#6853)

Barış Soner Uşaklı9c022afae1be
diff --git a/.travis.yml b/.travis.yml
index 98004ef03e..4f73cbdaf1 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,9 +7,9 @@ before_install:
before_script:
- sleep 15 # wait for mongodb to be ready
- "mongo mydb_test --eval 'db.createUser({user:\"travis\", pwd: \"test\", roles: []});'"
- - sh -c "if [ '$DB' = 'mongodb' ]; then node app --setup=\"{\\\"url\\\":\\\"http://127.0.0.1:4567\\\",\\\"secret\\\":\\\"abcdef\\\",\\\"database\\\":\\\"mongo\\\",\\\"mongo:host\\\":\\\"127.0.0.1\\\",\\\"mongo:port\\\":27017,\\\"mongo:username\\\":\\\"\\\",\\\"mongo:password\\\":\\\"\\\",\\\"mongo:database\\\":0,\\\"admin:username\\\":\\\"admin\\\",\\\"admin:email\\\":\\\"[email protected]\\\",\\\"admin:password\\\":\\\"abcdef\\\",\\\"admin:password:confirm\\\":\\\"abcdef\\\"}\" --ci=\"{\\\"host\\\":\\\"127.0.0.1\\\",\\\"port\\\":27017,\\\"database\\\":0}\"; fi"
- - sh -c "if [ '$DB' = 'redis' ]; then node app --setup=\"{\\\"url\\\":\\\"http://127.0.0.1:4567\\\",\\\"secret\\\":\\\"abcdef\\\",\\\"database\\\":\\\"redis\\\",\\\"redis:host\\\":\\\"127.0.0.1\\\",\\\"redis:port\\\":6379,\\\"redis:password\\\":\\\"\\\",\\\"redis:database\\\":0,\\\"admin:username\\\":\\\"admin\\\",\\\"admin:email\\\":\\\"[email protected]\\\",\\\"admin:password\\\":\\\"abcdef\\\",\\\"admin:password:confirm\\\":\\\"abcdef\\\"}\" --ci=\"{\\\"host\\\":\\\"127.0.0.1\\\",\\\"port\\\":6379,\\\"database\\\":0}\"; fi"
- - sh -c "if [ '$DB' = 'postgres' ]; then psql -c 'create database nodebb;' -U postgres; psql -c 'create database travis_ci_test;' -U postgres; node app --setup=\"{\\\"url\\\":\\\"http://127.0.0.1:4567\\\",\\\"secret\\\":\\\"abcdef\\\",\\\"database\\\":\\\"postgres\\\",\\\"postgres:host\\\":\\\"127.0.0.1\\\",\\\"postgres:port\\\":5432,\\\"postgres:password\\\":\\\"\\\",\\\"postgres:database\\\":\\\"nodebb\\\",\\\"admin:username\\\":\\\"admin\\\",\\\"admin:email\\\":\\\"[email protected]\\\",\\\"admin:password\\\":\\\"abcdef\\\",\\\"admin:password:confirm\\\":\\\"abcdef\\\"}\" --ci=\"{\\\"host\\\":\\\"127.0.0.1\\\",\\\"port\\\":5432,\\\"username\\\":\\\"postgres\\\",\\\"database\\\":\\\"travis_ci_test\\\"}\"; fi"
+ - sh -c "if [ '$DB' = 'mongodb' ]; then node app --setup=\"{\\\"url\\\":\\\"http://127.0.0.1:4567\\\",\\\"secret\\\":\\\"abcdef\\\",\\\"database\\\":\\\"mongo\\\",\\\"mongo:host\\\":\\\"127.0.0.1\\\",\\\"mongo:port\\\":27017,\\\"mongo:username\\\":\\\"\\\",\\\"mongo:password\\\":\\\"\\\",\\\"mongo:database\\\":0,\\\"admin:username\\\":\\\"admin\\\",\\\"admin:email\\\":\\\"[email protected]\\\",\\\"admin:password\\\":\\\"hAN3Eg8W\\\",\\\"admin:password:confirm\\\":\\\"hAN3Eg8W\\\"}\" --ci=\"{\\\"host\\\":\\\"127.0.0.1\\\",\\\"port\\\":27017,\\\"database\\\":0}\"; fi"
+ - sh -c "if [ '$DB' = 'redis' ]; then node app --setup=\"{\\\"url\\\":\\\"http://127.0.0.1:4567\\\",\\\"secret\\\":\\\"abcdef\\\",\\\"database\\\":\\\"redis\\\",\\\"redis:host\\\":\\\"127.0.0.1\\\",\\\"redis:port\\\":6379,\\\"redis:password\\\":\\\"\\\",\\\"redis:database\\\":0,\\\"admin:username\\\":\\\"admin\\\",\\\"admin:email\\\":\\\"[email protected]\\\",\\\"admin:password\\\":\\\"hAN3Eg8W\\\",\\\"admin:password:confirm\\\":\\\"hAN3Eg8W\\\"}\" --ci=\"{\\\"host\\\":\\\"127.0.0.1\\\",\\\"port\\\":6379,\\\"database\\\":0}\"; fi"
+ - sh -c "if [ '$DB' = 'postgres' ]; then psql -c 'create database nodebb;' -U postgres; psql -c 'create database travis_ci_test;' -U postgres; node app --setup=\"{\\\"url\\\":\\\"http://127.0.0.1:4567\\\",\\\"secret\\\":\\\"abcdef\\\",\\\"database\\\":\\\"postgres\\\",\\\"postgres:host\\\":\\\"127.0.0.1\\\",\\\"postgres:port\\\":5432,\\\"postgres:password\\\":\\\"\\\",\\\"postgres:database\\\":\\\"nodebb\\\",\\\"admin:username\\\":\\\"admin\\\",\\\"admin:email\\\":\\\"[email protected]\\\",\\\"admin:password\\\":\\\"hAN3Eg8W\\\",\\\"admin:password:confirm\\\":\\\"hAN3Eg8W\\\"}\" --ci=\"{\\\"host\\\":\\\"127.0.0.1\\\",\\\"port\\\":5432,\\\"username\\\":\\\"postgres\\\",\\\"database\\\":\\\"travis_ci_test\\\"}\"; fi"
after_success:
- "npm run coveralls"
language: node_js
diff --git a/install/data/defaults.json b/install/data/defaults.json
index ed0ed1e2bf..97c92bddf5 100644
--- a/install/data/defaults.json
+++ b/install/data/defaults.json
@@ -1,9 +1,21 @@
{
"title": "NodeBB",
"showSiteTitle": 1,
+ "loginDays": 14,
+ "loginSeconds": 0,
+ "loginAttempts": 5,
+ "adminReloginDuration": 60,
"postDelay": 10,
"initialPostDelay": 10,
"newbiePostDelay": 120,
+ "postEditDuration": 0,
+ "postDeleteDuration": 0,
+ "enablePostHistory": 1,
+ "postCacheSize": 5242880,
+ "disableChat": 0,
+ "chatEditDuration": 0,
+ "chatDeleteDuration": 0,
+ "chatMessageDelay": 200,
"newbiePostDelayThreshold": 3,
"minimumPostLength": 8,
"maximumPostLength": 32767,
@@ -17,26 +29,45 @@
"allowFileUploads": 0,
"allowedFileExtensions": "png,jpg,bmp",
"allowUserHomePage": 1,
+ "allowMultipleBadges": 0,
"maximumFileSize": 2048,
+ "maximumImageWidth": 760,
+ "rejectImageWidth": 5000,
+ "rejectImageHeight": 5000,
+ "resizeImageQuality": 60,
+ "topicThumbSize": 120,
"minimumTitleLength": 3,
"maximumTitleLength": 255,
"minimumUsernameLength": 2,
"maximumUsernameLength": 16,
"minimumPasswordLength": 6,
+ "minimumPasswordStrength": 1,
"maximumSignatureLength": 255,
"maximumAboutMeLength": 1000,
+ "maximumUsersInChatRoom": 0,
"maximumChatMessageLength": 1000,
"maximumProfileImageSize": 256,
"maximumCoverImageSize": 2048,
"profileImageDimension": 200,
+ "profile:convertProfileImageToPNG": 0,
+ "profile:keepAllUserImages": 0,
"requireEmailConfirmation": 0,
"allowProfileImageUploads": 1,
"teaserPost": "last-reply",
"allowPrivateGroups": 1,
+ "allowGroupCreation": 0,
"unreadCutoff": 2,
"bookmarkThreshold": 5,
"autoDetectLang": 1,
+ "reputation:disabled": 0,
+ "downvote:disabled": 0,
+ "disableSignatures": 0,
"min:rep:flag": 0,
+ "min:rep:profile-picture": 0,
+ "min:rep:cover-picture": 0,
+ "min:rep:website": 0,
+ "min:rep:aboutme": 0,
+ "min:rep:signature": 0,
"notificationType_upvote": "notification",
"notificationType_new-topic": "notification",
"notificationType_new-reply": "notification",
@@ -45,7 +76,36 @@
"notificationType_group-invite": "notification",
"notificationType_mention": "notification",
"notificationType_new-register": "notification",
- "notificationType_post-queue": "notification",
- "notificationType_new-post-flag": "notification",
- "notificationType_new-user-flag": "notification"
-}
+ "notificationType_post-queue": "notification",
+ "notificationType_new-post-flag": "notification",
+ "notificationType_new-user-flag": "notification",
+ "topicStaleDays": 60,
+ "maxTopicsPerPage": 20,
+ "maxPostsPerPage": 20,
+ "topicsPerPage": 20,
+ "postsPerPage": 20,
+ "userSearchResultsPerPage": 50,
+ "maximumGroupNameLength": 255,
+ "preventTopicDeleteAfterReplies": 0,
+ "sitemapTopics": 500,
+ "maintenanceMode": 0,
+ "votesArePublic": 0,
+ "maximumInvites": 0,
+ "username:disableEdit": 0,
+ "email:disableEdit": 0,
+ "hideFullname": 0,
+ "allowGuestHandles": 0,
+ "disableRecentCategoryFilter": 0,
+ "maximumRelatedTopics": 0,
+ "disableEmailSubscriptions": 0,
+ "emailConfirmInterval": 10,
+ "inviteExpiration": 7,
+ "digestHour": 17,
+ "passwordExpiryDays": 0,
+ "hsts-maxage": 31536000,
+ "hsts-subdomains": 0,
+ "hsts-preload": 0,
+ "hsts-enabled": 0,
+ "eventLoopLagThreshold": 100,
+ "eventLoopInterval": 500
+}
\ No newline at end of file
diff --git a/public/src/utils.js b/public/src/utils.js
index b0a6c83b58..5e75be82a8 100644
--- a/public/src/utils.js
+++ b/public/src/utils.js
@@ -399,6 +399,7 @@
},
isNumber: function (n) {
+ // `isFinite('') === true` so isNan parseFloat check is necessary
return !isNaN(parseFloat(n)) && isFinite(n);
},
diff --git a/src/categories/data.js b/src/categories/data.js
index f41fb06906..a752c16f99 100644
--- a/src/categories/data.js
+++ b/src/categories/data.js
@@ -5,7 +5,10 @@ var validator = require('validator');
var db = require('../database');
-const intFields = ['cid', 'parentCid', 'disabled', 'isSection', 'order', 'topic_count', 'post_count'];
+const intFields = [
+ 'cid', 'parentCid', 'disabled', 'isSection', 'order',
+ 'topic_count', 'post_count',
+];
module.exports = function (Categories) {
Categories.getCategoriesFields = function (cids, fields, callback) {
diff --git a/src/controllers/accounts/chats.js b/src/controllers/accounts/chats.js
index 657a6cbc5f..793b43a958 100644
--- a/src/controllers/accounts/chats.js
+++ b/src/controllers/accounts/chats.js
@@ -11,7 +11,7 @@ var helpers = require('../helpers');
var chatsController = module.exports;
chatsController.get = function (req, res, callback) {
- if (parseInt(meta.config.disableChat, 10) === 1) {
+ if (meta.config.disableChat) {
return callback();
}
diff --git a/src/controllers/accounts/edit.js b/src/controllers/accounts/edit.js
index 3b1c154d1b..7c04633416 100644
--- a/src/controllers/accounts/edit.js
+++ b/src/controllers/accounts/edit.js
@@ -31,18 +31,18 @@ editController.get = function (req, res, callback) {
if (!userData) {
return callback();
}
- userData.maximumSignatureLength = parseInt(meta.config.maximumSignatureLength, 10) || 255;
- userData.maximumAboutMeLength = parseInt(meta.config.maximumAboutMeLength, 10) || 1000;
- userData.maximumProfileImageSize = parseInt(meta.config.maximumProfileImageSize, 10);
- userData.allowProfilePicture = !userData.isSelf || parseInt(userData.reputation, 10) >= (parseInt(meta.config['min:rep:profile-picture'], 10) || 0);
- userData.allowCoverPicture = !userData.isSelf || parseInt(userData.reputation, 10) >= (parseInt(meta.config['min:rep:cover-picture'], 10) || 0);
- userData.allowProfileImageUploads = parseInt(meta.config.allowProfileImageUploads, 10) === 1;
- userData.allowMultipleBadges = parseInt(meta.config.allowMultipleBadges, 10) === 1;
- userData.allowAccountDelete = parseInt(meta.config.allowAccountDelete, 10) === 1;
- userData.allowWebsite = !userData.isSelf || parseInt(userData.reputation, 10) >= (parseInt(meta.config['min:rep:website'], 10) || 0);
- userData.allowAboutMe = !userData.isSelf || parseInt(userData.reputation, 10) >= (parseInt(meta.config['min:rep:aboutme'], 10) || 0);
- userData.allowSignature = results.canUseSignature && (!userData.isSelf || parseInt(userData.reputation, 10) >= (parseInt(meta.config['min:rep:signature'], 10) || 0));
- userData.profileImageDimension = parseInt(meta.config.profileImageDimension, 10) || 200;
+ userData.maximumSignatureLength = meta.config.maximumSignatureLength;
+ userData.maximumAboutMeLength = meta.config.maximumAboutMeLength;
+ userData.maximumProfileImageSize = meta.config.maximumProfileImageSize;
+ userData.allowProfilePicture = !userData.isSelf || userData.reputation >= meta.config['min:rep:profile-picture'];
+ userData.allowCoverPicture = !userData.isSelf || userData.reputation >= meta.config['min:rep:cover-picture'];
+ userData.allowProfileImageUploads = meta.config.allowProfileImageUploads;
+ userData.allowMultipleBadges = meta.config.allowMultipleBadges === 1;
+ userData.allowAccountDelete = meta.config.allowAccountDelete === 1;
+ userData.allowWebsite = !userData.isSelf || userData.reputation >= meta.config['min:rep:website'];
+ userData.allowAboutMe = !userData.isSelf || userData.reputation >= meta.config['min:rep:aboutme'];
+ userData.allowSignature = results.canUseSignature && (!userData.isSelf || userData.reputation >= meta.config['min:rep:signature']);
+ userData.profileImageDimension = meta.config.profileImageDimension || 200;
userData.defaultAvatar = user.getDefaultAvatar();
userData.groups = userData.groups.filter(function (group) {
@@ -103,8 +103,8 @@ function renderRoute(name, req, res, next) {
}
if (name === 'password') {
- userData.minimumPasswordLength = parseInt(meta.config.minimumPasswordLength, 10);
- userData.minimumPasswordStrength = parseInt(meta.config.minimumPasswordStrength || 1, 10);
+ userData.minimumPasswordLength = meta.config.minimumPasswordLength;
+ userData.minimumPasswordStrength = meta.config.minimumPasswordStrength;
}
userData.title = '[[pages:account/edit/' + name + ', ' + userData.username + ']]';
diff --git a/src/controllers/accounts/helpers.js b/src/controllers/accounts/helpers.js
index 4cab153dd7..c25fe5e925 100644
--- a/src/controllers/accounts/helpers.js
+++ b/src/controllers/accounts/helpers.js
@@ -125,13 +125,13 @@ helpers.getUserDataByUserSlug = function (userslug, callerUID, callback) {
userData.emailClass = 'hide';
- if (!isAdmin && !isGlobalModerator && !isSelf && (!userSettings.showemail || parseInt(meta.config.hideEmail, 10) === 1)) {
+ if (!isAdmin && !isGlobalModerator && !isSelf && (!userSettings.showemail || meta.config.hideEmail)) {
userData.email = '';
} else if (!userSettings.showemail) {
userData.emailClass = '';
}
- if (!isAdmin && !isGlobalModerator && !isSelf && (!userSettings.showfullname || parseInt(meta.config.hideFullname, 10) === 1)) {
+ if (!isAdmin && !isGlobalModerator && !isSelf && (!userSettings.showfullname || meta.config.hideFullname)) {
userData.fullname = '';
}
@@ -159,15 +159,15 @@ helpers.getUserDataByUserSlug = function (userslug, callerUID, callback) {
userData.isSelfOrAdminOrGlobalModerator = isSelf || isAdmin || isGlobalModerator;
userData.canEdit = results.canEdit;
userData.canBan = results.canBanUser;
- userData.canChangePassword = isAdmin || (isSelf && parseInt(meta.config['password:disableEdit'], 10) !== 1);
+ userData.canChangePassword = isAdmin || (isSelf && !meta.config['password:disableEdit']);
userData.isSelf = isSelf;
userData.isFollowing = results.isFollowing;
userData.showHidden = isSelf || isAdmin || (isGlobalModerator && !results.isTargetAdmin);
userData.groups = Array.isArray(results.groups) && results.groups.length ? results.groups[0] : [];
- userData.disableSignatures = meta.config.disableSignatures !== undefined && parseInt(meta.config.disableSignatures, 10) === 1;
- userData['reputation:disabled'] = parseInt(meta.config['reputation:disabled'], 10) === 1;
- userData['downvote:disabled'] = parseInt(meta.config['downvote:disabled'], 10) === 1;
- userData['email:confirmed'] = !!parseInt(userData['email:confirmed'], 10);
+ userData.disableSignatures = meta.config.disableSignatures === 1;
+ userData['reputation:disabled'] = meta.config['reputation:disabled'] === 1;
+ userData['downvote:disabled'] = meta.config['downvote:disabled'] === 1;
+ userData['email:confirmed'] = !!userData['email:confirmed'];
userData.profile_links = filterLinks(results.profile_menu.links, {
self: isSelf,
other: !isSelf,
@@ -200,8 +200,8 @@ helpers.getUserDataByUserSlug = function (userslug, callerUID, callback) {
}
userData['cover:position'] = validator.escape(String(userData['cover:position'] || '50% 50%'));
- userData['username:disableEdit'] = !userData.isAdmin && parseInt(meta.config['username:disableEdit'], 10) === 1;
- userData['email:disableEdit'] = !userData.isAdmin && parseInt(meta.config['email:disableEdit'], 10) === 1;
+ userData['username:disableEdit'] = !userData.isAdmin && meta.config['username:disableEdit'];
+ userData['email:disableEdit'] = !userData.isAdmin && meta.config['email:disableEdit'];
next(null, userData);
},
diff --git a/src/controllers/accounts/profile.js b/src/controllers/accounts/profile.js
index 14f04b6d45..b6b5c54284 100644
--- a/src/controllers/accounts/profile.js
+++ b/src/controllers/accounts/profile.js
@@ -43,7 +43,7 @@ profileController.get = function (req, res, callback) {
req.session.uids_viewed = req.session.uids_viewed || {};
- if (req.uid !== parseInt(userData.uid, 10) && (!req.session.uids_viewed[userData.uid] || req.session.uids_viewed[userData.uid] < Date.now() - 3600000)) {
+ if (req.uid !== userData.uid && (!req.session.uids_viewed[userData.uid] || req.session.uids_viewed[userData.uid] < Date.now() - 3600000)) {
user.incrementUserFieldBy(userData.uid, 'profileviews', 1);
req.session.uids_viewed[userData.uid] = Date.now();
}
@@ -68,23 +68,21 @@ profileController.get = function (req, res, callback) {
}, next);
},
function (results, next) {
- if (parseInt(meta.config['reputation:disabled'], 10) === 1) {
+ if (meta.config['reputation:disabled']) {
delete userData.reputation;
}
- userData.posts = results.posts.posts.filter(function (p) {
- return p && parseInt(p.deleted, 10) !== 1;
- });
+ userData.posts = results.posts.posts.filter(p => p && !p.deleted);
userData.hasPrivateChat = results.hasPrivateChat;
userData.aboutme = translator.escape(results.aboutme);
userData.nextStart = results.posts.nextStart;
userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username }]);
userData.title = userData.username;
- userData.allowCoverPicture = !userData.isSelf || parseInt(userData.reputation, 10) >= (parseInt(meta.config['min:rep:cover-picture'], 10) || 0);
+ userData.allowCoverPicture = !userData.isSelf || userData.reputation >= (meta.config['min:rep:cover-picture'] || 0);
var pageCount = Math.ceil(userData.postcount / itemsPerPage);
userData.pagination = pagination.create(page, pageCount, req.query);
- if (!parseInt(userData.profileviews, 10)) {
+ if (!userData.profileviews) {
userData.profileviews = 1;
}
diff --git a/src/controllers/accounts/settings.js b/src/controllers/accounts/settings.js
index 0beab3f77a..02253c3f23 100644
--- a/src/controllers/accounts/settings.js
+++ b/src/controllers/accounts/settings.js
@@ -102,7 +102,7 @@ settingsController.get = function (req, res, callback) {
function (results) {
userData.homePageRoutes = results.routes;
userData.notificationSettings = results.notificationSettings;
- userData.disableEmailSubscriptions = parseInt(meta.config.disableEmailSubscriptions, 10) === 1;
+ userData.disableEmailSubscriptions = meta.config.disableEmailSubscriptions;
userData.dailyDigestFreqOptions = [
{ value: 'off', name: '[[user:digest_off]]', selected: userData.settings.dailyDigestFreq === 'off' },
@@ -162,17 +162,17 @@ settingsController.get = function (req, res, callback) {
};
});
- userData.disableCustomUserSkins = parseInt(meta.config.disableCustomUserSkins, 10) === 1;
+ userData.disableCustomUserSkins = meta.config.disableCustomUserSkins;
- userData.allowUserHomePage = parseInt(meta.config.allowUserHomePage, 10) === 1;
+ userData.allowUserHomePage = meta.config.allowUserHomePage;
- userData.hideFullname = parseInt(meta.config.hideFullname, 10) === 1;
- userData.hideEmail = parseInt(meta.config.hideEmail, 10) === 1;
+ userData.hideFullname = meta.config.hideFullname;
+ userData.hideEmail = meta.config.hideEmail;
userData.inTopicSearchAvailable = plugins.hasListeners('filter:topic.search');
- userData.maxTopicsPerPage = parseInt(meta.config.maxTopicsPerPage, 10) || 20;
- userData.maxPostsPerPage = parseInt(meta.config.maxPostsPerPage, 10) || 20;
+ userData.maxTopicsPerPage = meta.config.maxTopicsPerPage;
+ userData.maxPostsPerPage = meta.config.maxPostsPerPage;
userData.title = '[[pages:account/settings]]';
userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username, url: '/user/' + userData.userslug }, { text: '[[user:settings]]' }]);
diff --git a/src/controllers/accounts/uploads.js b/src/controllers/accounts/uploads.js
index 21a5287550..899ed866b5 100644
--- a/src/controllers/accounts/uploads.js
+++ b/src/controllers/accounts/uploads.js
@@ -48,7 +48,7 @@ uploadsController.get = function (req, res, callback) {
});
var pageCount = Math.ceil(results.itemCount / itemsPerPage);
userData.pagination = pagination.create(page, pageCount, req.query);
- userData.privateUploads = parseInt(meta.config.privateUploads, 10) === 1;
+ userData.privateUploads = meta.config.privateUploads === 1;
userData.title = '[[pages:account/uploads, ' + userData.username + ']]';
userData.breadcrumbs = helpers.buildBreadcrumbs([{ text: userData.username, url: '/user/' + userData.userslug }, { text: '[[global:uploads]]' }]);
res.render('account/uploads', userData);
diff --git a/src/controllers/admin/groups.js b/src/controllers/admin/groups.js
index a8a4f269b7..ab452c6eb3 100644
--- a/src/controllers/admin/groups.js
+++ b/src/controllers/admin/groups.js
@@ -68,7 +68,7 @@ groupsController.get = function (req, res, callback) {
res.render('admin/manage/group', {
group: result.group,
groupNames: result.groupNames,
- allowPrivateGroups: parseInt(meta.config.allowPrivateGroups, 10) === 1,
+ allowPrivateGroups: meta.config.allowPrivateGroups,
});
},
], callback);
diff --git a/src/controllers/admin/languages.js b/src/controllers/admin/languages.js
index 987c1d70cc..d51bad3e47 100644
--- a/src/controllers/admin/languages.js
+++ b/src/controllers/admin/languages.js
@@ -19,7 +19,7 @@ languagesController.get = function (req, res, next) {
res.render('admin/general/languages', {
languages: languages,
- autoDetectLang: parseInt(meta.config.autoDetectLang, 10) === 1,
+ autoDetectLang: meta.config.autoDetectLang,
});
},
], next);
diff --git a/src/controllers/admin/users.js b/src/controllers/admin/users.js
index f33435c325..c31de51453 100644
--- a/src/controllers/admin/users.js
+++ b/src/controllers/admin/users.js
@@ -173,7 +173,7 @@ function getUsers(set, section, min, max, req, res, next) {
function render(req, res, data) {
data.search_display = 'hidden';
data.pagination = pagination.create(data.page, data.pageCount, req.query);
- data.requireEmailConfirmation = parseInt(meta.config.requireEmailConfirmation, 10) === 1;
+ data.requireEmailConfirmation = meta.config.requireEmailConfirmation;
var registrationType = meta.config.registrationType;
diff --git a/src/controllers/api.js b/src/controllers/api.js
index c4987e7ab5..65140b70fe 100644
--- a/src/controllers/api.js
+++ b/src/controllers/api.js
@@ -22,23 +22,23 @@ apiController.loadConfig = function (req, callback) {
config.siteTitle = validator.escape(String(meta.config.title || meta.config.browserTitle || 'NodeBB'));
config.browserTitle = validator.escape(String(meta.config.browserTitle || meta.config.title || 'NodeBB'));
config.titleLayout = (meta.config.titleLayout || '{pageTitle} | {browserTitle}').replace(/{/g, '&#123;').replace(/}/g, '&#125;');
- config.showSiteTitle = parseInt(meta.config.showSiteTitle, 10) === 1;
+ config.showSiteTitle = meta.config.showSiteTitle === 1;
config.minimumTitleLength = meta.config.minimumTitleLength;
config.maximumTitleLength = meta.config.maximumTitleLength;
config.minimumPostLength = meta.config.minimumPostLength;
config.maximumPostLength = meta.config.maximumPostLength;
- config.minimumTagsPerTopic = parseInt(meta.config.minimumTagsPerTopic || 0, 10);
- config.maximumTagsPerTopic = parseInt(meta.config.maximumTagsPerTopic || 5, 10);
+ config.minimumTagsPerTopic = meta.config.minimumTagsPerTopic || 0;
+ config.maximumTagsPerTopic = meta.config.maximumTagsPerTopic || 5;
config.minimumTagLength = meta.config.minimumTagLength || 3;
config.maximumTagLength = meta.config.maximumTagLength || 15;
- config.useOutgoingLinksPage = parseInt(meta.config.useOutgoingLinksPage, 10) === 1;
- config.allowGuestHandles = parseInt(meta.config.allowGuestHandles, 10) === 1;
- config.allowFileUploads = parseInt(meta.config.allowFileUploads, 10) === 1;
- config.allowTopicsThumbnail = parseInt(meta.config.allowTopicsThumbnail, 10) === 1;
- config.usePagination = parseInt(meta.config.usePagination, 10) === 1;
- config.disableChat = parseInt(meta.config.disableChat, 10) === 1;
- config.disableChatMessageEditing = parseInt(meta.config.disableChatMessageEditing, 10) === 1;
- config.maximumChatMessageLength = parseInt(meta.config.maximumChatMessageLength, 10) || 1000;
+ config.useOutgoingLinksPage = meta.config.useOutgoingLinksPage === 1;
+ config.allowGuestHandles = meta.config.allowGuestHandles === 1;
+ config.allowFileUploads = meta.config.allowFileUploads === 1;
+ config.allowTopicsThumbnail = meta.config.allowTopicsThumbnail === 1;
+ config.usePagination = meta.config.usePagination === 1;
+ config.disableChat = meta.config.disableChat === 1;
+ config.disableChatMessageEditing = meta.config.disableChatMessageEditing === 1;
+ config.maximumChatMessageLength = meta.config.maximumChatMessageLength || 1000;
config.socketioTransports = nconf.get('socket.io:transports') || ['polling', 'websocket'];
config.websocketAddress = nconf.get('socket.io:address') || '';
config.maxReconnectionAttempts = meta.config.maxReconnectionAttempts || 5;
@@ -53,15 +53,15 @@ apiController.loadConfig = function (req, callback) {
config.loggedIn = !!req.user;
config.uid = req.uid;
config['cache-buster'] = meta.config['cache-buster'] || '';
- config.requireEmailConfirmation = parseInt(meta.config.requireEmailConfirmation, 10) === 1;
+ config.requireEmailConfirmation = meta.config.requireEmailConfirmation === 1;
config.topicPostSort = meta.config.topicPostSort || 'oldest_to_newest';
config.categoryTopicSort = meta.config.categoryTopicSort || 'newest_to_oldest';
config.csrf_token = req.csrfToken && req.csrfToken();
config.searchEnabled = plugins.hasListeners('filter:search.query');
config.bootswatchSkin = meta.config.bootswatchSkin || 'noskin';
config.defaultBootswatchSkin = meta.config.bootswatchSkin || 'noskin';
- config.enablePostHistory = parseInt(meta.config.enablePostHistory || 1, 10) === 1;
- config.notificationAlertTimeout = parseInt(meta.config.notificationAlertTimeout, 10) || 5000;
+ config.enablePostHistory = (meta.config.enablePostHistory || 1) === 1;
+ config.notificationAlertTimeout = meta.config.notificationAlertTimeout || 5000;
if (config.useOutgoingLinksPage) {
config.outgoingLinksWhitelist = meta.config['outgoingLinks:whitelist'];
@@ -71,7 +71,7 @@ apiController.loadConfig = function (req, callback) {
config.timeagoCutoff = timeagoCutoff !== '' ? Math.max(0, parseInt(timeagoCutoff, 10)) : timeagoCutoff;
config.cookies = {
- enabled: parseInt(meta.config.cookieConsentEnabled, 10) === 1,
+ enabled: meta.config.cookieConsentEnabled === 1,
message: translator.escape(validator.escape(meta.config.cookieConsentMessage || '[[global:cookies.message]]')).replace(/\\/g, '\\\\'),
dismiss: translator.escape(validator.escape(meta.config.cookieConsentDismiss || '[[global:cookies.accept]]')).replace(/\\/g, '\\\\'),
link: translator.escape(validator.escape(meta.config.cookieConsentLink || '[[global:cookies.learn_more]]')).replace(/\\/g, '\\\\'),
@@ -95,7 +95,7 @@ apiController.loadConfig = function (req, callback) {
config.categoryTopicSort = settings.categoryTopicSort || config.categoryTopicSort;
config.topicSearchEnabled = settings.topicSearchEnabled || false;
config.delayImageLoading = settings.delayImageLoading !== undefined ? settings.delayImageLoading : true;
- config.bootswatchSkin = (parseInt(meta.config.disableCustomUserSkins, 10) !== 1 && settings.bootswatchSkin && settings.bootswatchSkin !== 'default') ? settings.bootswatchSkin : config.bootswatchSkin;
+ config.bootswatchSkin = (meta.config.disableCustomUserSkins !== 1 && settings.bootswatchSkin && settings.bootswatchSkin !== 'default') ? settings.bootswatchSkin : config.bootswatchSkin;
plugins.fireHook('filter:config.get', config, next);
},
], callback);
diff --git a/src/controllers/authentication.js b/src/controllers/authentication.js
index 3dae021976..5bdb9fbc57 100644
--- a/src/controllers/authentication.js
+++ b/src/controllers/authentication.js
@@ -256,7 +256,7 @@ function continueLogin(req, res, next) {
// Alter user cookie depending on passed-in option
if (req.body.remember === 'on') {
- var duration = 1000 * 60 * 60 * 24 * (parseInt(meta.config.loginDays, 10) || 14);
+ var duration = 1000 * 60 * 60 * 24 * meta.config.loginDays;
req.session.cookie.maxAge = duration;
req.session.cookie.expires = new Date(Date.now() + duration);
} else {
diff --git a/src/controllers/category.js b/src/controllers/category.js
index e99c95bc5d..2bd1806b8c 100644
--- a/src/controllers/category.js
+++ b/src/controllers/category.js
@@ -135,8 +135,8 @@ categoryController.get = function (req, res, callback) {
addTags(categoryData, res);
- categoryData['feeds:disableRSS'] = parseInt(meta.config['feeds:disableRSS'], 10) === 1;
- categoryData['reputation:disabled'] = parseInt(meta.config['reputation:disabled'], 10) === 1;
+ categoryData['feeds:disableRSS'] = meta.config['feeds:disableRSS'];
+ categoryData['reputation:disabled'] = meta.config['reputation:disabled'];
categoryData.title = translator.escape(categoryData.name);
pageCount = Math.max(1, Math.ceil(categoryData.topic_count / settings.topicsPerPage));
categoryData.pagination = pagination.create(currentPage, pageCount, req.query);
diff --git a/src/controllers/groups.js b/src/controllers/groups.js
index 6063653fc0..96e6c0bbbb 100644
--- a/src/controllers/groups.js
+++ b/src/controllers/groups.js
@@ -39,7 +39,7 @@ groupsController.getGroupsFromSet = function (uid, sort, start, stop, callback)
function (groupsData, next) {
next(null, {
groups: groupsData,
- allowGroupCreation: parseInt(meta.config.allowGroupCreation, 10) === 1,
+ allowGroupCreation: meta.config.allowGroupCreation,
nextStart: stop + 1,
});
},
@@ -106,7 +106,7 @@ groupsController.details = function (req, res, callback) {
results.group.isOwner = results.group.isOwner || results.isAdmin || (results.isGlobalMod && !results.group.system);
results.title = '[[pages:group, ' + results.group.displayName + ']]';
results.breadcrumbs = helpers.buildBreadcrumbs([{ text: '[[pages:groups]]', url: '/groups' }, { text: results.group.displayName }]);
- results.allowPrivateGroups = parseInt(meta.config.allowPrivateGroups, 10) === 1;
+ results.allowPrivateGroups = meta.config.allowPrivateGroups;
res.render('groups/details', results);
},
diff --git a/src/controllers/home.js b/src/controllers/home.js
index 49cee7e192..a97b391052 100644
--- a/src/controllers/home.js
+++ b/src/controllers/home.js
@@ -35,7 +35,7 @@ function rewrite(req, res, next) {
async.waterfall([
function (next) {
- if (parseInt(meta.config.allowUserHomePage, 10)) {
+ if (meta.config.allowUserHomePage) {
getUserHomeRoute(req.uid, next);
} else {
next(null, adminHomePageRoute());
diff --git a/src/controllers/index.js b/src/controllers/index.js
index a183692d4e..89cfb2e06e 100644
--- a/src/controllers/index.js
+++ b/src/controllers/index.js
@@ -45,8 +45,8 @@ Controllers.reset = function (req, res, next) {
valid: valid,
displayExpiryNotice: req.session.passwordExpired,
code: code,
- minimumPasswordLength: parseInt(meta.config.minimumPasswordLength, 10),
- minimumPasswordStrength: parseInt(meta.config.minimumPasswordStrength, 10),
+ minimumPasswordLength: meta.config.minimumPasswordLength,
+ minimumPasswordStrength: meta.config.minimumPasswordStrength,
breadcrumbs: helpers.buildBreadcrumbs([
{
text: '[[reset_password:reset_password]]',
@@ -180,10 +180,10 @@ Controllers.register = function (req, res, next) {
data.authentication = loginStrategies;
- data.minimumUsernameLength = parseInt(meta.config.minimumUsernameLength, 10);
- data.maximumUsernameLength = parseInt(meta.config.maximumUsernameLength, 10);
- data.minimumPasswordLength = parseInt(meta.config.minimumPasswordLength, 10);
- data.minimumPasswordStrength = parseInt(meta.config.minimumPasswordStrength || 1, 10);
+ data.minimumUsernameLength = meta.config.minimumUsernameLength;
+ data.maximumUsernameLength = meta.config.maximumUsernameLength;
+ data.minimumPasswordLength = meta.config.minimumPasswordLength;
+ data.minimumPasswordStrength = meta.config.minimumPasswordStrength;
data.termsOfUse = termsOfUse.postData.content;
data.breadcrumbs = helpers.buildBreadcrumbs([{
text: '[[register:register]]',
diff --git a/src/controllers/recent.js b/src/controllers/recent.js
index 334d709784..727746a567 100644
--- a/src/controllers/recent.js
+++ b/src/controllers/recent.js
@@ -79,7 +79,7 @@ recentController.getData = function (req, url, sort, callback) {
data.selectedCategory = categoryData.selectedCategory;
data.selectedCids = categoryData.selectedCids;
data.nextStart = stop + 1;
- data['feeds:disableRSS'] = parseInt(meta.config['feeds:disableRSS'], 10) === 1;
+ data['feeds:disableRSS'] = meta.config['feeds:disableRSS'];
data.rssFeedUrl = nconf.get('relative_path') + '/' + url + '.rss';
if (req.loggedIn) {
data.rssFeedUrl += '?uid=' + req.uid + '&token=' + rssToken;
diff --git a/src/controllers/sitemap.js b/src/controllers/sitemap.js
index 846c6facb2..224a6dbcc3 100644
--- a/src/controllers/sitemap.js
+++ b/src/controllers/sitemap.js
@@ -37,7 +37,7 @@ sitemapController.getTopicPage = function (req, res, next) {
};
function sendSitemap(method, res, callback) {
- if (parseInt(meta.config['feeds:disableSitemap'], 10) === 1) {
+ if (meta.config['feeds:disableSitemap']) {
return callback();
}
async.waterfall([
diff --git a/src/controllers/topics.js b/src/controllers/topics.js
index e1796c13f9..a5fc105131 100644
--- a/src/controllers/topics.js
+++ b/src/controllers/topics.js
@@ -138,15 +138,15 @@ topicsController.get = function (req, res, callback) {
},
function (topicData) {
topicData.privileges = userPrivileges;
- topicData.topicStaleDays = parseInt(meta.config.topicStaleDays, 10) || 60;
- topicData['reputation:disabled'] = parseInt(meta.config['reputation:disabled'], 10) === 1;
- topicData['downvote:disabled'] = parseInt(meta.config['downvote:disabled'], 10) === 1;
- topicData['feeds:disableRSS'] = parseInt(meta.config['feeds:disableRSS'], 10) === 1;
- topicData.bookmarkThreshold = parseInt(meta.config.bookmarkThreshold, 10) || 5;
- topicData.postEditDuration = parseInt(meta.config.postEditDuration, 10) || 0;
- topicData.postDeleteDuration = parseInt(meta.config.postDeleteDuration, 10) || 0;
+ topicData.topicStaleDays = meta.config.topicStaleDays;
+ topicData['reputation:disabled'] = meta.config['reputation:disabled'];
+ topicData['downvote:disabled'] = meta.config['downvote:disabled'];
+ topicData['feeds:disableRSS'] = meta.config['feeds:disableRSS'];
+ topicData.bookmarkThreshold = meta.config.bookmarkThreshold;
+ topicData.postEditDuration = meta.config.postEditDuration;
+ topicData.postDeleteDuration = meta.config.postDeleteDuration;
topicData.scrollToMyPost = settings.scrollToMyPost;
- topicData.allowMultipleBadges = parseInt(meta.config.allowMultipleBadges, 10) === 1;
+ topicData.allowMultipleBadges = meta.config.allowMultipleBadges === 1;
topicData.rssFeedUrl = nconf.get('relative_path') + '/topic/' + topicData.tid + '.rss';
if (req.loggedIn) {
topicData.rssFeedUrl += '?uid=' + req.uid + '&token=' + rssToken;
diff --git a/src/controllers/uploads.js b/src/controllers/uploads.js
index 4ab683f45d..f4313fed0a 100644
--- a/src/controllers/uploads.js
+++ b/src/controllers/uploads.js
@@ -71,7 +71,7 @@ function uploadAsImage(req, uploadedFile, callback) {
uploadsController.uploadFile(req.uid, uploadedFile, next);
},
function (fileObj, next) {
- if (parseInt(meta.config.maximumImageWidth, 10) === 0) {
+ if (meta.config.maximumImageWidth === 0) {
return next(null, fileObj);
}
@@ -92,7 +92,7 @@ function uploadAsFile(req, uploadedFile, callback) {
if (!canUpload) {
return next(new Error('[[error:no-privileges]]'));
}
- if (parseInt(meta.config.allowFileUploads, 10) !== 1) {
+ if (!meta.config.allowFileUploads) {
return next(new Error('[[error:uploads-are-disabled]]'));
}
uploadsController.uploadFile(req.uid, uploadedFile, next);
@@ -112,15 +112,15 @@ function resizeImage(fileObj, callback) {
image.size(fileObj.path, next);
},
function (imageData, next) {
- if (imageData.width < (parseInt(meta.config.maximumImageWidth, 10) || 760)) {
+ if (imageData.width < meta.config.maximumImageWidth) {
return callback(null, fileObj);
}
image.resizeImage({
path: fileObj.path,
target: file.appendToFileName(fileObj.path, '-resized'),
- width: parseInt(meta.config.maximumImageWidth, 10) || 760,
- quality: parseInt(meta.config.resizeImageQuality, 10) || 60,
+ width: meta.config.maximumImageWidth,
+ quality: meta.config.resizeImageQuality,
}, next);
},
function (next) {
@@ -133,7 +133,7 @@ function resizeImage(fileObj, callback) {
}
uploadsController.uploadThumb = function (req, res, next) {
- if (parseInt(meta.config.allowTopicsThumbnail, 10) !== 1) {
+ if (!meta.config.allowTopicsThumbnail) {
deleteTempFiles(req.files.files);
return next(new Error('[[error:topic-thumbnails-are-disabled]]'));
}
@@ -148,11 +148,10 @@ uploadsController.uploadThumb = function (req, res, next) {
file.isFileTypeAllowed(uploadedFile.path, next);
},
function (next) {
- var size = parseInt(meta.config.topicThumbSize, 10) || 120;
image.resizeImage({
path: uploadedFile.path,
- width: size,
- height: size,
+ width: meta.config.topicThumbSize,
+ height: meta.config.topicThumbSize,
}, next);
},
function (next) {
@@ -206,7 +205,7 @@ uploadsController.uploadFile = function (uid, uploadedFile, callback) {
return callback(new Error('[[error:invalid-file]]'));
}
- if (uploadedFile.size > parseInt(meta.config.maximumFileSize, 10) * 1024) {
+ if (uploadedFile.size > meta.config.maximumFileSize * 1024) {
return callback(new Error('[[error:file-too-big, ' + meta.config.maximumFileSize + ']]'));
}
diff --git a/src/controllers/user.js b/src/controllers/user.js
index a848dc0a14..16ed5d615b 100644
--- a/src/controllers/user.js
+++ b/src/controllers/user.js
@@ -84,7 +84,7 @@ userController.getUserDataByField = function (callerUid, field, fieldValue, call
};
userController.getUserDataByUID = function (callerUid, uid, callback) {
- if (!parseInt(callerUid, 10) && parseInt(meta.config.privateUserInfo, 10) === 1) {
+ if (!parseInt(callerUid, 10) && meta.config.privateUserInfo) {
return callback(new Error('[[error:no-privileges]]'));
}
@@ -100,8 +100,8 @@ userController.getUserDataByUID = function (callerUid, uid, callback) {
return callback(err || new Error('[[error:no-user]]'));
}
- results.userData.email = results.settings.showemail && parseInt(meta.config.hideEmail, 10) !== 1 ? results.userData.email : undefined;
- results.userData.fullname = results.settings.showfullname && parseInt(meta.config.hideFullname, 10) !== 1 ? results.userData.fullname : undefined;
+ results.userData.email = results.settings.showemail && !meta.config.hideEmail ? results.userData.email : undefined;
+ results.userData.fullname = results.settings.showfullname && !meta.config.hideFullname ? results.userData.fullname : undefined;
callback(null, results.userData);
});
diff --git a/src/controllers/users.js b/src/controllers/users.js
index 5c441be72e..cf57829546 100644
--- a/src/controllers/users.js
+++ b/src/controllers/users.js
@@ -105,7 +105,7 @@ usersController.getUsersSortedByPosts = function (req, res, next) {
};
usersController.getUsersSortedByReputation = function (req, res, next) {
- if (parseInt(meta.config['reputation:disabled'], 10) === 1) {
+ if (meta.config['reputation:disabled']) {
return next();
}
usersController.renderUsersPage('users:reputation', req, res, next);
@@ -169,7 +169,7 @@ usersController.getUsers = function (set, uid, query, callback) {
}
var page = parseInt(query.page, 10) || 1;
- var resultsPerPage = parseInt(meta.config.userSearchResultsPerPage, 10) || 50;
+ var resultsPerPage = meta.config.userSearchResultsPerPage;
var start = Math.max(0, page - 1) * resultsPerPage;
var stop = start + resultsPerPage - 1;
@@ -241,7 +241,7 @@ function render(req, res, data, next) {
data.maximumInvites = meta.config.maximumInvites;
data.inviteOnly = registrationType === 'invite-only' || registrationType === 'admin-invite-only';
data.adminInviteOnly = registrationType === 'admin-invite-only';
- data['reputation:disabled'] = parseInt(meta.config['reputation:disabled'], 10) === 1;
+ data['reputation:disabled'] = meta.config['reputation:disabled'];
async.waterfall([
function (next) {
diff --git a/src/flags.js b/src/flags.js
index c0c49c4a0a..120674655f 100644
--- a/src/flags.js
+++ b/src/flags.js
@@ -257,9 +257,8 @@ Flags.validate = function (payload, callback) {
return callback(err);
}
- var minimumReputation = utils.isNumber(meta.config['min:rep:flag']) ? parseInt(meta.config['min:rep:flag'], 10) : 0;
// Check if reporter meets rep threshold (or can edit the target post, in which case threshold does not apply)
- if (!editable.flag && parseInt(data.reporter.reputation, 10) < minimumReputation) {
+ if (!editable.flag && data.reporter.reputation < meta.config['min:rep:flag']) {
return callback(new Error('[[error:not-enough-reputation-to-flag]]'));
}
@@ -273,9 +272,8 @@ Flags.validate = function (payload, callback) {
return callback(err);
}
- var minimumReputation = utils.isNumber(meta.config['min:rep:flag']) ? parseInt(meta.config['min:rep:flag'], 10) : 0;
// Check if reporter meets rep threshold (or can edit the target user, in which case threshold does not apply)
- if (!editable && parseInt(data.reporter.reputation, 10) < minimumReputation) {
+ if (!editable && data.reporter.reputation < meta.config['min:rep:flag']) {
return callback(new Error('[[error:not-enough-reputation-to-flag]]'));
}
diff --git a/src/groups/create.js b/src/groups/create.js
index 46e8baff9d..3645ea4b2f 100644
--- a/src/groups/create.js
+++ b/src/groups/create.js
@@ -87,7 +87,7 @@ module.exports = function (Groups) {
return callback(new Error('[[error:group-name-too-short]]'));
}
- if (!Groups.isPrivilegeGroup(name) && name.length > (parseInt(meta.config.maximumGroupNameLength, 10) || 255)) {
+ if (!Groups.isPrivilegeGroup(name) && name.length > meta.config.maximumGroupNameLength) {
return callback(new Error('[[error:group-name-too-long]]'));
}
diff --git a/src/image.js b/src/image.js
index 9e65654507..5c2d233e90 100644
--- a/src/image.js
+++ b/src/image.js
@@ -93,8 +93,8 @@ image.checkDimensions = function (path, callback) {
return callback(err);
}
- const maxWidth = parseInt(meta.config.rejectImageWidth, 10) || 5000;
- const maxHeight = parseInt(meta.config.rejectImageHeight, 10) || 5000;
+ const maxWidth = meta.config.rejectImageWidth;
+ const maxHeight = meta.config.rejectImageHeight;
if (result.width > maxWidth || result.height > maxHeight) {
return callback(new Error('[[error:invalid-image-dimensions]]'));
}
diff --git a/src/messaging.js b/src/messaging.js
index 7a32c43df1..9564c7783e 100644
--- a/src/messaging.js
+++ b/src/messaging.js
@@ -249,7 +249,7 @@ Messaging.getTeaser = function (uid, roomId, callback) {
};
Messaging.canMessageUser = function (uid, toUid, callback) {
- if (parseInt(meta.config.disableChat, 10) === 1 || !uid || uid === toUid) {
+ if (meta.config.disableChat || !uid || uid === toUid) {
return callback(new Error('[[error:chat-disabled]]'));
}
@@ -272,7 +272,7 @@ Messaging.canMessageUser = function (uid, toUid, callback) {
return callback(new Error('[[error:user-banned]]'));
}
- if (parseInt(meta.config.requireEmailConfirmation, 10) === 1 && parseInt(userData['email:confirmed'], 10) !== 1) {
+ if (meta.config.requireEmailConfirmation && parseInt(userData['email:confirmed'], 10) !== 1) {
return callback(new Error('[[error:email-not-confirmed-chat]]'));
}
@@ -299,7 +299,7 @@ Messaging.canMessageUser = function (uid, toUid, callback) {
};
Messaging.canMessageRoom = function (uid, roomId, callback) {
- if (parseInt(meta.config.disableChat, 10) === 1 || !uid) {
+ if (meta.config.disableChat || !uid) {
return callback(new Error('[[error:chat-disabled]]'));
}
@@ -326,7 +326,7 @@ Messaging.canMessageRoom = function (uid, roomId, callback) {
return next(new Error('[[error:user-banned]]'));
}
- if (parseInt(meta.config.requireEmailConfirmation, 10) === 1 && parseInt(userData['email:confirmed'], 10) !== 1) {
+ if (meta.config.requireEmailConfirmation && parseInt(userData['email:confirmed'], 10) !== 1) {
return next(new Error('[[error:email-not-confirmed-chat]]'));
}
diff --git a/src/messaging/edit.js b/src/messaging/edit.js
index b118ca03c5..10ad773c79 100644
--- a/src/messaging/edit.js
+++ b/src/messaging/edit.js
@@ -59,9 +59,9 @@ module.exports = function (Messaging) {
durationConfig = 'chatDeleteDuration';
}
- if (parseInt(meta.config.disableChat, 10) === 1) {
+ if (meta.config.disableChat) {
return callback(new Error('[[error:chat-disabled]]'));
- } else if (parseInt(meta.config.disableChatMessageEditing, 10) === 1) {
+ } else if (meta.config.disableChatMessageEditing) {
return callback(new Error('[[error:chat-message-editing-disabled]]'));
}
@@ -74,7 +74,7 @@ module.exports = function (Messaging) {
return callback(new Error('[[error:user-banned]]'));
}
- if (parseInt(meta.config.requireEmailConfirmation, 10) === 1 && parseInt(userData['email:confirmed'], 10) !== 1) {
+ if (meta.config.requireEmailConfirmation && parseInt(userData['email:confirmed'], 10) !== 1) {
return callback(new Error('[[error:email-not-confirmed]]'));
}
async.parallel({
@@ -90,7 +90,7 @@ module.exports = function (Messaging) {
if (results.isAdmin) {
return callback();
}
- var chatConfigDuration = parseInt(meta.config[durationConfig], 10);
+ var chatConfigDuration = meta.config[durationConfig];
if (chatConfigDuration && Date.now() - parseInt(results.messageData.timestamp, 10) > chatConfigDuration * 1000) {
return callback(new Error('[[error:chat-' + type + '-duration-expired, ' + meta.config[durationConfig] + ']]'));
}
diff --git a/src/messaging/rooms.js b/src/messaging/rooms.js
index 6e85e594d0..7e16db352b 100644
--- a/src/messaging/rooms.js
+++ b/src/messaging/rooms.js
@@ -321,8 +321,8 @@ module.exports = function (Messaging) {
room.canReply = results.canReply;
room.groupChat = room.hasOwnProperty('groupChat') ? room.groupChat : results.users.length > 2;
room.usernames = Messaging.generateUsernames(results.users, uid);
- room.maximumUsersInChatRoom = parseInt(meta.config.maximumUsersInChatRoom, 10) || 0;
- room.maximumChatMessageLength = parseInt(meta.config.maximumChatMessageLength, 10) || 1000;
+ room.maximumUsersInChatRoom = meta.config.maximumUsersInChatRoom;
+ room.maximumChatMessageLength = meta.config.maximumChatMessageLength;
room.showUserInput = !room.maximumUsersInChatRoom || room.maximumUsersInChatRoom > 2;
room.isAdminOrGlobalMod = results.isAdminOrGlobalMod;
next(null, room);
diff --git a/src/meta.js b/src/meta.js
index 9a03c89ee6..6d5505a726 100644
--- a/src/meta.js
+++ b/src/meta.js
@@ -63,8 +63,8 @@ function restart() {
}
Meta.getSessionTTLSeconds = function () {
- var ttlDays = 60 * 60 * 24 * (parseInt(Meta.config.loginDays, 10) || 0);
- var ttlSeconds = (parseInt(Meta.config.loginSeconds, 10) || 0);
+ var ttlDays = 60 * 60 * 24 * Meta.config.loginDays;
+ var ttlSeconds = Meta.config.loginSeconds;
var ttl = ttlSeconds || ttlDays || 1209600; // Default to 14 days
return ttl;
};
diff --git a/src/meta/configs.js b/src/meta/configs.js
index bf4bfbb907..5b6392d8fc 100644
--- a/src/meta/configs.js
+++ b/src/meta/configs.js
@@ -10,11 +10,34 @@ var db = require('../database');
var pubsub = require('../pubsub');
var Meta = require('../meta');
var cacheBuster = require('./cacheBuster');
+const defaults = require('../../install/data/defaults');
var Configs = module.exports;
Meta.config = {};
+function deserialize(config) {
+ var deserialized = {};
+ Object.keys(config).forEach(function (key) {
+ if (typeof config[key] !== 'string') {
+ deserialized[key] = config[key];
+ return;
+ }
+
+ var number = parseFloat(config[key]);
+ if (!isNaN(number) && isFinite(config[key])) {
+ deserialized[key] = number;
+ } else if (config[key] === 'true') {
+ deserialized[key] = true;
+ } else if (config[key] === 'false') {
+ deserialized[key] = false;
+ } else {
+ deserialized[key] = config[key];
+ }
+ });
+ return deserialized;
+}
+
Configs.init = function (callback) {
var config;
async.waterfall([
@@ -34,20 +57,37 @@ Configs.init = function (callback) {
};
Configs.list = function (callback) {
- db.getObject('config', function (err, config) {
- config = config || {};
- config.version = nconf.get('version');
- config.registry = nconf.get('registry');
- callback(err, config);
- });
+ Configs.getFields([], callback);
};
Configs.get = function (field, callback) {
- db.getObjectField('config', field, callback);
+ Configs.getFields([field], function (err, values) {
+ callback(err, values ? values[field] : null);
+ });
};
Configs.getFields = function (fields, callback) {
- db.getObjectFields('config', fields, callback);
+ async.waterfall([
+ function (next) {
+ if (fields.length) {
+ db.getObjectFields('config', fields, next);
+ } else {
+ db.getObject('config', next);
+ }
+ },
+ function (values, next) {
+ try {
+ values = Object.assign({}, defaults, values ? deserialize(values) : {});
+ } catch (err) {
+ return next(err);
+ }
+ if (!fields.length) {
+ values.version = nconf.get('version');
+ values.registry = nconf.get('registry');
+ }
+ next(null, values);
+ },
+ ], callback);
};
Configs.set = function (field, value, callback) {
@@ -56,13 +96,15 @@ Configs.set = function (field, value, callback) {
return callback(new Error('[[error:invalid-data]]'));
}
- var data = {};
- data[field] = value;
- Configs.setMultiple(data, callback);
+ Configs.setMultiple({
+ [field]: value,
+ }, callback);
};
-
+// data comes from client-side
Configs.setMultiple = function (data, callback) {
+ data = deserialize(data);
+
async.waterfall([
function (next) {
processConfig(data, next);
@@ -77,6 +119,22 @@ Configs.setMultiple = function (data, callback) {
], callback);
};
+Configs.setOnEmpty = function (values, callback) {
+ async.waterfall([
+ function (next) {
+ db.getObject('config', next);
+ },
+ function (data, next) {
+ var config = Object.assign({}, values, data ? deserialize(data) : {});
+ db.setObject('config', config, next);
+ },
+ ], callback);
+};
+
+Configs.remove = function (field, callback) {
+ db.deleteObjectField('config', field, callback);
+};
+
function processConfig(data, callback) {
async.parallel([
async.apply(saveRenderedCss, data),
@@ -141,29 +199,3 @@ pubsub.on('config:update', function onConfigReceived(config) {
updateLocalConfig(config);
}
});
-
-Configs.setOnEmpty = function (values, callback) {
- async.waterfall([
- function (next) {
- db.getObject('config', next);
- },
- function (data, next) {
- data = data || {};
- var empty = {};
- Object.keys(values).forEach(function (key) {
- if (!data.hasOwnProperty(key)) {
- empty[key] = values[key];
- }
- });
- if (Object.keys(empty).length) {
- db.setObject('config', empty, next);
- } else {
- setImmediate(next);
- }
- },
- ], callback);
-};
-
-Configs.remove = function (field, callback) {
- db.deleteObjectField('config', field, callback);
-};
diff --git a/src/meta/themes.js b/src/meta/themes.js
index d011bed707..2c3f5147e7 100644
--- a/src/meta/themes.js
+++ b/src/meta/themes.js
@@ -192,7 +192,7 @@ Themes.setupPaths = function (callback) {
async.parallel({
themesData: Themes.get,
currentThemeId: function (next) {
- db.getObjectField('config', 'theme:id', next);
+ Meta.configs.get('theme:id', next);
},
}, next);
},
diff --git a/src/middleware/header.js b/src/middleware/header.js
index cb29604f95..881b4b6432 100644
--- a/src/middleware/header.js
+++ b/src/middleware/header.js
@@ -183,19 +183,19 @@ module.exports = function (middleware) {
templateValues.isAdmin = results.user.isAdmin;
templateValues.isGlobalMod = results.user.isGlobalMod;
templateValues.showModMenu = results.user.isAdmin || results.user.isGlobalMod || results.user.isMod;
- templateValues.canChat = results.canChat && parseInt(meta.config.disableChat, 10) !== 1;
+ templateValues.canChat = results.canChat && meta.config.disableChat !== 1;
templateValues.user = results.user;
templateValues.userJSON = jsesc(JSON.stringify(results.user), { isScriptContext: true });
- templateValues.useCustomCSS = parseInt(meta.config.useCustomCSS, 10) === 1 && meta.config.customCSS;
+ templateValues.useCustomCSS = meta.config.useCustomCSS && meta.config.customCSS;
templateValues.customCSS = templateValues.useCustomCSS ? (meta.config.renderedCustomCSS || '') : '';
- templateValues.useCustomHTML = parseInt(meta.config.useCustomHTML, 10) === 1;
+ templateValues.useCustomHTML = meta.config.useCustomHTML;
templateValues.customHTML = templateValues.useCustomHTML ? meta.config.customHTML : '';
- templateValues.maintenanceHeader = parseInt(meta.config.maintenanceMode, 10) === 1 && !results.isAdmin;
+ templateValues.maintenanceHeader = meta.config.maintenanceMode && !results.isAdmin;
templateValues.defaultLang = meta.config.defaultLang || 'en-GB';
templateValues.userLang = res.locals.config.userLang;
templateValues.languageDirection = results.languageDirection;
- templateValues.privateUserInfo = parseInt(meta.config.privateUserInfo, 10) === 1;
- templateValues.privateTagListing = parseInt(meta.config.privateTagListing, 10) === 1;
+ templateValues.privateUserInfo = meta.config.privateUserInfo;
+ templateValues.privateTagListing = meta.config.privateTagListing;
templateValues.template = { name: res.locals.template };
templateValues.template[res.locals.template] = true;
@@ -243,7 +243,7 @@ module.exports = function (middleware) {
});
addTimeagoLocaleScript(data.templateValues.scripts, res.locals.config.userLang);
- data.templateValues.useCustomJS = parseInt(meta.config.useCustomJS, 10) === 1;
+ data.templateValues.useCustomJS = meta.config.useCustomJS;
data.templateValues.customJS = data.templateValues.useCustomJS ? meta.config.customJS : '';
data.templateValues.isSpider = req.isSpider();
req.app.render('footer', data.templateValues, next);
@@ -270,7 +270,7 @@ module.exports = function (middleware) {
if (config && config.bootswatchSkin !== 'noskin') {
var skinToUse = '';
- if (parseInt(meta.config.disableCustomUserSkins, 10) !== 1) {
+ if (!meta.config.disableCustomUserSkins) {
skinToUse = config.bootswatchSkin;
} else if (meta.config.bootswatchSkin) {
skinToUse = meta.config.bootswatchSkin;
diff --git a/src/middleware/index.js b/src/middleware/index.js
index 0af7e7a6ee..2768fe644a 100644
--- a/src/middleware/index.js
+++ b/src/middleware/index.js
@@ -109,7 +109,7 @@ middleware.routeTouchIcon = function (req, res) {
};
middleware.privateTagListing = function (req, res, next) {
- if (!req.loggedIn && parseInt(meta.config.privateTagListing, 10) === 1) {
+ if (!req.loggedIn && meta.config.privateTagListing) {
controllers.helpers.notAllowed(req, res);
} else {
next();
@@ -140,7 +140,7 @@ function expose(exposedField, method, field, req, res, next) {
}
middleware.privateUploads = function (req, res, next) {
- if (req.loggedIn || parseInt(meta.config.privateUploads, 10) !== 1) {
+ if (req.loggedIn || !meta.config.privateUploads) {
return next();
}
@@ -156,7 +156,7 @@ middleware.privateUploads = function (req, res, next) {
};
middleware.busyCheck = function (req, res, next) {
- if (global.env === 'production' && (!meta.config.hasOwnProperty('eventLoopCheckEnabled') || parseInt(meta.config.eventLoopCheckEnabled, 10) === 1) && toobusy()) {
+ if (global.env === 'production' && (!meta.config.hasOwnProperty('eventLoopCheckEnabled') || meta.config.eventLoopCheckEnabled) && toobusy()) {
analytics.increment('errors:503');
res.status(503).type('text/html').sendFile(path.join(__dirname, '../../public/503.html'));
} else {
diff --git a/src/middleware/maintenance.js b/src/middleware/maintenance.js
index ce5053a616..7828619ead 100644
--- a/src/middleware/maintenance.js
+++ b/src/middleware/maintenance.js
@@ -7,7 +7,7 @@ var user = require('../user');
module.exports = function (middleware) {
middleware.maintenanceMode = function (req, res, callback) {
- if (parseInt(meta.config.maintenanceMode, 10) !== 1) {
+ if (!meta.config.maintenanceMode) {
return callback();
}
var url = req.url.replace(nconf.get('relative_path'), '');
diff --git a/src/middleware/user.js b/src/middleware/user.js
index 3cc69a750d..2fe60fce64 100644
--- a/src/middleware/user.js
+++ b/src/middleware/user.js
@@ -78,7 +78,7 @@ module.exports = function (middleware) {
}
middleware.checkGlobalPrivacySettings = function (req, res, next) {
- if (!req.loggedIn && !!parseInt(meta.config.privateUserInfo, 10)) {
+ if (!req.loggedIn && meta.config.privateUserInfo) {
return middleware.authenticate(req, res, next);
}
@@ -187,8 +187,8 @@ module.exports = function (middleware) {
}
var loginTime = req.session.meta ? req.session.meta.datetime : 0;
- var adminReloginDuration = (meta.config.adminReloginDuration || 60) * 60000;
- var disabled = parseInt(meta.config.adminReloginDuration, 10) === 0;
+ var adminReloginDuration = meta.config.adminReloginDuration * 60000;
+ var disabled = meta.config.adminReloginDuration === 0;
if (disabled || (loginTime && parseInt(loginTime, 10) > Date.now() - adminReloginDuration)) {
var timeLeft = parseInt(loginTime, 10) - (Date.now() - adminReloginDuration);
if (req.session.meta && timeLeft < Math.min(300000, adminReloginDuration)) {
diff --git a/src/posts/cache.js b/src/posts/cache.js
index 9c9bbe67d5..7d45ba8631 100644
--- a/src/posts/cache.js
+++ b/src/posts/cache.js
@@ -4,7 +4,7 @@ var LRU = require('lru-cache');
var meta = require('../meta');
var cache = LRU({
- max: parseInt(meta.config.postCacheSize, 10) || 5242880,
+ max: meta.config.postCacheSize,
length: function (n) { return n.length; },
maxAge: 0,
});
diff --git a/src/posts/create.js b/src/posts/create.js
index 19bf95c8a0..3074b298fe 100644
--- a/src/posts/create.js
+++ b/src/posts/create.js
@@ -49,7 +49,7 @@ module.exports = function (Posts) {
postData.toPid = data.toPid;
}
- if (data.ip && parseInt(meta.config.trackIpPerPost, 10) === 1) {
+ if (data.ip && meta.config.trackIpPerPost) {
postData.ip = data.ip;
}
diff --git a/src/posts/data.js b/src/posts/data.js
index a05de93305..fc60fff021 100644
--- a/src/posts/data.js
+++ b/src/posts/data.js
@@ -5,7 +5,7 @@ var async = require('async');
var db = require('../database');
var plugins = require('../plugins');
-const intFields = ['uid', 'pid', 'tid', 'deleted'];
+const intFields = ['uid', 'pid', 'tid', 'deleted', 'timestamp'];
module.exports = function (Posts) {
Posts.getPostsFields = function (pids, fields, callback) {
diff --git a/src/posts/diffs.js b/src/posts/diffs.js
index deec210619..13a10eaca2 100644
--- a/src/posts/diffs.js
+++ b/src/posts/diffs.js
@@ -12,7 +12,7 @@ var translator = require('../translator');
var Diffs = {};
Diffs.exists = function (pid, callback) {
- if (parseInt(meta.config.enablePostHistory || 1, 10) !== 1) {
+ if (meta.config.enablePostHistory !== 1) {
return callback(null, 0);
}
diff --git a/src/posts/edit.js b/src/posts/edit.js
index 7148149042..38dd067c3f 100644
--- a/src/posts/edit.js
+++ b/src/posts/edit.js
@@ -10,14 +10,13 @@ var topics = require('../topics');
var user = require('../user');
var privileges = require('../privileges');
var plugins = require('../plugins');
-var cache = require('./cache');
var pubsub = require('../pubsub');
var utils = require('../utils');
var translator = require('../translator');
module.exports = function (Posts) {
pubsub.on('post:edit', function (pid) {
- cache.del(pid);
+ require('./cache').del(pid);
});
Posts.edit = function (data, callback) {
@@ -67,7 +66,7 @@ module.exports = function (Posts) {
Posts.setPostFields(data.pid, postData, next);
},
function (next) {
- if (parseInt(meta.config.enablePostHistory || 1, 10) !== 1) {
+ if (meta.config.enablePostHistory !== 1) {
return setImmediate(next);
}
@@ -79,7 +78,7 @@ module.exports = function (Posts) {
postData.topic = results.topic;
plugins.fireHook('action:post.edit', { post: _.clone(postData), data: data, uid: data.uid });
- cache.del(String(postData.pid));
+ require('./cache').del(String(postData.pid));
pubsub.publish('post:edit', String(postData.pid));
Posts.parsePost(postData, next);
diff --git a/src/posts/parse.js b/src/posts/parse.js
index da293d0db8..5fd2ca1818 100644
--- a/src/posts/parse.js
+++ b/src/posts/parse.js
@@ -6,7 +6,6 @@ var url = require('url');
var winston = require('winston');
var meta = require('../meta');
-var cache = require('./cache');
var plugins = require('../plugins');
var translator = require('../translator');
var utils = require('../utils');
@@ -24,7 +23,7 @@ module.exports = function (Posts) {
Posts.parsePost = function (postData, callback) {
postData.content = String(postData.content || '');
-
+ var cache = require('./cache');
if (postData.pid && cache.has(String(postData.pid))) {
postData.content = cache.get(String(postData.pid));
cache.hits += 1;
@@ -86,11 +85,11 @@ module.exports = function (Posts) {
signature = translator.escape(signature);
var tagsToStrip = [];
- if (parseInt(meta.config['signatures:disableLinks'], 10) === 1) {
+ if (meta.config['signatures:disableLinks']) {
tagsToStrip.push('a');
}
- if (parseInt(meta.config['signatures:disableImages'], 10) === 1) {
+ if (meta.config['signatures:disableImages']) {
tagsToStrip.push('img');
}
diff --git a/src/posts/queue.js b/src/posts/queue.js
index c1fb332450..8c80e4125f 100644
--- a/src/posts/queue.js
+++ b/src/posts/queue.js
@@ -15,10 +15,10 @@ module.exports = function (Posts) {
Posts.shouldQueue = function (uid, data, callback) {
async.waterfall([
function (next) {
- user.getUserFields(uid, ['reputation', 'postcount'], next);
+ user.getUserFields(uid, ['uid', 'reputation', 'postcount'], next);
},
function (userData, next) {
- var shouldQueue = parseInt(meta.config.postQueue, 10) === 1 && (!parseInt(uid, 10) || (parseInt(userData.reputation, 10) <= 0 && parseInt(userData.postcount, 10) <= 0));
+ var shouldQueue = meta.config.postQueue && (!userData.uid || (userData.reputation <= 0 && userData.postcount <= 0));
plugins.fireHook('filter:post.shouldQueue', {
shouldQueue: shouldQueue,
uid: uid,
@@ -199,8 +199,8 @@ module.exports = function (Posts) {
function (postData, next) {
var result = {
posts: [postData],
- 'reputation:disabled': parseInt(meta.config['reputation:disabled'], 10) === 1,
- 'downvote:disabled': parseInt(meta.config['downvote:disabled'], 10) === 1,
+ 'reputation:disabled': !!meta.config['reputation:disabled'],
+ 'downvote:disabled': !!meta.config['downvote:disabled'],
};
socketHelpers.notifyNew(data.uid, 'newPost', result);
next();
diff --git a/src/posts/tools.js b/src/posts/tools.js
index c395eae457..cf7c8923c4 100644
--- a/src/posts/tools.js
+++ b/src/posts/tools.js
@@ -3,7 +3,6 @@
var async = require('async');
var privileges = require('../privileges');
-var cache = require('./cache');
module.exports = function (Posts) {
Posts.tools = {};
@@ -42,7 +41,7 @@ module.exports = function (Posts) {
}
if (isDelete) {
- cache.del(pid);
+ require('./cache').del(pid);
Posts.delete(pid, uid, next);
} else {
Posts.restore(pid, uid, function (err, postData) {
@@ -65,7 +64,7 @@ module.exports = function (Posts) {
if (!canPurge) {
return next(new Error('[[error:no-privileges]]'));
}
- cache.del(pid);
+ require('./cache').del(pid);
Posts.purge(pid, uid, next);
},
], callback);
diff --git a/src/posts/user.js b/src/posts/user.js
index dc61786eda..ad82e7e684 100644
--- a/src/posts/user.js
+++ b/src/posts/user.js
@@ -72,7 +72,7 @@ module.exports = function (Posts) {
userData.fullname = userSettings[index].showfullname ? validator.escape(String(userData.fullname || '')) : undefined;
userData.selectedGroups = [];
- if (parseInt(meta.config.hideFullname, 10) === 1) {
+ if (meta.config.hideFullname) {
userData.fullname = undefined;
}
});
@@ -88,7 +88,7 @@ module.exports = function (Posts) {
groups.isMemberOfGroups(userData.uid, userData.groupTitleArray, next);
},
signature: function (next) {
- if (!userData.signature || !canUseSignature || parseInt(meta.config.disableSignatures, 10) === 1) {
+ if (!userData.signature || !canUseSignature || meta.config.disableSignatures) {
userData.signature = '';
return next();
}
diff --git a/src/posts/votes.js b/src/posts/votes.js
index 422ca67efa..75a2b5b3ca 100644
--- a/src/posts/votes.js
+++ b/src/posts/votes.js
@@ -12,7 +12,7 @@ module.exports = function (Posts) {
var votesInProgress = {};
Posts.upvote = function (pid, uid, callback) {
- if (parseInt(meta.config['reputation:disabled'], 10) === 1) {
+ if (meta.config['reputation:disabled']) {
return callback(new Error('[[error:reputation-system-disabled]]'));
}
@@ -40,11 +40,11 @@ module.exports = function (Posts) {
};
Posts.downvote = function (pid, uid, callback) {
- if (parseInt(meta.config['reputation:disabled'], 10) === 1) {
+ if (meta.config['reputation:disabled']) {
return callback(new Error('[[error:reputation-system-disabled]]'));
}
- if (parseInt(meta.config['downvote:disabled'], 10) === 1) {
+ if (meta.config['downvote:disabled']) {
return callback(new Error('[[error:downvoting-disabled]]'));
}
@@ -179,7 +179,7 @@ module.exports = function (Posts) {
return callback(new Error('[[error:self-vote]]'));
}
- if (command === 'downvote' && parseInt(results.reputation, 10) < parseInt(meta.config['min:rep:downvote'], 10)) {
+ if (command === 'downvote' && results.reputation < meta.config['min:rep:downvote']) {
return callback(new Error('[[error:not-enough-reputation-to-downvote]]'));
}
diff --git a/src/privileges/posts.js b/src/privileges/posts.js
index 02f9b7136e..78181b3cdb 100644
--- a/src/privileges/posts.js
+++ b/src/privileges/posts.js
@@ -10,7 +10,6 @@ var topics = require('../topics');
var user = require('../user');
var helpers = require('./helpers');
var plugins = require('../plugins');
-var utils = require('../utils');
module.exports = function (privileges) {
privileges.posts = {};
@@ -184,7 +183,7 @@ module.exports = function (privileges) {
return next(null, { flag: false, message: '[[error:no-privileges]]' });
}
- var postDeleteDuration = parseInt(meta.config.postDeleteDuration, 10);
+ var postDeleteDuration = meta.config.postDeleteDuration;
if (postDeleteDuration && (Date.now() - parseInt(postData.timestamp, 10) > postDeleteDuration * 1000)) {
return next(null, { flag: false, message: '[[error:post-delete-duration-expired, ' + meta.config.postDeleteDuration + ']]' });
}
@@ -204,8 +203,8 @@ module.exports = function (privileges) {
}, next);
},
function (results, next) {
- var minimumReputation = utils.isNumber(meta.config['min:rep:flag']) ? parseInt(meta.config['min:rep:flag'], 10) : 0;
- var canFlag = results.isAdminOrMod || parseInt(results.userReputation, 10) >= minimumReputation;
+ var minimumReputation = meta.config['min:rep:flag'];
+ var canFlag = results.isAdminOrMod || (results.userReputation >= minimumReputation);
next(null, { flag: canFlag });
},
], callback);
@@ -249,8 +248,8 @@ module.exports = function (privileges) {
posts.getPostFields(pid, ['tid', 'timestamp'], next);
},
function (postData, next) {
- var postEditDuration = parseInt(meta.config.postEditDuration, 10);
- if (postEditDuration && Date.now() - parseInt(postData.timestamp, 10) > postEditDuration * 1000) {
+ var postEditDuration = meta.config.postEditDuration;
+ if (postEditDuration && (Date.now() - postData.timestamp > postEditDuration * 1000)) {
return callback(null, { flag: false, message: '[[error:post-edit-duration-expired, ' + meta.config.postEditDuration + ']]' });
}
topics.isLocked(postData.tid, next);
diff --git a/src/privileges/topics.js b/src/privileges/topics.js
index b3366e2185..e7fcbb32bc 100644
--- a/src/privileges/topics.js
+++ b/src/privileges/topics.js
@@ -191,7 +191,7 @@ module.exports = function (privileges) {
return next(null, true);
}
- var preventTopicDeleteAfterReplies = parseInt(meta.config.preventTopicDeleteAfterReplies, 10) || 0;
+ var preventTopicDeleteAfterReplies = meta.config.preventTopicDeleteAfterReplies;
if (preventTopicDeleteAfterReplies && (topicData.postcount - 1) >= preventTopicDeleteAfterReplies) {
var langKey = preventTopicDeleteAfterReplies > 1 ?
'[[error:cant-delete-topic-has-replies, ' + meta.config.preventTopicDeleteAfterReplies + ']]' :
diff --git a/src/routes/feeds.js b/src/routes/feeds.js
index 07e1cf2379..db1d394de2 100644
--- a/src/routes/feeds.js
+++ b/src/routes/feeds.js
@@ -78,7 +78,7 @@ function validateTokenIfRequiresLogin(requiresLogin, cid, req, res, callback) {
}
function generateForTopic(req, res, callback) {
- if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
+ if (meta.config['feeds:disableRSS']) {
return controllers404.send404(req, res);
}
@@ -149,7 +149,7 @@ function generateForTopic(req, res, callback) {
}
function generateForCategory(req, res, next) {
- if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
+ if (meta.config['feeds:disableRSS']) {
return controllers404.send404(req, res);
}
var cid = req.params.category_id;
@@ -195,7 +195,7 @@ function generateForCategory(req, res, next) {
}
function generateForTopics(req, res, next) {
- if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
+ if (meta.config['feeds:disableRSS']) {
return controllers404.send404(req, res);
}
@@ -220,7 +220,7 @@ function generateForTopics(req, res, next) {
}
function generateForRecent(req, res, next) {
- if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
+ if (meta.config['feeds:disableRSS']) {
return controllers404.send404(req, res);
}
@@ -245,7 +245,7 @@ function generateForRecent(req, res, next) {
}
function generateForTop(req, res, next) {
- if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
+ if (meta.config['feeds:disableRSS']) {
return controllers404.send404(req, res);
}
var term = terms[req.params.term] || 'day';
@@ -285,7 +285,7 @@ function generateForTop(req, res, next) {
}
function generateForPopular(req, res, next) {
- if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
+ if (meta.config['feeds:disableRSS']) {
return controllers404.send404(req, res);
}
@@ -387,7 +387,7 @@ function generateTopicsFeed(feedOptions, feedTopics, callback) {
}
function generateForRecentPosts(req, res, next) {
- if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
+ if (meta.config['feeds:disableRSS']) {
return controllers404.send404(req, res);
}
@@ -409,7 +409,7 @@ function generateForRecentPosts(req, res, next) {
}
function generateForCategoryRecentPosts(req, res, callback) {
- if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
+ if (meta.config['feeds:disableRSS']) {
return controllers404.send404(req, res);
}
var cid = req.params.category_id;
@@ -475,7 +475,7 @@ function generateForPostsFeed(feedOptions, posts) {
}
function generateForUserTopics(req, res, callback) {
- if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
+ if (meta.config['feeds:disableRSS']) {
return controllers404.send404(req, res);
}
@@ -504,7 +504,7 @@ function generateForUserTopics(req, res, callback) {
}
function generateForTag(req, res, next) {
- if (parseInt(meta.config['feeds:disableRSS'], 10) === 1) {
+ if (meta.config['feeds:disableRSS']) {
return controllers404.send404(req, res);
}
var tag = validator.escape(String(req.params.tag));
diff --git a/src/sitemap.js b/src/sitemap.js
index 588d39e07e..663f7da08e 100644
--- a/src/sitemap.js
+++ b/src/sitemap.js
@@ -19,7 +19,7 @@ var sitemap = {
};
sitemap.render = function (callback) {
- var topicsPerPage = parseInt(meta.config.sitemapTopics, 10) || 500;
+ var topicsPerPage = meta.config.sitemapTopics;
var returnData = {
url: nconf.get('url'),
topics: [],
@@ -119,7 +119,7 @@ sitemap.getTopicPage = function (page, callback) {
return callback();
}
- var numTopics = parseInt(meta.config.sitemapTopics, 10) || 500;
+ var numTopics = meta.config.sitemapTopics;
var min = (parseInt(page, 10) - 1) * numTopics;
var max = min + numTopics;
diff --git a/src/socket.io/admin/user.js b/src/socket.io/admin/user.js
index c15e41fec6..4c7c6caf44 100644
--- a/src/socket.io/admin/user.js
+++ b/src/socket.io/admin/user.js
@@ -98,7 +98,7 @@ User.sendValidationEmail = function (socket, uids, callback) {
return callback(new Error('[[error:invalid-data]]'));
}
- if (parseInt(meta.config.requireEmailConfirmation, 10) !== 1) {
+ if (!meta.config.requireEmailConfirmation) {
return callback(new Error('[[error:email-confirmations-are-disabled]]'));
}
diff --git a/src/socket.io/groups.js b/src/socket.io/groups.js
index 033a4e7a4b..2834fd3c5f 100644
--- a/src/socket.io/groups.js
+++ b/src/socket.io/groups.js
@@ -36,7 +36,7 @@ SocketGroups.join = function (socket, data, callback) {
return next(new Error('[[error:no-group]]'));
}
- if (parseInt(meta.config.allowPrivateGroups, 10) !== 1) {
+ if (!meta.config.allowPrivateGroups) {
return groups.join(data.groupName, socket.uid, callback);
}
@@ -238,7 +238,7 @@ SocketGroups.kick = isOwner(function (socket, data, callback) {
SocketGroups.create = function (socket, data, callback) {
if (!socket.uid) {
return callback(new Error('[[error:no-privileges]]'));
- } else if (parseInt(meta.config.allowGroupCreation, 10) !== 1) {
+ } else if (!meta.config.allowGroupCreation) {
return callback(new Error('[[error:group-creation-disabled]]'));
} else if (groups.isPrivilegeGroup(data.name)) {
return callback(new Error('[[error:invalid-group-name]]'));
diff --git a/src/socket.io/index.js b/src/socket.io/index.js
index 4c772db131..046f64e91d 100644
--- a/src/socket.io/index.js
+++ b/src/socket.io/index.js
@@ -168,7 +168,7 @@ function requireModules() {
function checkMaintenance(socket, callback) {
var meta = require('../meta');
- if (parseInt(meta.config.maintenanceMode, 10) !== 1) {
+ if (!meta.config.maintenanceMode) {
return setImmediate(callback);
}
user.isAdministrator(socket.uid, function (err, isAdmin) {
diff --git a/src/socket.io/modules.js b/src/socket.io/modules.js
index 2a169a3cfa..e0c9ec4a6d 100644
--- a/src/socket.io/modules.js
+++ b/src/socket.io/modules.js
@@ -137,8 +137,7 @@ SocketModules.chats.send = function (socket, data, callback) {
function rateLimitExceeded(socket) {
var now = Date.now();
socket.lastChatMessageTime = socket.lastChatMessageTime || 0;
- var delay = meta.config.hasOwnProperty('chatMessageDelay') ? parseInt(meta.config.chatMessageDelay, 10) : 200;
- if (now - socket.lastChatMessageTime < delay) {
+ if (now - socket.lastChatMessageTime < meta.config.chatMessageDelay) {
return true;
}
socket.lastChatMessageTime = now;
@@ -193,7 +192,7 @@ SocketModules.chats.addUserToRoom = function (socket, data, callback) {
Messaging.getUserCountInRoom(data.roomId, next);
},
function (userCount, next) {
- var maxUsers = parseInt(meta.config.maximumUsersInChatRoom, 10) || 0;
+ var maxUsers = meta.config.maximumUsersInChatRoom;
if (maxUsers && userCount >= maxUsers) {
return next(new Error('[[error:cant-add-more-users-to-chat-room]]'));
}
diff --git a/src/socket.io/posts.js b/src/socket.io/posts.js
index d0e1372b9e..0b14cc2407 100644
--- a/src/socket.io/posts.js
+++ b/src/socket.io/posts.js
@@ -24,7 +24,7 @@ require('./posts/tools')(SocketPosts);
require('./posts/diffs')(SocketPosts);
SocketPosts.reply = function (socket, data, callback) {
- if (!data || !data.tid || (parseInt(meta.config.minimumPostLength, 10) !== 0 && !data.content)) {
+ if (!data || !data.tid || (meta.config.minimumPostLength !== 0 && !data.content)) {
return callback(new Error('[[error:invalid-data]]'));
}
@@ -57,8 +57,8 @@ function postReply(socket, data, callback) {
function (postData, next) {
var result = {
posts: [postData],
- 'reputation:disabled': parseInt(meta.config['reputation:disabled'], 10) === 1,
- 'downvote:disabled': parseInt(meta.config['downvote:disabled'], 10) === 1,
+ 'reputation:disabled': meta.config['reputation:disabled'] === 1,
+ 'downvote:disabled': meta.config['downvote:disabled'] === 1,
};
next(null, postData);
diff --git a/src/socket.io/posts/edit.js b/src/socket.io/posts/edit.js
index 296e3e2cb4..2e418fc041 100644
--- a/src/socket.io/posts/edit.js
+++ b/src/socket.io/posts/edit.js
@@ -15,24 +15,24 @@ module.exports = function (SocketPosts) {
SocketPosts.edit = function (socket, data, callback) {
if (!socket.uid) {
return callback(new Error('[[error:not-logged-in]]'));
- } else if (!data || !data.pid || (parseInt(meta.config.minimumPostLength, 10) !== 0 && !data.content)) {
+ } else if (!data || !data.pid || (meta.config.minimumPostLength !== 0 && !data.content)) {
return callback(new Error('[[error:invalid-data]]'));
}
// Trim and remove HTML (latter for composers that send in HTML, like redactor)
var contentLen = utils.stripHTMLTags(data.content).trim().length;
- if (data.title && data.title.length < parseInt(meta.config.minimumTitleLength, 10)) {
+ if (data.title && data.title.length < meta.config.minimumTitleLength) {
return callback(new Error('[[error:title-too-short, ' + meta.config.minimumTitleLength + ']]'));
- } else if (data.title && data.title.length > parseInt(meta.config.maximumTitleLength, 10)) {
+ } else if (data.title && data.title.length > meta.config.maximumTitleLength) {
return callback(new Error('[[error:title-too-long, ' + meta.config.maximumTitleLength + ']]'));
- } else if (data.tags && data.tags.length < parseInt(meta.config.minimumTagsPerTopic, 10)) {
+ } else if (data.tags && data.tags.length < meta.config.minimumTagsPerTopic) {
return callback(new Error('[[error:not-enough-tags, ' + meta.config.minimumTagsPerTopic + ']]'));
- } else if (data.tags && data.tags.length > parseInt(meta.config.maximumTagsPerTopic, 10)) {
+ } else if (data.tags && data.tags.length > meta.config.maximumTagsPerTopic) {
return callback(new Error('[[error:too-many-tags, ' + meta.config.maximumTagsPerTopic + ']]'));
- } else if (parseInt(meta.config.minimumPostLength, 10) !== 0 && contentLen < parseInt(meta.config.minimumPostLength, 10)) {
+ } else if (meta.config.minimumPostLength !== 0 && contentLen < meta.config.minimumPostLength) {
return callback(new Error('[[error:content-too-short, ' + meta.config.minimumPostLength + ']]'));
- } else if (contentLen > parseInt(meta.config.maximumPostLength, 10)) {
+ } else if (contentLen > meta.config.maximumPostLength) {
return callback(new Error('[[error:content-too-long, ' + meta.config.maximumPostLength + ']]'));
}
diff --git a/src/socket.io/posts/votes.js b/src/socket.io/posts/votes.js
index 0d708f2901..29535641ea 100644
--- a/src/socket.io/posts/votes.js
+++ b/src/socket.io/posts/votes.js
@@ -17,7 +17,7 @@ module.exports = function (SocketPosts) {
async.waterfall([
function (next) {
- if (parseInt(meta.config.votesArePublic, 10) !== 0) {
+ if (meta.config.votesArePublic) {
return next(null, true);
}
privileges.categories.isAdminOrMod(data.cid, socket.uid, next);
diff --git a/src/socket.io/topics/infinitescroll.js b/src/socket.io/topics/infinitescroll.js
index 54d4289e8c..8157656fe2 100644
--- a/src/socket.io/topics/infinitescroll.js
+++ b/src/socket.io/topics/infinitescroll.js
@@ -78,8 +78,8 @@ module.exports = function (SocketTopics) {
}
topicData.privileges = userPrivileges;
- topicData['reputation:disabled'] = parseInt(meta.config['reputation:disabled'], 10) === 1;
- topicData['downvote:disabled'] = parseInt(meta.config['downvote:disabled'], 10) === 1;
+ topicData['reputation:disabled'] = meta.config['reputation:disabled'] === 1;
+ topicData['downvote:disabled'] = meta.config['downvote:disabled'] === 1;
topics.modifyPostsByPrivilege(topicData, userPrivileges);
next(null, topicData);
diff --git a/src/socket.io/user.js b/src/socket.io/user.js
index ca21d0a38b..db1c49d48f 100644
--- a/src/socket.io/user.js
+++ b/src/socket.io/user.js
@@ -84,7 +84,7 @@ SocketUser.emailConfirm = function (socket, data, callback) {
return callback(new Error('[[error:no-privileges]]'));
}
- if (parseInt(meta.config.requireEmailConfirmation, 10) !== 1) {
+ if (!meta.config.requireEmailConfirmation) {
return callback(new Error('[[error:email-confirmations-are-disabled]]'));
}
@@ -297,7 +297,7 @@ SocketUser.invite = function (socket, email, callback) {
if (registrationType === 'admin-invite-only' && !isAdmin) {
return next(new Error('[[error:no-privileges]]'));
}
- var max = parseInt(meta.config.maximumInvites, 10);
+ var max = meta.config.maximumInvites;
email = email.split(',').map(email => email.trim()).filter(Boolean);
async.eachSeries(email, function (email, next) {
async.waterfall([
diff --git a/src/socket.io/user/profile.js b/src/socket.io/user/profile.js
index 857ac4ddf8..e84442650e 100644
--- a/src/socket.io/user/profile.js
+++ b/src/socket.io/user/profile.js
@@ -171,11 +171,11 @@ module.exports = function (SocketUser) {
return next(new Error('[[error:no-privileges]]'));
}
- if (!results.isAdminOrGlobalMod && parseInt(meta.config['username:disableEdit'], 10) === 1) {
+ if (!results.isAdminOrGlobalMod && meta.config['username:disableEdit']) {
data.username = oldUserData.username;
}
- if (!results.isAdminOrGlobalMod && parseInt(meta.config['email:disableEdit'], 10) === 1) {
+ if (!results.isAdminOrGlobalMod && meta.config['email:disableEdit']) {
data.email = oldUserData.email;
}
diff --git a/src/topics.js b/src/topics.js
index 52f08c9ca7..66f2f05d98 100644
--- a/src/topics.js
+++ b/src/topics.js
@@ -117,7 +117,7 @@ Topics.getTopicsByTids = function (tids, uid, callback) {
},
function (results, next) {
results.users.forEach(function (user, index) {
- if (parseInt(meta.config.hideFullname, 10) === 1 || !results.userSettings[index].showfullname) {
+ if (meta.config.hideFullname || !results.userSettings[index].showfullname) {
user.fullname = undefined;
}
});
diff --git a/src/topics/create.js b/src/topics/create.js
index 4a0d1be942..95cb490ad2 100644
--- a/src/topics/create.js
+++ b/src/topics/create.js
@@ -314,7 +314,7 @@ module.exports = function (Topics) {
postData.index = parseInt(results.topicInfo.postcount, 10) - 1;
// Username override for guests, if enabled
- if (parseInt(meta.config.allowGuestHandles, 10) === 1 && parseInt(postData.uid, 10) === 0 && data.handle) {
+ if (meta.config.allowGuestHandles && postData.uid === 0 && data.handle) {
postData.user.username = validator.escape(String(data.handle));
}
@@ -348,7 +348,7 @@ module.exports = function (Topics) {
}
function guestHandleValid(data, callback) {
- if (parseInt(meta.config.allowGuestHandles, 10) === 1 && parseInt(data.uid, 10) === 0 && data.handle) {
+ if (meta.config.allowGuestHandles && parseInt(data.uid, 10) === 0 && data.handle) {
if (data.handle.length > meta.config.maximumUsernameLength) {
return callback(new Error('[[error:guest-handle-invalid]]'));
}
diff --git a/src/topics/data.js b/src/topics/data.js
index 29e6eafcf0..842722d38a 100644
--- a/src/topics/data.js
+++ b/src/topics/data.js
@@ -8,7 +8,10 @@ var categories = require('../categories');
var utils = require('../utils');
var translator = require('../translator');
-const intFields = ['tid', 'cid', 'uid', 'mainPid', 'deleted', 'locked', 'pinned'];
+const intFields = [
+ 'tid', 'cid', 'uid', 'mainPid', 'deleted', 'locked', 'pinned',
+ 'timestamp',
+];
module.exports = function (Topics) {
Topics.getTopicsFields = function (tids, fields, callback) {
diff --git a/src/topics/fork.js b/src/topics/fork.js
index 4ac4dfb113..de34054c3f 100644
--- a/src/topics/fork.js
+++ b/src/topics/fork.js
@@ -15,9 +15,9 @@ module.exports = function (Topics) {
title = title.trim();
}
- if (title.length < parseInt(meta.config.minimumTitleLength, 10)) {
+ if (title.length < meta.config.minimumTitleLength) {
return callback(new Error('[[error:title-too-short, ' + meta.config.minimumTitleLength + ']]'));
- } else if (title.length > parseInt(meta.config.maximumTitleLength, 10)) {
+ } else if (title.length > meta.config.maximumTitleLength) {
return callback(new Error('[[error:title-too-long, ' + meta.config.maximumTitleLength + ']]'));
}
diff --git a/src/topics/posts.js b/src/topics/posts.js
index 8c131cfe9e..de62b79450 100644
--- a/src/topics/posts.js
+++ b/src/topics/posts.js
@@ -116,7 +116,7 @@ module.exports = function (Topics) {
postObj.selfPost = !!parseInt(uid, 10) && parseInt(uid, 10) === parseInt(postObj.uid, 10);
// Username override for guests, if enabled
- if (parseInt(meta.config.allowGuestHandles, 10) === 1 && parseInt(postObj.uid, 10) === 0 && postObj.handle) {
+ if (meta.config.allowGuestHandles && postObj.uid === 0 && postObj.handle) {
postObj.user.username = validator.escape(String(postObj.handle));
}
}
diff --git a/src/topics/sorted.js b/src/topics/sorted.js
index 4a42bb528f..5748f34551 100644
--- a/src/topics/sorted.js
+++ b/src/topics/sorted.js
@@ -132,7 +132,7 @@ module.exports = function (Topics) {
function (tids, next) {
async.parallel({
ignoredCids: function (next) {
- if (filter === 'watched' || parseInt(meta.config.disableRecentCategoryFilter, 10) === 1) {
+ if (filter === 'watched' || meta.config.disableRecentCategoryFilter) {
return next(null, []);
}
user.getIgnoredCategories(uid, next);
diff --git a/src/topics/tags.js b/src/topics/tags.js
index 8b2e1c3972..377757919d 100644
--- a/src/topics/tags.js
+++ b/src/topics/tags.js
@@ -485,7 +485,7 @@ module.exports = function (Topics) {
return plugins.fireHook('filter:topic.getRelatedTopics', { topic: topicData, uid: uid }, callback);
}
- var maximumTopics = parseInt(meta.config.maximumRelatedTopics, 10) || 0;
+ var maximumTopics = meta.config.maximumRelatedTopics;
if (maximumTopics === 0 || !topicData.tags || !topicData.tags.length) {
return callback(null, []);
}
diff --git a/src/topics/thumb.js b/src/topics/thumb.js
index 17d2806810..0050f5670e 100644
--- a/src/topics/thumb.js
+++ b/src/topics/thumb.js
@@ -46,11 +46,10 @@ module.exports = function (Topics) {
file.isFileTypeAllowed(pathToUpload, next);
},
function (next) {
- var size = parseInt(meta.config.topicThumbSize, 10) || 120;
image.resizeImage({
path: pathToUpload,
- width: size,
- height: size,
+ width: meta.config.topicThumbSize,
+ height: meta.config.topicThumbSize,
}, next);
},
function (next) {
diff --git a/src/topics/unread.js b/src/topics/unread.js
index 3a2ee3ed20..4053795efe 100644
--- a/src/topics/unread.js
+++ b/src/topics/unread.js
@@ -60,8 +60,7 @@ module.exports = function (Topics) {
};
Topics.unreadCutoff = function () {
- var cutoff = parseInt(meta.config.unreadCutoff, 10) || 2;
- return Date.now() - (cutoff * 86400000);
+ return Date.now() - (meta.config.unreadCutoff * 86400000);
};
Topics.getUnreadTids = function (params, callback) {
diff --git a/src/user/auth.js b/src/user/auth.js
index 195e14ce50..53d0b60427 100644
--- a/src/user/auth.js
+++ b/src/user/auth.js
@@ -27,8 +27,7 @@ module.exports = function (User) {
db.increment('loginAttempts:' + uid, next);
},
function (attemps, next) {
- var loginAttempts = parseInt(meta.config.loginAttempts, 10) || 5;
- if (attemps <= loginAttempts) {
+ if (attemps <= meta.config.loginAttempts) {
return db.pexpire('loginAttempts:' + uid, 1000 * 60 * 60, callback);
}
// Lock out the account
diff --git a/src/user/create.js b/src/user/create.js
index a82c050409..fecdf7a1ae 100644
--- a/src/user/create.js
+++ b/src/user/create.js
@@ -110,7 +110,7 @@ module.exports = function (User) {
async.apply(db.sortedSetAdd, 'user:' + userData.uid + ':emails', timestamp, userData.email),
], next);
- if (parseInt(userData.uid, 10) !== 1 && parseInt(meta.config.requireEmailConfirmation, 10) === 1) {
+ if (userData.uid > 1 && meta.config.requireEmailConfirmation) {
User.email.sendValidationEmail(userData.uid, {
email: userData.email,
});
diff --git a/src/user/data.js b/src/user/data.js
index a789252d35..1f2de654f1 100644
--- a/src/user/data.js
+++ b/src/user/data.js
@@ -11,7 +11,11 @@ var meta = require('../meta');
var plugins = require('../plugins');
var utils = require('../utils');
-const intFields = ['uid', 'postcount', 'topiccount', 'banned'];
+const intFields = [
+ 'uid', 'postcount', 'topiccount', 'reputation', 'profileviews',
+ 'banned', 'email:confirmed', 'joindate', 'lastonline', 'lastqueuetime',
+ 'lastposttime',
+];
module.exports = function (User) {
var iconBackgrounds = [
@@ -205,7 +209,7 @@ module.exports = function (User) {
if (!Array.isArray(user.groupTitleArray)) {
user.groupTitleArray = [user.groupTitleArray];
}
- if (parseInt(meta.config.allowMultipleBadges, 10) !== 1) {
+ if (!meta.config.allowMultipleBadges) {
user.groupTitleArray = [user.groupTitleArray[0]];
}
}
diff --git a/src/user/digest.js b/src/user/digest.js
index 07bc7f1cde..f5940e911f 100644
--- a/src/user/digest.js
+++ b/src/user/digest.js
@@ -17,7 +17,7 @@ var Digest = module.exports;
Digest.execute = function (payload, callback) {
callback = callback || function () {};
- var digestsDisabled = parseInt(meta.config.disableEmailSubscriptions, 10) === 1;
+ var digestsDisabled = meta.config.disableEmailSubscriptions === 1;
if (digestsDisabled) {
winston.info('[user/jobs] Did not send digests (' + payload.interval + ') because subscription system is disabled.');
return callback();
diff --git a/src/user/email.js b/src/user/email.js
index 24559104a3..571d55f9fb 100644
--- a/src/user/email.js
+++ b/src/user/email.js
@@ -50,7 +50,7 @@ UserEmail.sendValidationEmail = function (uid, options, callback) {
var confirm_code = utils.generateUUID();
var confirm_link = nconf.get('url') + '/confirm/' + confirm_code;
- var emailInterval = meta.config.hasOwnProperty('emailConfirmInterval') ? parseInt(meta.config.emailConfirmInterval, 10) : 10;
+ var emailInterval = meta.config.emailConfirmInterval;
async.waterfall([
function (next) {
diff --git a/src/user/invite.js b/src/user/invite.js
index a7d6401982..84dd975001 100644
--- a/src/user/invite.js
+++ b/src/user/invite.js
@@ -60,7 +60,7 @@ module.exports = function (User) {
var token = utils.generateUUID();
var registerLink = nconf.get('url') + '/register?token=' + token + '&email=' + encodeURIComponent(email);
- var expireDays = (parseInt(meta.config.inviteExpiration, 10) || 7);
+ var expireDays = meta.config.inviteExpiration;
var expireIn = expireDays * 86400000;
async.waterfall([
diff --git a/src/user/jobs.js b/src/user/jobs.js
index b519c22a9c..ccdadb146d 100644
--- a/src/user/jobs.js
+++ b/src/user/jobs.js
@@ -12,7 +12,7 @@ module.exports = function (User) {
winston.verbose('[user/jobs] (Re-)starting user jobs...');
var started = 0;
- var digestHour = parseInt(meta.config.digestHour, 10);
+ var digestHour = meta.config.digestHour;
// Fix digest hour if invalid
if (isNaN(digestHour)) {
diff --git a/src/user/picture.js b/src/user/picture.js
index d39bce659d..caae45e3e9 100644
--- a/src/user/picture.js
+++ b/src/user/picture.js
@@ -38,8 +38,7 @@ module.exports = function (User) {
async.waterfall([
function (next) {
var size = data.file ? data.file.size : image.sizeFromBase64(data.imageData);
- meta.config.maximumCoverImageSize = meta.config.maximumCoverImageSize || 2048;
- if (size > parseInt(meta.config.maximumCoverImageSize, 10) * 1024) {
+ if (size > meta.config.maximumCoverImageSize * 1024) {
return next(new Error('[[error:file-too-big, ' + meta.config.maximumCoverImageSize + ']]'));
}
@@ -81,7 +80,7 @@ module.exports = function (User) {
};
User.uploadCroppedPicture = function (data, callback) {
- if (parseInt(meta.config.allowProfileImageUploads, 10) !== 1) {
+ if (!meta.config.allowProfileImageUploads) {
return callback(new Error('[[error:profile-image-uploads-disabled]]'));
}
@@ -90,7 +89,7 @@ module.exports = function (User) {
}
var size = data.file ? data.file.size : image.sizeFromBase64(data.imageData);
- var uploadSize = parseInt(meta.config.maximumProfileImageSize, 10) || 256;
+ var uploadSize = meta.config.maximumProfileImageSize;
if (size > uploadSize * 1024) {
return callback(new Error('[[error:file-too-big, ' + uploadSize + ']]'));
}
@@ -123,11 +122,10 @@ module.exports = function (User) {
},
function (path, next) {
picture.path = path;
- var imageDimension = parseInt(meta.config.profileImageDimension, 10) || 200;
image.resizeImage({
path: picture.path,
- width: imageDimension,
- height: imageDimension,
+ width: meta.config.profileImageDimension,
+ height: meta.config.profileImageDimension,
}, next);
},
function (next) {
@@ -149,7 +147,7 @@ module.exports = function (User) {
};
function convertToPNG(path, extension, callback) {
- var convertToPNG = parseInt(meta.config['profile:convertProfileImageToPNG'], 10) === 1;
+ var convertToPNG = meta.config['profile:convertProfileImageToPNG'] === 1;
if (!convertToPNG) {
return setImmediate(callback, null, path);
}
@@ -176,8 +174,8 @@ module.exports = function (User) {
}
function generateProfileImageFilename(uid, type, extension) {
- var keepAllVersions = parseInt(meta.config['profile:keepAllUserImages'], 10) === 1;
- var convertToPNG = parseInt(meta.config['profile:convertProfileImageToPNG'], 10) === 1;
+ var keepAllVersions = meta.config['profile:keepAllUserImages'] === 1;
+ var convertToPNG = meta.config['profile:convertProfileImageToPNG'] === 1;
return uid + '-' + type + (keepAllVersions ? '-' + Date.now() : '') + (convertToPNG ? '.png' : extension);
}
diff --git a/src/user/posts.js b/src/user/posts.js
index 419747b276..cda65a5f85 100644
--- a/src/user/posts.js
+++ b/src/user/posts.js
@@ -44,20 +44,20 @@ module.exports = function (User) {
return next(new Error('[[error:user-banned]]'));
}
- if (parseInt(meta.config.requireEmailConfirmation, 10) === 1 && parseInt(userData['email:confirmed'], 10) !== 1) {
+ if (meta.config.requireEmailConfirmation && !userData['email:confirmed']) {
return next(new Error('[[error:email-not-confirmed]]'));
}
var now = Date.now();
- if (now - parseInt(userData.joindate, 10) < parseInt(meta.config.initialPostDelay, 10) * 1000) {
+ if (now - userData.joindate < meta.config.initialPostDelay * 1000) {
return next(new Error('[[error:user-too-new, ' + meta.config.initialPostDelay + ']]'));
}
var lasttime = userData[field] || 0;
- if (parseInt(meta.config.newbiePostDelay, 10) > 0 && parseInt(meta.config.newbiePostDelayThreshold, 10) > parseInt(userData.reputation, 10) && now - parseInt(lasttime, 10) < parseInt(meta.config.newbiePostDelay, 10) * 1000) {
+ if (meta.config.newbiePostDelay > 0 && meta.config.newbiePostDelayThreshold > userData.reputation && now - lasttime < meta.config.newbiePostDelay * 1000) {
return next(new Error('[[error:too-many-posts-newbie, ' + meta.config.newbiePostDelay + ', ' + meta.config.newbiePostDelayThreshold + ']]'));
- } else if (now - parseInt(lasttime, 10) < parseInt(meta.config.postDelay, 10) * 1000) {
+ } else if (now - lasttime < meta.config.postDelay * 1000) {
return next(new Error('[[error:too-many-posts, ' + meta.config.postDelay + ']]'));
}
diff --git a/src/user/profile.js b/src/user/profile.js
index 6f2d3252b5..6b9cb78eef 100644
--- a/src/user/profile.js
+++ b/src/user/profile.js
@@ -168,7 +168,7 @@ module.exports = function (User) {
User.checkMinReputation = function (callerUid, uid, setting, callback) {
var isSelf = parseInt(callerUid, 10) === parseInt(uid, 10);
- if (!isSelf || parseInt(meta.config['reputation:disabled'], 10) === 1) {
+ if (!isSelf || meta.config['reputation:disabled']) {
return setImmediate(callback);
}
async.waterfall([
@@ -176,7 +176,7 @@ module.exports = function (User) {
User.getUserField(uid, 'reputation', next);
},
function (reputation, next) {
- if (parseInt(reputation, 10) < (parseInt(meta.config[setting], 10) || 0)) {
+ if (reputation < meta.config[setting]) {
return next(new Error('[[error:not-enough-reputation-' + setting.replace(/:/g, '-') + ']]'));
}
next();
@@ -218,7 +218,7 @@ module.exports = function (User) {
User.setUserField(uid, 'email', newEmail, next);
},
function (next) {
- if (parseInt(meta.config.requireEmailConfirmation, 10) === 1 && newEmail) {
+ if (meta.config.requireEmailConfirmation && newEmail) {
User.email.sendValidationEmail(uid, {
email: newEmail,
subject: '[[email:email.verify-your-email.subject]]',
diff --git a/src/user/reset.js b/src/user/reset.js
index c287776ec5..4dc76a8c16 100644
--- a/src/user/reset.js
+++ b/src/user/reset.js
@@ -138,7 +138,7 @@ UserReset.commit = function (code, password, callback) {
UserReset.updateExpiry = function (uid, callback) {
var oneDay = 1000 * 60 * 60 * 24;
- var expireDays = parseInt(meta.config.passwordExpiryDays || 0, 10);
+ var expireDays = meta.config.passwordExpiryDays;
var expiry = Date.now() + (oneDay * expireDays);
callback = callback || function () {};
diff --git a/src/user/search.js b/src/user/search.js
index 68f6afde62..891e41de13 100644
--- a/src/user/search.js
+++ b/src/user/search.js
@@ -39,7 +39,7 @@ module.exports = function (User) {
searchResult.matchCount = uids.length;
if (paginate) {
- var resultsPerPage = parseInt(meta.config.userSearchResultsPerPage, 10) || 20;
+ var resultsPerPage = meta.config.userSearchResultsPerPage;
var start = Math.max(0, page - 1) * resultsPerPage;
var stop = start + resultsPerPage;
searchResult.pageCount = Math.ceil(uids.length / resultsPerPage);
@@ -64,7 +64,7 @@ module.exports = function (User) {
var min = query;
var max = query.substr(0, query.length - 1) + String.fromCharCode(query.charCodeAt(query.length - 1) + 1);
- var resultsPerPage = parseInt(meta.config.userSearchResultsPerPage, 10) || 20;
+ var resultsPerPage = meta.config.userSearchResultsPerPage;
hardCap = hardCap || resultsPerPage * 10;
async.waterfall([
diff --git a/src/user/settings.js b/src/user/settings.js
index 9d8307b475..ec4ecb46d4 100644
--- a/src/user/settings.js
+++ b/src/user/settings.js
@@ -31,9 +31,7 @@ module.exports = function (User) {
return callback(null, []);
}
- var keys = uids.map(function (uid) {
- return 'user:' + uid + ':settings';
- });
+ var keys = uids.map(uid => 'user:' + uid + ':settings');
async.waterfall([
function (next) {
@@ -60,8 +58,8 @@ module.exports = function (User) {
function (data, next) {
settings = data.settings;
- var defaultTopicsPerPage = parseInt(meta.config.topicsPerPage, 10) || 20;
- var defaultPostsPerPage = parseInt(meta.config.postsPerPage, 10) || 20;
+ var defaultTopicsPerPage = meta.config.topicsPerPage;
+ var defaultPostsPerPage = meta.config.postsPerPage;
settings.showemail = parseInt(getSetting(settings, 'showemail', 0), 10) === 1;
settings.showfullname = parseInt(getSetting(settings, 'showfullname', 0), 10) === 1;
diff --git a/src/webserver.js b/src/webserver.js
index a5d3d5e6fb..4a094a7b43 100644
--- a/src/webserver.js
+++ b/src/webserver.js
@@ -179,12 +179,11 @@ function setupExpressApp(app, callback) {
}));
var hsts_option = {
- maxAge: parseInt(meta.config['hsts-maxage'], 10) || 31536000,
- includeSubdomains: !!parseInt(meta.config['hsts-subdomains'], 10),
- preload: !!parseInt(meta.config['hsts-preload'], 10),
+ maxAge: meta.config['hsts-maxage'],
+ includeSubdomains: !!meta.config['hsts-subdomains'],
+ preload: !!meta.config['hsts-preload'],
setIf: function () {
- // If not set, default to on - previous and recommended behavior
- return meta.config['hsts-enabled'] === undefined || !!parseInt(meta.config['hsts-enabled'], 10);
+ return !!meta.config['hsts-enabled'];
},
};
app.use(helmet({
@@ -196,8 +195,8 @@ function setupExpressApp(app, callback) {
auth.initialize(app, middleware);
var toobusy = require('toobusy-js');
- toobusy.maxLag(parseInt(meta.config.eventLoopLagThreshold, 10) || 100);
- toobusy.interval(parseInt(meta.config.eventLoopInterval, 10) || 500);
+ toobusy.maxLag(meta.config.eventLoopLagThreshold);
+ toobusy.interval(meta.config.eventLoopInterval);
setupAutoLocale(app, callback);
}
@@ -246,7 +245,7 @@ function setupAutoLocale(app, callback) {
});
app.use(function (req, res, next) {
- if (parseInt(req.uid, 10) > 0 || parseInt(meta.config.autoDetectLang, 10) !== 1) {
+ if (parseInt(req.uid, 10) > 0 || !meta.config.autoDetectLang) {
return next();
}
diff --git a/test/meta.js b/test/meta.js
index 5fe417ca2f..c5024acb17 100644
--- a/test/meta.js
+++ b/test/meta.js
@@ -105,8 +105,8 @@ describe('meta', function () {
it('should get config fields', function (done) {
meta.configs.getFields(['minimumTagLength', 'maximumTagLength'], function (err, data) {
assert.ifError(err);
- assert.equal(data.minimumTagLength, 3);
- assert.equal(data.maximumTagLength, 15);
+ assert.strictEqual(data.minimumTagLength, 3);
+ assert.strictEqual(data.maximumTagLength, 15);
done();
});
});
@@ -125,7 +125,7 @@ describe('meta', function () {
});
});
- it('should set single config value', function (done) {
+ it('should set multiple config values', function (done) {
socketAdmin.config.set({ uid: fooUid }, { key: 'someKey', value: 'someValue' }, function (err) {
assert.ifError(err);
meta.configs.getFields(['someKey'], function (err, data) {
@@ -141,7 +141,51 @@ describe('meta', function () {
assert.ifError(err);
meta.configs.getFields(['someField'], function (err, data) {
assert.ifError(err);
- assert.equal(data.someField, 'someValue');
+ assert.strictEqual(data.someField, 'someValue');
+ done();
+ });
+ });
+ });
+
+ it('should set numeric config value', function (done) {
+ meta.configs.set('numericField', 123, function (err) {
+ assert.ifError(err);
+ meta.configs.getFields(['numericField'], function (err, data) {
+ assert.ifError(err);
+ assert.strictEqual(data.numericField, 123);
+ done();
+ });
+ });
+ });
+
+ it('should set boolean config value', function (done) {
+ meta.configs.set('booleanField', true, function (err) {
+ assert.ifError(err);
+ meta.configs.getFields(['booleanField'], function (err, data) {
+ assert.ifError(err);
+ assert.strictEqual(data.booleanField, true);
+ done();
+ });
+ });
+ });
+
+ it('should set boolean config value', function (done) {
+ meta.configs.set('booleanField', 'true', function (err) {
+ assert.ifError(err);
+ meta.configs.getFields(['booleanField'], function (err, data) {
+ assert.ifError(err);
+ assert.strictEqual(data.booleanField, true);
+ done();
+ });
+ });
+ });
+
+ it('should set string config value', function (done) {
+ meta.configs.set('stringField', '123', function (err) {
+ assert.ifError(err);
+ meta.configs.getFields(['stringField'], function (err, data) {
+ assert.ifError(err);
+ assert.strictEqual(data.stringField, 123);
done();
});
});
@@ -173,7 +217,7 @@ describe('meta', function () {
it('should not set config if not empty', function (done) {
meta.configs.setOnEmpty({ someField1: 'foo' }, function (err) {
assert.ifError(err);
- db.getObjectField('config', 'someField1', function (err, value) {
+ meta.configs.get('someField1', function (err, value) {
assert.ifError(err);
assert.equal(value, 'someValue1');
done();
diff --git a/test/mocks/databasemock.js b/test/mocks/databasemock.js
index bf9416ae62..c692d67883 100644
--- a/test/mocks/databasemock.js
+++ b/test/mocks/databasemock.js
@@ -224,6 +224,7 @@ function setupDefaultConfigs(meta, next) {
var defaults = require(path.join(nconf.get('base_dir'), 'install/data/defaults.json'));
defaults.eventLoopCheckEnabled = 0;
+ defaults.minimumPasswordStrength = 0;
meta.configs.setOnEmpty(defaults, next);
}
diff --git a/test/posts.js b/test/posts.js
index fa029c26cb..af11c52e9b 100644
--- a/test/posts.js
+++ b/test/posts.js
@@ -364,7 +364,7 @@ describe('Post\'s', function () {
});
it('should error if title is too long', function (done) {
- var longTitle = new Array(parseInt(meta.config.maximumTitleLength, 10) + 2).join('a');
+ var longTitle = new Array(meta.config.maximumTitleLength + 2).join('a');
socketPosts.edit({ uid: voterUid }, { pid: pid, content: 'edited post content', title: longTitle }, function (err) {
assert.equal(err.message, '[[error:title-too-long, ' + meta.config.maximumTitleLength + ']]');
done();
@@ -400,7 +400,7 @@ describe('Post\'s', function () {
});
it('should error if content is too long', function (done) {
- var longContent = new Array(parseInt(meta.config.maximumPostLength, 10) + 2).join('a');
+ var longContent = new Array(meta.config.maximumPostLength + 2).join('a');
socketPosts.edit({ uid: voterUid }, { pid: pid, content: longContent }, function (err) {
assert.equal(err.message, '[[error:content-too-long, ' + meta.config.maximumPostLength + ']]');
done();
diff --git a/test/user.js b/test/user.js
index 6a0b961279..b5ae9c11dc 100644
--- a/test/user.js
+++ b/test/user.js
@@ -552,7 +552,8 @@ describe('User', function () {
assert(!userData.hasOwnProperty('another_secret'));
assert(!userData.hasOwnProperty('password'));
assert(!userData.hasOwnProperty('rss_token'));
- assert.equal(userData.postcount, '123');
+ assert.strictEqual(userData.postcount, 123);
+ assert.strictEqual(userData.uid, testUid);
done();
});
});