misc fixes

handle spider uids properly
v1.18.x
Barış Soner Uşaklı 6 years ago
parent afa84023a2
commit 69bb3293ee

@ -110,6 +110,7 @@
"hsts-subdomains": 0,
"hsts-preload": 0,
"hsts-enabled": 0,
"eventLoopCheckEnabled": 1,
"eventLoopLagThreshold": 100,
"eventLoopInterval": 500,
"onlineCutoff": 30

@ -513,7 +513,7 @@
timestamp = Math.min(timestamp, 8640000000000000);
try {
return Date.prototype.toISOString ? new Date(parseInt(timestamp, 10)).toISOString() : timestamp;
return new Date(parseInt(timestamp, 10)).toISOString();
} catch (e) {
return timestamp;
}

@ -84,7 +84,7 @@ userController.getUserDataByField = function (callerUid, field, fieldValue, call
};
userController.getUserDataByUID = function (callerUid, uid, callback) {
if (!parseInt(callerUid, 10) && meta.config.privateUserInfo) {
if (parseInt(callerUid, 10) <= 0 && meta.config.privateUserInfo) {
return callback(new Error('[[error:no-privileges]]'));
}

@ -7,14 +7,14 @@ var sockets = require('../socket.io');
module.exports = function (Messaging) {
Messaging.getUnreadCount = function (uid, callback) {
if (!parseInt(uid, 10)) {
return callback(null, 0);
if (parseInt(uid, 10) <= 0) {
return setImmediate(callback, null, 0);
}
db.sortedSetCard('uid:' + uid + ':chat:rooms:unread', callback);
};
Messaging.pushUnreadCount = function (uid) {
if (!parseInt(uid, 10)) {
if (parseInt(uid, 10) <= 0) {
return;
}
Messaging.getUnreadCount(uid, function (err, unreadCount) {

@ -62,10 +62,10 @@ middleware.pageView = function (req, res, next) {
user.updateOnlineUsers(req.uid, next);
} else {
user.updateOnlineUsers(req.uid);
next();
setImmediate(next);
}
} else {
next();
setImmediate(next);
}
};
@ -156,11 +156,11 @@ middleware.privateUploads = function (req, res, next) {
};
middleware.busyCheck = function (req, res, next) {
if (global.env === 'production' && (!meta.config.hasOwnProperty('eventLoopCheckEnabled') || meta.config.eventLoopCheckEnabled) && toobusy()) {
if (global.env === 'production' && meta.config.eventLoopCheckEnabled && toobusy()) {
analytics.increment('errors:503');
res.status(503).type('text/html').sendFile(path.join(__dirname, '../../public/503.html'));
} else {
next();
setImmediate(next);
}
};

@ -8,12 +8,12 @@ var user = require('../user');
module.exports = function (middleware) {
middleware.maintenanceMode = function (req, res, callback) {
if (!meta.config.maintenanceMode) {
return callback();
return setImmediate(callback);
}
var url = req.url.replace(nconf.get('relative_path'), '');
if (url.startsWith('/login') || url.startsWith('/api/login')) {
return callback();
return setImmediate(callback);
}
var data;
async.waterfall([

@ -226,7 +226,7 @@ module.exports = function (middleware) {
middleware.registrationComplete = function (req, res, next) {
// If the user's session contains registration data, redirect the user to complete registration
if (!req.session.hasOwnProperty('registration')) {
return next();
return setImmediate(next);
}
if (!req.path.endsWith('/register/complete')) {
// Append user data if present
@ -234,7 +234,7 @@ module.exports = function (middleware) {
controllers.helpers.redirect(res, '/register/complete');
} else {
return next();
return setImmediate(next);
}
};
};

@ -357,16 +357,16 @@ Notifications.rescind = function (nid, callback) {
Notifications.markRead = function (nid, uid, callback) {
callback = callback || function () {};
if (!parseInt(uid, 10) || !nid) {
return callback();
if (parseInt(uid, 10) <= 0 || !nid) {
return setImmediate(callback);
}
Notifications.markReadMultiple([nid], uid, callback);
};
Notifications.markUnread = function (nid, uid, callback) {
callback = callback || function () {};
if (!parseInt(uid, 10) || !nid) {
return callback();
if (parseInt(uid, 10) <= 0 || !nid) {
return setImmediate(callback);
}
async.waterfall([
function (next) {

@ -15,7 +15,7 @@ module.exports = function (Posts) {
};
function toggleBookmark(type, pid, uid, callback) {
if (!parseInt(uid, 10)) {
if (parseInt(uid, 10) <= 0) {
return callback(new Error('[[error:not-logged-in]]'));
}
@ -85,9 +85,9 @@ module.exports = function (Posts) {
}
Posts.hasBookmarked = function (pid, uid, callback) {
if (!parseInt(uid, 10)) {
if (parseInt(uid, 10) <= 0) {
if (Array.isArray(pid)) {
callback(null, pid.map(function () { return false; }));
callback(null, pid.map(() => false));
} else {
callback(null, false);
}
@ -95,10 +95,7 @@ module.exports = function (Posts) {
}
if (Array.isArray(pid)) {
var sets = pid.map(function (pid) {
return 'pid:' + pid + ':users_bookmarked';
});
var sets = pid.map(pid => 'pid:' + pid + ':users_bookmarked');
db.isMemberOfSets(sets, uid, callback);
} else {
db.isSetMember('pid:' + pid + ':users_bookmarked', uid, callback);

@ -35,7 +35,7 @@ Posts.exists = function (pid, callback) {
Posts.getPidsFromSet = function (set, start, stop, reverse, callback) {
if (isNaN(start) || isNaN(stop)) {
return callback(null, []);
return setImmediate(callback, null, []);
}
db[reverse ? 'getSortedSetRevRange' : 'getSortedSetRange'](set, start, stop, callback);
};

@ -144,8 +144,8 @@ module.exports = function (Posts) {
};
Posts.isModerator = function (pids, uid, callback) {
if (!parseInt(uid, 10)) {
return callback(null, pids.map(function () { return false; }));
if (parseInt(uid, 10) <= 0) {
return setImmediate(callback, null, pids.map(() => false));
}
Posts.getCidsByPids(pids, function (err, cids) {
if (err) {

@ -85,8 +85,8 @@ module.exports = function (Posts) {
};
Posts.hasVoted = function (pid, uid, callback) {
if (!parseInt(uid, 10)) {
return callback(null, { upvoted: false, downvoted: false });
if (parseInt(uid, 10) <= 0) {
return setImmediate(callback, null, { upvoted: false, downvoted: false });
}
async.waterfall([
function (next) {
@ -99,9 +99,9 @@ module.exports = function (Posts) {
};
Posts.getVoteStatusByPostIDs = function (pids, uid, callback) {
if (!parseInt(uid, 10)) {
var data = pids.map(function () { return false; });
return callback(null, { upvotes: data, downvotes: data });
if (parseInt(uid, 10) <= 0) {
var data = pids.map(() => false);
return setImmediate(callback, null, { upvotes: data, downvotes: data });
}
var upvoteSets = [];
var downvoteSets = [];
@ -110,15 +110,17 @@ module.exports = function (Posts) {
upvoteSets.push('pid:' + pids[i] + ':upvote');
downvoteSets.push('pid:' + pids[i] + ':downvote');
}
async.parallel({
upvotes: function (next) {
db.isMemberOfSets(upvoteSets, uid, next);
async.waterfall([
function (next) {
db.isMemberOfSets(upvoteSets.concat(downvoteSets), uid, next);
},
downvotes: function (next) {
db.isMemberOfSets(downvoteSets, uid, next);
function (data, next) {
next(null, {
upvotes: data.slice(0, pids.length),
downvotes: data.slice(pids.length, pids.length * 2),
});
},
}, callback);
], callback);
};
Posts.getUpvotedUidsByPids = function (pids, callback) {

@ -76,8 +76,8 @@ module.exports = function (privileges) {
};
privileges.categories.isAdminOrMod = function (cid, uid, callback) {
if (!parseInt(uid, 10)) {
return callback(null, false);
if (parseInt(uid, 10) <= 0) {
return setImmediate(callback, null, false);
}
helpers.some([
function (next) {

@ -17,7 +17,11 @@ module.exports = function (privileges) {
privileges.topics.get = function (tid, uid, callback) {
uid = parseInt(uid, 10);
var topic;
var privs = ['topics:reply', 'topics:read', 'topics:tag', 'topics:delete', 'posts:edit', 'posts:history', 'posts:delete', 'posts:view_deleted', 'read', 'purge'];
var privs = [
'topics:reply', 'topics:read', 'topics:tag',
'topics:delete', 'posts:edit', 'posts:history',
'posts:delete', 'posts:view_deleted', 'read', 'purge',
];
async.waterfall([
async.apply(topics.getTopicFields, tid, ['cid', 'uid', 'locked', 'deleted']),
function (_topic, next) {

@ -38,7 +38,7 @@ module.exports = function (privileges) {
};
function isModeratorOfCategories(cids, uid, callback) {
if (!parseInt(uid, 10)) {
if (parseInt(uid, 10) <= 0) {
return filterIsModerator(cids, uid, cids.map(function () { return false; }), callback);
}
var uniqueCids;

@ -10,7 +10,7 @@ social.postSharing = null;
social.getPostSharing = function (callback) {
if (social.postSharing) {
return callback(null, social.postSharing);
return setImmediate(callback, null, social.postSharing);
}
var networks = [
@ -55,9 +55,7 @@ social.getActivePostSharing = function (callback) {
social.getPostSharing(next);
},
function (networks, next) {
networks = networks.filter(function (network) {
return network && network.activated;
});
networks = networks.filter(network => network && network.activated);
next(null, networks);
},
], callback);

@ -180,6 +180,9 @@ SocketAdmin.config.setMultiple = function (socket, data, callback) {
var changes = {};
Object.keys(data).forEach(function (key) {
if (typeof meta.config[key] === 'number') {
data[key] = parseInt(data[key], 10);
}
if (data[key] !== meta.config[key]) {
changes[key] = data[key];
changes[key + '_old'] = meta.config[key];

@ -19,7 +19,7 @@ SocketGroups.before = function (socket, method, data, next) {
};
SocketGroups.join = function (socket, data, callback) {
if (!parseInt(socket.uid, 10)) {
if (socket.uid <= 0) {
return callback(new Error('[[error:invalid-uid]]'));
}
@ -60,7 +60,7 @@ SocketGroups.join = function (socket, data, callback) {
};
SocketGroups.leave = function (socket, data, callback) {
if (!parseInt(socket.uid, 10)) {
if (socket.uid <= 0) {
return callback(new Error('[[error:invalid-uid]]'));
}

@ -8,21 +8,17 @@ var user = require('../user');
module.exports = function (Topics) {
Topics.getUserBookmark = function (tid, uid, callback) {
if (!parseInt(uid, 10)) {
if (parseInt(uid, 10) <= 0) {
return callback(null, null);
}
db.sortedSetScore('tid:' + tid + ':bookmarks', uid, callback);
};
Topics.getUserBookmarks = function (tids, uid, callback) {
if (!parseInt(uid, 10)) {
return callback(null, tids.map(function () {
return null;
}));
if (parseInt(uid, 10) <= 0) {
return callback(null, tids.map(() => null));
}
db.sortedSetsScore(tids.map(function (tid) {
return 'tid:' + tid + ':bookmarks';
}), uid, callback);
db.sortedSetsScore(tids.map(tid => 'tid:' + tid + ':bookmarks'), uid, callback);
};
Topics.setUserBookmark = function (tid, uid, index, callback) {

@ -90,7 +90,7 @@ module.exports = function (Topics) {
function escapeTitle(topicData) {
if (topicData) {
if (topicData.title) {
topicData.title = translator.escape(validator.escape(String(topicData.title)));
topicData.title = translator.escape(validator.escape(topicData.title));
}
if (topicData.titleRaw) {
topicData.titleRaw = translator.escape(topicData.titleRaw);

@ -52,8 +52,8 @@ module.exports = function (Topics) {
function setWatching(method1, method2, hook, tid, uid, callback) {
callback = callback || function () {};
if (!parseInt(uid, 10)) {
return callback();
if (parseInt(uid, 10) <= 0) {
return setImmediate(callback);
}
async.waterfall([
function (next) {
@ -121,16 +121,41 @@ module.exports = function (Topics) {
isIgnoringOrFollowing('ignorers', tids, uid, callback);
};
function isIgnoringOrFollowing(set, tids, uid, callback) {
Topics.getFollowData = function (tids, uid, callback) {
if (!Array.isArray(tids)) {
return callback();
return setImmediate(callback);
}
if (!parseInt(uid, 10)) {
return callback(null, tids.map(function () { return false; }));
if (parseInt(uid, 10) <= 0) {
return setImmediate(callback, null, tids.map(() => ({ following: false, ignoring: false })));
}
var keys = tids.map(function (tid) {
return 'tid:' + tid + ':' + set;
const keys = [];
tids.forEach((tid) => {
keys.push('tid:' + tid + ':followers', 'tid:' + tid + ':ignorers');
});
db.isMemberOfSets(keys, uid, function (err, data) {
if (err) {
return callback(err);
}
const followData = [];
for (let i = 0; i < data.length; i += 2) {
followData.push({
following: data[i],
ignoring: data[i + 1],
});
}
callback(null, followData);
});
};
function isIgnoringOrFollowing(set, tids, uid, callback) {
if (!Array.isArray(tids)) {
return setImmediate(callback);
}
if (parseInt(uid, 10) <= 0) {
return setImmediate(callback, null, tids.map(() => false));
}
var keys = tids.map(tid => 'tid:' + tid + ':' + set);
db.isMemberOfSets(keys, uid, callback);
}

@ -159,8 +159,7 @@ Topics.getTopicWithPosts = function (topicData, set, uid, start, stop, reverse,
category: async.apply(categories.getCategoryData, topicData.cid),
tagWhitelist: async.apply(categories.getTagWhitelist, [topicData.cid]),
threadTools: async.apply(plugins.fireHook, 'filter:topic.thread_tools', { topic: topicData, uid: uid, tools: [] }),
isFollowing: async.apply(Topics.isFollowing, [topicData.tid], uid),
isIgnoring: async.apply(Topics.isIgnoring, [topicData.tid], uid),
followData: async.apply(Topics.getFollowData, [topicData.tid], uid),
bookmark: async.apply(Topics.getUserBookmark, topicData.tid, uid),
postSharing: async.apply(social.getActivePostSharing),
deleter: async.apply(getDeleter, topicData),
@ -183,9 +182,9 @@ Topics.getTopicWithPosts = function (topicData, set, uid, start, stop, reverse,
topicData.category = results.category;
topicData.tagWhitelist = results.tagWhitelist[0];
topicData.thread_tools = results.threadTools.tools;
topicData.isFollowing = results.isFollowing[0];
topicData.isNotFollowing = !results.isFollowing[0] && !results.isIgnoring[0];
topicData.isIgnoring = results.isIgnoring[0];
topicData.isFollowing = results.followData[0].following;
topicData.isNotFollowing = !results.followData[0].following && !results.followData[0].ignoring;
topicData.isIgnoring = results.followData[0].ignoring;
topicData.bookmark = results.bookmark;
topicData.postSharing = results.postSharing;
topicData.deleter = results.deleter;

@ -63,6 +63,7 @@ module.exports = function (Topics) {
}
});
const uids = Object.keys(uidsMap);
async.waterfall([
function (next) {
method(uids, next);
@ -110,7 +111,7 @@ module.exports = function (Topics) {
postObj.downvoted = results.voteData.downvotes[i];
postObj.votes = postObj.votes || 0;
postObj.replies = results.replies[i];
postObj.selfPost = !!parseInt(uid, 10) && parseInt(uid, 10) === postObj.uid;
postObj.selfPost = parseInt(uid, 10) > 0 && parseInt(uid, 10) === postObj.uid;
// Username override for guests, if enabled
if (meta.config.allowGuestHandles && postObj.uid === 0 && postObj.handle) {
@ -130,7 +131,7 @@ module.exports = function (Topics) {
};
Topics.modifyPostsByPrivilege = function (topicData, topicPrivileges) {
var loggedIn = !!parseInt(topicPrivileges.uid, 10);
var loggedIn = parseInt(topicPrivileges.uid, 10) > 0;
topicData.posts.forEach(function (post) {
if (post) {
post.display_edit_tools = topicPrivileges.isAdminOrMod || (post.selfPost && topicPrivileges['posts:edit']);
@ -151,7 +152,7 @@ module.exports = function (Topics) {
}).filter(Boolean);
if (!parentPids.length) {
return callback();
return setImmediate(callback);
}
var parentPosts;
@ -159,9 +160,7 @@ module.exports = function (Topics) {
async.apply(posts.getPostsFields, parentPids, ['uid']),
function (_parentPosts, next) {
parentPosts = _parentPosts;
var parentUids = _.uniq(parentPosts.map(function (postObj) {
return postObj && parseInt(postObj.uid, 10);
}));
var parentUids = _.uniq(parentPosts.map(postObj => postObj && postObj.uid));
user.getUsersFields(parentUids, ['username'], next);
},
@ -391,9 +390,7 @@ module.exports = function (Topics) {
var uniquePids;
async.waterfall([
function (next) {
var keys = pids.map(function (pid) {
return 'pid:' + pid + ':replies';
});
const keys = pids.map(pid => 'pid:' + pid + ':replies');
db.getSortedSetsMembers(keys, next);
},
function (arrayOfPids, next) {
@ -405,9 +402,7 @@ module.exports = function (Topics) {
},
function (_replyData, next) {
replyData = _replyData;
var uids = replyData.map(function (replyData) {
return replyData && replyData.uid;
});
const uids = replyData.map(replyData => replyData && replyData.uid);
uniqueUids = _.uniq(uids);

@ -277,9 +277,7 @@ module.exports = function (Topics) {
topicTags = _topicTags;
uniqueTopicTags = _.uniq(_.flatten(topicTags));
var tags = uniqueTopicTags.map(function (tag) {
return { value: tag };
});
var tags = uniqueTopicTags.map(tag => ({ value: tag }));
async.parallel({
tagData: function (next) {

@ -13,7 +13,7 @@ module.exports = function (User) {
User.auth = {};
User.auth.logAttempt = function (uid, ip, callback) {
if (!parseInt(uid, 10)) {
if (parseInt(uid, 10) <= 0) {
return setImmediate(callback);
}
async.waterfall([
@ -49,8 +49,8 @@ module.exports = function (User) {
};
User.auth.getFeedToken = function (uid, callback) {
if (!uid) {
return callback();
if (parseInt(uid, 10) <= 0) {
return setImmediate(callback);
}
var token;
async.waterfall([

@ -18,7 +18,7 @@ module.exports = function (User) {
var deletesInProgress = {};
User.delete = function (callerUid, uid, callback) {
if (!parseInt(uid, 10)) {
if (parseInt(uid, 10) <= 0) {
return setImmediate(callback, new Error('[[error:invalid-uid]]'));
}
if (deletesInProgress[uid]) {

@ -15,7 +15,7 @@ module.exports = function (User) {
};
function toggleFollow(type, uid, theiruid, callback) {
if (!parseInt(uid, 10) || !parseInt(theiruid, 10)) {
if (parseInt(uid, 10) <= 0 || parseInt(theiruid, 10) <= 0) {
return callback(new Error('[[error:invalid-uid]]'));
}
@ -71,8 +71,8 @@ module.exports = function (User) {
};
function getFollow(uid, type, start, stop, callback) {
if (!parseInt(uid, 10)) {
return callback(null, []);
if (parseInt(uid, 10) <= 0) {
return setImmediate(callback, null, []);
}
async.waterfall([
function (next) {
@ -93,8 +93,8 @@ module.exports = function (User) {
}
User.isFollowing = function (uid, theirid, callback) {
if (!parseInt(uid, 10) || !parseInt(theirid, 10)) {
return callback(null, false);
if (parseInt(uid, 10) <= 0 || parseInt(theirid, 10) <= 0) {
return setImmediate(callback, null, false);
}
db.isSortedSetMember('following:' + uid, theirid, callback);
};

@ -13,8 +13,8 @@ var utils = require('../utils');
var UserNotifications = module.exports;
UserNotifications.get = function (uid, callback) {
if (!parseInt(uid, 10)) {
return callback(null, { read: [], unread: [] });
if (parseInt(uid, 10) <= 0) {
return setImmediate(callback, null, { read: [], unread: [] });
}
async.waterfall([
function (next) {
@ -177,8 +177,8 @@ UserNotifications.getDailyUnread = function (uid, callback) {
};
UserNotifications.getUnreadCount = function (uid, callback) {
if (!parseInt(uid, 10)) {
return callback(null, 0);
if (parseInt(uid, 10) <= 0) {
return setImmediate(callback, null, 0);
}
async.waterfall([
@ -240,8 +240,8 @@ UserNotifications.getUnreadByField = function (uid, field, values, callback) {
};
UserNotifications.deleteAll = function (uid, callback) {
if (!parseInt(uid, 10)) {
return callback();
if (parseInt(uid, 10) <= 0) {
return setImmediate(callback);
}
async.parallel([
function (next) {

@ -94,7 +94,7 @@ module.exports = function (User) {
User.incrementUserFieldBy(uid, 'postcount', value, next);
},
function (newpostcount, next) {
if (!parseInt(uid, 10)) {
if (parseInt(uid, 10) <= 0) {
return next();
}
db.sortedSetAdd('users:postcount', newpostcount, uid, next);

@ -10,7 +10,7 @@ var notifications = require('../notifications');
module.exports = function (User) {
User.getSettings = function (uid, callback) {
if (!parseInt(uid, 10)) {
if (parseInt(uid, 10) <= 0) {
return onSettingsLoaded(0, {}, callback);
}
@ -181,7 +181,7 @@ module.exports = function (User) {
};
User.setSetting = function (uid, key, value, callback) {
if (!parseInt(uid, 10)) {
if (parseInt(uid, 10) <= 0) {
return setImmediate(callback);
}

Loading…
Cancel
Save