* Store config fields as JSON in the db

Fewer parseInts

* Remove unnecessary parseInts

* remove some dupe code add tests

* remove console.log

* remove more parseInts

* WIP: read meta.configs defaults from defaults.json

remove more parseInts

* more work

* add log for failing test

* update admin pwd

* fix tests, dont require posts/cache before configs are initialized

* handle saves

* Test boolean conditions

* remove more parseInts

* Fix boolean values

* remove lots more parseInts

* removed json parsing

* renamed var to number

* categories dont have timestamp
v1.18.x
Barış Soner Uşaklı 7 years ago committed by GitHub
parent 60c58870af
commit 9c022afae1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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\\\":\\\"test@example.org\\\",\\\"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\\\":\\\"test@example.org\\\",\\\"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\\\":\\\"test@example.org\\\",\\\"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\\\":\\\"test@example.org\\\",\\\"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\\\":\\\"test@example.org\\\",\\\"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\\\":\\\"test@example.org\\\",\\\"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

@ -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
}

@ -399,6 +399,7 @@
},
isNumber: function (n) {
// `isFinite('') === true` so isNan parseFloat check is necessary
return !isNaN(parseFloat(n)) && isFinite(n);
},

@ -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) {

@ -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();
}

@ -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 + ']]';

@ -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);
},

@ -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;
}

@ -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]]' }]);

@ -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);

@ -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);

@ -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);

@ -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;

@ -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);

@ -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 {

@ -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);

@ -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);
},

@ -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());

@ -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]]',

@ -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;

@ -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([

@ -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;

@ -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 + ']]'));
}

@ -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);
});

@ -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) {

@ -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]]'));
}

@ -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]]'));
}

@ -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]]'));
}

@ -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]]'));
}

@ -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] + ']]'));
}

@ -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);

@ -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;
};

@ -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);
};

@ -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);
},

@ -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;

@ -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 {

@ -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'), '');

@ -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)) {

@ -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,
});

@ -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;
}

@ -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) {

@ -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);
}

@ -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);

@ -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');
}

@ -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();

@ -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);

@ -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();
}

@ -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]]'));
}

@ -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);

@ -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 + ']]' :

@ -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));

@ -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;

@ -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]]'));
}

@ -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]]'));

@ -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) {

@ -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]]'));
}

@ -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);

@ -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 + ']]'));
}

@ -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);

@ -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);

@ -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([

@ -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;
}

@ -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;
}
});

@ -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]]'));
}

@ -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) {

@ -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 + ']]'));
}

@ -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));
}
}

@ -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);

@ -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, []);
}

@ -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) {

@ -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) {

@ -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

@ -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,
});

@ -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]];
}
}

@ -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();

@ -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) {

@ -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([

@ -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)) {

@ -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);
}

@ -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 + ']]'));
}

@ -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]]',

@ -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 () {};

@ -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([

@ -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;

@ -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();
}

@ -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();

@ -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);
}

@ -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();

@ -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();
});
});

Loading…
Cancel
Save