Compare commits

..

4 Commits

Author SHA1 Message Date
Barış Soner Uşaklı
bad359f308 fix: lint 2021-10-06 09:19:19 -04:00
Barış Soner Uşaklı
51b3bb4481 fix: tests 2021-10-06 09:18:36 -04:00
Barış Soner Uşaklı
00c6ddfdaf fix: keep query string on redirects 2021-10-06 09:18:05 -04:00
Barış Soner Uşaklı
e4344d31d9 feat: add userData to static:user.delete 2021-09-29 09:39:35 -04:00
2 changed files with 9 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
'use strict';
const nconf = require('nconf');
const qs = require('querystring');
const user = require('../user');
const meta = require('../meta');
@@ -58,7 +59,7 @@ topicsController.get = async function getTopic(req, res, callback) {
}
if (!res.locals.isAPI && (!req.params.slug || topicData.slug !== `${tid}/${req.params.slug}`) && (topicData.slug && topicData.slug !== `${tid}/`)) {
return helpers.redirect(res, `/topic/${topicData.slug}${postIndex ? `/${postIndex}` : ''}${currentPage > 1 ? `?page=${currentPage}` : ''}`, true);
return helpers.redirect(res, `/topic/${topicData.slug}${postIndex ? `/${postIndex}` : ''}${generateQueryString(req.query)}`, true);
}
if (postIndex === 'unread') {
@@ -66,7 +67,7 @@ topicsController.get = async function getTopic(req, res, callback) {
}
if (utils.isNumber(postIndex) && topicData.postcount > 0 && (postIndex < 1 || postIndex > topicData.postcount)) {
return helpers.redirect(res, `/topic/${req.params.topic_id}/${req.params.slug}${postIndex > topicData.postcount ? `/${topicData.postcount}` : ''}`);
return helpers.redirect(res, `/topic/${tid}/${req.params.slug}${postIndex > topicData.postcount ? `/${topicData.postcount}` : ''}${generateQueryString(req.query)}`);
}
postIndex = Math.max(1, postIndex);
const sort = req.query.sort || settings.topicPostSort;
@@ -120,6 +121,11 @@ topicsController.get = async function getTopic(req, res, callback) {
res.render('topic', topicData);
};
function generateQueryString(query) {
const qString = qs.stringify(query);
return qString.length ? `?${qString}` : '';
}
function calculatePageFromIndex(postIndex, settings) {
return 1 + Math.floor((postIndex - 1) / settings.postsPerPage);
}

View File

@@ -105,7 +105,7 @@ module.exports = function (User) {
throw new Error('[[error:no-user]]');
}
await plugins.hooks.fire('static:user.delete', { uid: uid });
await plugins.hooks.fire('static:user.delete', { uid: uid, userData: userData });
await deleteVotes(uid);
await deleteChats(uid);
await User.auth.revokeAllSessions(uid);