Compare commits

..

2 Commits

Author SHA1 Message Date
Julian Lam
dc6fc65322 chore: bump version 2021-03-24 12:56:05 -04:00
Barış Soner Uşaklı
27b481765b fix: #9420, paginate after loading notifications 2021-03-24 12:54:47 -04:00
26 changed files with 154 additions and 379 deletions

View File

@@ -2,7 +2,7 @@
"name": "nodebb",
"license": "GPL-3.0",
"description": "NodeBB Forum",
"version": "1.16.2",
"version": "1.16.2-beta.1",
"homepage": "http://www.nodebb.org",
"repository": {
"type": "git",
@@ -43,7 +43,7 @@
"bcryptjs": "2.4.3",
"benchpressjs": "2.4.0",
"body-parser": "^1.19.0",
"bootbox": "5.5.2",
"bootbox": "4.4.0",
"bootstrap": "^3.4.1",
"chart.js": "^2.9.3",
"cli-graph": "^3.2.2",
@@ -101,7 +101,7 @@
"nodebb-plugin-spam-be-gone": "0.7.7",
"nodebb-rewards-essentials": "0.1.4",
"nodebb-theme-lavender": "5.0.17",
"nodebb-theme-persona": "10.3.19",
"nodebb-theme-persona": "10.3.18",
"nodebb-theme-slick": "1.3.8",
"nodebb-theme-vanilla": "11.3.10",
"nodebb-widget-essentials": "5.0.2",
@@ -154,12 +154,12 @@
"@commitlint/cli": "11.0.0",
"@commitlint/config-angular": "11.0.0",
"coveralls": "3.1.0",
"eslint": "7.18.0",
"eslint": "7.17.0",
"eslint-config-airbnb-base": "14.2.1",
"eslint-plugin-import": "2.22.1",
"grunt": "1.3.0",
"grunt-contrib-watch": "1.1.0",
"husky": "4.3.8",
"husky": "4.3.7",
"jsdom": "16.4.0",
"lint-staged": "10.5.3",
"mocha": "8.2.1",
@@ -190,4 +190,4 @@
"url": "https://github.com/barisusakli"
}
]
}
}

View File

@@ -13,7 +13,7 @@
"filter-active": "Ci sono uno o più filtri attivi in questa lista di segnalazioni",
"filter-reset": "Rimuovi Filtri",
"filters": "Opzioni Filtri",
"filter-reporterId": "UID segnalatore",
"filter-reporterId": "Segnalatore UID",
"filter-targetUid": "UID segnalato",
"filter-type": "Tipo Segnalazione",
"filter-type-all": "Tutto il Contenuto",

View File

@@ -104,16 +104,10 @@ paths:
$ref: 'write/posts/pid.yaml'
/posts/{pid}/state:
$ref: 'write/posts/pid/state.yaml'
/posts/{pid}/move:
$ref: 'write/posts/pid/move.yaml'
/posts/{pid}/vote:
$ref: 'write/posts/pid/vote.yaml'
/posts/{pid}/bookmark:
$ref: 'write/posts/pid/bookmark.yaml'
/posts/{pid}/diffs:
$ref: 'write/posts/pid/diffs.yaml'
/posts/{pid}/diffs/{since}:
$ref: 'write/posts/pid/diffs/since.yaml'
/admin/settings/{setting}:
$ref: 'write/admin/settings/setting.yaml'
/files/:

View File

@@ -1,41 +0,0 @@
get:
tags:
- posts
summary: get post edit history
description: This operation retrieves a post's edit history
parameters:
- in: path
name: pid
schema:
type: string
required: true
description: a valid post id
example: 2
responses:
'200':
description: Post history successfully retrieved.
content:
application/json:
schema:
type: object
properties:
status:
$ref: ../../../components/schemas/Status.yaml#/Status
response:
type: object
properties:
timestamps:
type: array
items:
type: number
revisions:
type: array
items:
type: object
properties:
timestamp:
type: number
username:
type: string
editable:
type: boolean

View File

@@ -1,65 +0,0 @@
get:
tags:
- posts
summary: get single post edit history
description: This operation retrieves a post's edit history
parameters:
- in: path
name: pid
schema:
type: string
required: true
description: a valid post id
example: 2
- in: path
name: since
schema:
type: number
required: true
description: a valid UNIX timestamp
example: 0
responses:
'200':
description: Post history successfully retrieved.
content:
application/json:
schema:
type: object
properties:
status:
$ref: ../../../../components/schemas/Status.yaml#/Status
response:
$ref: ../../../../components/schemas/PostObject.yaml#/PostObject
put:
tags:
- posts
summary: revert a post
description: This operation reverts a post to an earlier version. The revert process will append a new history item to the post's edit history.
parameters:
- in: path
name: pid
schema:
type: string
required: true
description: a valid post id
example: 2
- in: path
name: since
schema:
type: number
required: true
description: a valid UNIX timestamp
example: 0
responses:
'200':
description: Post successfully reverted
content:
application/json:
schema:
type: object
properties:
status:
$ref: ../../../../components/schemas/Status.yaml#/Status
response:
type: object
properties: {}

View File

@@ -1,36 +0,0 @@
put:
tags:
- posts
summary: move a post
description: This operation moves a post to a different topic.
parameters:
- in: path
name: pid
schema:
type: number
required: true
description: a valid post id
example: 5
requestBody:
content:
application/json:
schema:
type: object
properties:
tid:
type: number
description: a valid topic id
example: 4
responses:
'200':
description: Post successfully moved
content:
application/json:
schema:
type: object
properties:
status:
$ref: ../../../components/schemas/Status.yaml#/Status
response:
type: object
properties: {}

View File

@@ -1,6 +1,6 @@
'use strict';
define('forum/topic/diffs', ['api', 'forum/topic/images'], function (api) {
define('forum/topic/diffs', ['forum/topic/images'], function () {
var Diffs = {};
Diffs.open = function (pid) {
@@ -10,7 +10,11 @@ define('forum/topic/diffs', ['api', 'forum/topic/images'], function (api) {
var localeStringOpts = { year: 'numeric', month: 'short', day: 'numeric', hour: 'numeric', minute: 'numeric' };
api.get(`/posts/${pid}/diffs`, {}).then((data) => {
socket.emit('posts.getDiffs', { pid: pid }, function (err, data) {
if (err) {
return app.alertError(err.message);
}
app.parseAndTranslate('partials/modals/post_history', {
diffs: data.revisions.map(function (revision) {
var timestamp = parseInt(revision.timestamp, 10);
@@ -52,7 +56,7 @@ define('forum/topic/diffs', ['api', 'forum/topic/images'], function (api) {
revertEl.prop('disabled', true);
});
});
}).catch(app.alertError);
});
};
Diffs.load = function (pid, since, postContainer) {
@@ -60,7 +64,11 @@ define('forum/topic/diffs', ['api', 'forum/topic/images'], function (api) {
return;
}
api.get(`/posts/${pid}/diffs/${since}`, {}).then((data) => {
socket.emit('posts.showPostAt', { pid: pid, since: since }, function (err, data) {
if (err) {
return app.alertError(err.message);
}
data.deleted = !!parseInt(data.deleted, 10);
app.parseAndTranslate('partials/posts_list', 'posts', {
@@ -68,7 +76,7 @@ define('forum/topic/diffs', ['api', 'forum/topic/images'], function (api) {
}, function (html) {
postContainer.empty().append(html);
});
}).catch(app.alertError);
});
};
Diffs.restore = function (pid, since, modal) {
@@ -76,10 +84,14 @@ define('forum/topic/diffs', ['api', 'forum/topic/images'], function (api) {
return;
}
api.put(`/posts/${pid}/diffs/${since}`, {}).then(() => {
socket.emit('posts.restoreDiff', { pid: pid, since: since }, function (err) {
if (err) {
return app.alertError(err);
}
modal.modal('hide');
app.alertSuccess('[[topic:diffs.post-restored]]');
}).catch(app.alertError);
});
};
return Diffs;

View File

@@ -2,8 +2,8 @@
define('forum/topic/move-post', [
'components', 'postSelect', 'translator', 'alerts', 'api',
], function (components, postSelect, translator, alerts, api) {
'components', 'postSelect', 'translator', 'alerts',
], function (components, postSelect, translator, alerts) {
var MovePost = {};
var moveModal;
@@ -100,10 +100,10 @@ define('forum/topic/move-post', [
if (!ajaxify.data.template.topic || !data.tid) {
return;
}
Promise.all(data.pids.map(pid => api.put(`/posts/${pid}/move`, {
tid: data.tid,
}))).then(() => {
socket.emit('posts.movePosts', { pids: data.pids, tid: data.tid }, function (err) {
if (err) {
return app.alertError(err.message);
}
data.pids.forEach(function (pid) {
components.get('post', 'pid', pid).fadeOut(500, function () {
$(this).remove();
@@ -111,7 +111,7 @@ define('forum/topic/move-post', [
});
closeMoveModal();
}).catch(app.alertError);
});
}
function closeMoveModal() {

View File

@@ -210,9 +210,7 @@ define('forum/topic/posts', [
html.insertBefore(before);
// Now restore the relative position the user was on prior to new post insertion
if (scrollTop > 0) {
$(window).scrollTop(scrollTop + ($(document).height() - height));
}
$(window).scrollTop(scrollTop + ($(document).height() - height));
} else {
components.get('topic').append(html);
}

View File

@@ -286,9 +286,6 @@
var out = translated;
translatedArgs.forEach(function (arg, i) {
var escaped = arg.replace(/%(?=\d)/g, '%').replace(/\\,/g, ',');
// fix double escaped translation keys, see https://github.com/NodeBB/NodeBB/issues/9206
escaped = escaped.replace(/[/g, '[')
.replace(/]/g, ']');
out = out.replace(new RegExp('%' + (i + 1), 'g'), escaped);
});
return out;

View File

@@ -4,7 +4,6 @@ const validator = require('validator');
const _ = require('lodash');
const utils = require('../utils');
const user = require('../user');
const posts = require('../posts');
const topics = require('../topics');
const groups = require('../groups');
@@ -13,7 +12,6 @@ const events = require('../events');
const privileges = require('../privileges');
const apiHelpers = require('./helpers');
const websockets = require('../socket.io');
const socketHelpers = require('../socket.io/helpers');
const postsAPI = module.exports;
@@ -196,27 +194,6 @@ async function isMainAndLastPost(pid) {
};
}
postsAPI.move = async function (caller, data) {
const canMove = await Promise.all([
privileges.topics.isAdminOrMod(data.tid, caller.uid),
privileges.posts.canMove(data.pid, caller.uid),
]);
if (!canMove.every(Boolean)) {
throw new Error('[[error:no-privileges]]');
}
await topics.movePostToTopic(caller.uid, data.pid, data.tid);
const [postDeleted, topicDeleted] = await Promise.all([
posts.getPostField(data.pid, 'deleted'),
topics.getTopicField(data.tid, 'deleted'),
]);
if (!postDeleted && !topicDeleted) {
socketHelpers.sendNotificationToPostOwner(data.pid, caller.uid, 'move', 'notifications:moved_your_post');
}
};
postsAPI.upvote = async function (caller, data) {
return await apiHelpers.postCommand(caller, 'upvote', 'voted', 'notifications:upvoted_your_post_in', data);
};
@@ -236,61 +213,3 @@ postsAPI.bookmark = async function (caller, data) {
postsAPI.unbookmark = async function (caller, data) {
return await apiHelpers.postCommand(caller, 'unbookmark', 'bookmarked', '', data);
};
async function diffsPrivilegeCheck(pid, uid) {
const [deleted, privilegesData] = await Promise.all([
posts.getPostField(pid, 'deleted'),
privileges.posts.get([pid], uid),
]);
const allowed = privilegesData[0]['posts:history'] && (deleted ? privilegesData[0]['posts:view_deleted'] : true);
if (!allowed) {
throw new Error('[[error:no-privileges]]');
}
}
postsAPI.getDiffs = async (caller, data) => {
await diffsPrivilegeCheck(data.pid, caller.uid);
const timestamps = await posts.diffs.list(data.pid);
const post = await posts.getPostFields(data.pid, ['timestamp', 'uid']);
const diffs = await posts.diffs.get(data.pid);
const uids = diffs.map(diff => diff.uid || null);
uids.push(post.uid);
let usernames = await user.getUsersFields(uids, ['username']);
usernames = usernames.map(userObj => (userObj.uid ? userObj.username : null));
let canEdit = true;
try {
await user.isPrivilegedOrSelf(caller.uid, post.uid);
} catch (e) {
canEdit = false;
}
timestamps.push(post.timestamp);
return {
timestamps: timestamps,
revisions: timestamps.map((timestamp, idx) => ({
timestamp: timestamp,
username: usernames[idx],
})),
editable: canEdit,
};
};
postsAPI.loadDiff = async (caller, data) => {
await diffsPrivilegeCheck(data.pid, caller.uid);
return await posts.diffs.load(data.pid, data.since, caller.uid);
};
postsAPI.restoreDiff = async (caller, data) => {
const cid = await posts.getCidByPid(data.pid);
const canEdit = await privileges.categories.can('edit', cid, caller.uid);
if (!canEdit) {
throw new Error('[[error:no-privileges]]');
}
const edit = await posts.diffs.restore(data.pid, data.since, caller.uid, apiHelpers.buildReqObject(caller));
websockets.in('topic_' + edit.topic.tid).emit('event:post_edited', edit);
};

View File

@@ -51,11 +51,12 @@ notificationsController.get = async function (req, res, next) {
if (!selectedFilter) {
return next();
}
let nids = await user.notifications.getAll(req.uid, selectedFilter.filter);
const pageCount = Math.max(1, Math.ceil(nids.length / itemsPerPage));
nids = nids.slice(start, stop + 1);
const notifications = await user.notifications.getNotifications(nids, req.uid);
const nids = await user.notifications.getAll(req.uid, selectedFilter.filter);
let notifications = await user.notifications.getNotifications(nids, req.uid);
const pageCount = Math.max(1, Math.ceil(notifications.length / itemsPerPage));
notifications = notifications.slice(start, stop + 1);
res.render('notifications', {
notifications: notifications,

View File

@@ -38,14 +38,6 @@ Posts.delete = async (req, res) => {
helpers.formatApiResponse(200, res);
};
Posts.move = async (req, res) => {
await api.posts.move(req, {
pid: req.params.pid,
tid: req.body.tid,
});
helpers.formatApiResponse(200, res);
};
async function mock(req) {
const tid = await posts.getPostField(req.params.pid, 'tid');
return { pid: req.params.pid, room_id: `topic_${tid}` };
@@ -81,16 +73,3 @@ Posts.unbookmark = async (req, res) => {
await api.posts.unbookmark(req, data);
helpers.formatApiResponse(200, res);
};
Posts.getDiffs = async (req, res) => {
helpers.formatApiResponse(200, res, await api.posts.getDiffs(req, { ...req.params }));
};
Posts.loadDiff = async (req, res) => {
helpers.formatApiResponse(200, res, await api.posts.loadDiff(req, { ...req.params }));
};
Posts.restoreDiff = async (req, res) => {
helpers.formatApiResponse(200, res, await api.posts.restoreDiff(req, { ...req.params }));
};

View File

@@ -104,14 +104,8 @@ Topics.deleteTags = async (req, res) => {
};
Topics.getThumbs = async (req, res) => {
if (isFinite(req.params.tid)) { // post_uuids can be passed in occasionally, in that case no checks are necessary
const [exists, canRead] = await Promise.all([
topics.exists(req.params.tid),
privileges.topics.can('topics:read', req.params.tid, req.uid),
]);
if (!exists || !canRead) {
return helpers.formatApiResponse(403, res);
}
if (!await privileges.topics.can('topics:read', req.params.tid, req.uid)) {
return helpers.formatApiResponse(403, res);
}
helpers.formatApiResponse(200, res, await topics.thumbs.get(req.params.tid));

View File

@@ -230,16 +230,6 @@ Emailer.send = async (template, uid, params) => {
params.uid = uid;
params.username = userData.username;
params.rtl = await translator.translate('[[language:dir]]', userSettings.userLang) === 'rtl';
const result = await Plugins.hooks.fire('filter:email.cancel', {
cancel: false, // set to true in plugin to cancel sending email
template: template,
params: params,
});
if (result.cancel) {
return;
}
await Emailer.sendToEmail(template, userData.email, userSettings.userLang, params);
};

View File

@@ -46,7 +46,7 @@ Assert.topic = helpers.try(async (req, res, next) => {
Assert.post = helpers.try(async (req, res, next) => {
if (!await posts.exists(req.params.pid)) {
return controllerHelpers.formatApiResponse(404, res, new Error('[[error:no-post]]'));
return controllerHelpers.formatApiResponse(404, res, new Error('[[error:no-topic]]'));
}
next();

View File

@@ -1,26 +1,26 @@
'use strict';
const nconf = require('nconf');
const jsesc = require('jsesc');
const _ = require('lodash');
var nconf = require('nconf');
var jsesc = require('jsesc');
var _ = require('lodash');
const validator = require('validator');
const util = require('util');
var util = require('util');
const db = require('../database');
const user = require('../user');
const topics = require('../topics');
const messaging = require('../messaging');
const flags = require('../flags');
const meta = require('../meta');
const plugins = require('../plugins');
const navigation = require('../navigation');
const translator = require('../translator');
const privileges = require('../privileges');
const languages = require('../languages');
const utils = require('../utils');
const helpers = require('./helpers');
var db = require('../database');
var user = require('../user');
var topics = require('../topics');
var messaging = require('../messaging');
var flags = require('../flags');
var meta = require('../meta');
var plugins = require('../plugins');
var navigation = require('../navigation');
var translator = require('../translator');
var privileges = require('../privileges');
var languages = require('../languages');
var utils = require('../utils');
var helpers = require('./helpers');
const controllers = {
var controllers = {
api: require('../controllers/api'),
helpers: require('../controllers/helpers'),
};
@@ -49,9 +49,9 @@ middleware.buildHeader = helpers.try(async function buildHeader(req, res, next)
middleware.buildHeaderAsync = util.promisify(middleware.buildHeader);
middleware.renderHeader = async function renderHeader(req, res, data) {
const registrationType = meta.config.registrationType || 'normal';
var registrationType = meta.config.registrationType || 'normal';
res.locals.config = res.locals.config || {};
const templateValues = {
var templateValues = {
title: meta.config.title || '',
'title:url': meta.config['title:url'] || '',
description: meta.config.description || '',
@@ -240,7 +240,7 @@ middleware.renderFooter = async function renderFooter(req, res, templateValues)
};
function modifyTitle(obj) {
const title = controllers.helpers.buildTitle(meta.config.homePageTitle || '[[pages:home]]');
var title = controllers.helpers.buildTitle(meta.config.homePageTitle || '[[pages:home]]');
obj.browserTitle = title;
if (obj.metaTags) {

View File

@@ -327,9 +327,10 @@ Notifications.prune = async function () {
]);
await batch.processSortedSet('users:joindate', async function (uids) {
const unread = uids.map(uid => 'uid:' + uid + ':notifications:unread');
const read = uids.map(uid => 'uid:' + uid + ':notifications:read');
await db.sortedSetsRemoveRangeByScore(unread.concat(read), '-inf', cutoffTime);
await Promise.all([
db.sortedSetsRemoveRangeByScore(uids.map(uid => 'uid:' + uid + ':notifications:unread'), '-inf', cutoffTime),
db.sortedSetsRemoveRangeByScore(uids.map(uid => 'uid:' + uid + ':notifications:read'), '-inf', cutoffTime),
]);
}, { batch: 500, interval: 100 });
} catch (err) {
if (err) {

View File

@@ -92,7 +92,7 @@ Hooks.unregister = function (id, hook, method) {
Hooks.fire = async function (hook, params) {
const hookList = plugins.loadedHooks[hook];
const hookType = hook.split(':')[0];
if (global.env === 'development' && hook !== 'action:plugins.firehook') {
if (global.env === 'development' && hook !== 'action:plugins.fireHook') {
winston.verbose('[plugins/fireHook] ' + hook);
}
@@ -102,8 +102,8 @@ Hooks.fire = async function (hook, params) {
}
const result = await hookTypeToMethod[hookType](hook, hookList, params);
if (hook !== 'action:plugins.firehook') {
Hooks.fire('action:plugins.firehook', { hook: hook, params: params });
if (hook !== 'action:plugins.fireHook') {
Hooks.fire('action:plugins.fireHook', { hook: hook, params: params });
}
if (result !== undefined) {
return result;

View File

@@ -18,17 +18,11 @@ module.exports = function () {
setupApiRoute(router, 'put', '/:pid/state', [...middlewares, middleware.assert.post], controllers.write.posts.restore);
setupApiRoute(router, 'delete', '/:pid/state', [...middlewares, middleware.assert.post], controllers.write.posts.delete);
setupApiRoute(router, 'put', '/:pid/move', [...middlewares, middleware.assert.post, middleware.checkRequired.bind(null, ['tid'])], controllers.write.posts.move);
setupApiRoute(router, 'put', '/:pid/vote', [...middlewares, middleware.checkRequired.bind(null, ['delta']), middleware.assert.post], controllers.write.posts.vote);
setupApiRoute(router, 'delete', '/:pid/vote', [...middlewares, middleware.assert.post], controllers.write.posts.unvote);
setupApiRoute(router, 'put', '/:pid/bookmark', [...middlewares, middleware.assert.post], controllers.write.posts.bookmark);
setupApiRoute(router, 'delete', '/:pid/bookmark', [...middlewares, middleware.assert.post], controllers.write.posts.unbookmark);
setupApiRoute(router, 'get', '/:pid/diffs', [middleware.authenticateOrGuest, middleware.assert.post], controllers.write.posts.getDiffs);
setupApiRoute(router, 'get', '/:pid/diffs/:since', [middleware.authenticateOrGuest, middleware.assert.post], controllers.write.posts.loadDiff);
setupApiRoute(router, 'put', '/:pid/diffs/:since', [...middlewares, middleware.assert.post], controllers.write.posts.restoreDiff);
return router;
};

View File

@@ -1,21 +1,67 @@
'use strict';
const api = require('../../api');
const posts = require('../../posts');
const user = require('../../user');
const privileges = require('../../privileges');
const apiHelpers = require('../../api/helpers');
const websockets = require('..');
module.exports = function (SocketPosts) {
SocketPosts.getDiffs = async function (socket, data) {
websockets.warnDeprecated(socket, 'GET /api/v3/posts/:pid/diffs');
return await api.posts.getDiffs(socket, data);
await privilegeCheck(data.pid, socket.uid);
const timestamps = await posts.diffs.list(data.pid);
const post = await posts.getPostFields(data.pid, ['timestamp', 'uid']);
const diffs = await posts.diffs.get(data.pid);
const uids = diffs.map(diff => diff.uid || null);
uids.push(post.uid);
let usernames = await user.getUsersFields(uids, ['username']);
usernames = usernames.map(userObj => (userObj.uid ? userObj.username : null));
let canEdit = true;
try {
await user.isPrivilegedOrSelf(socket.uid, post.uid);
} catch (e) {
canEdit = false;
}
timestamps.push(post.timestamp);
return {
timestamps: timestamps,
revisions: timestamps.map((timestamp, idx) => ({
timestamp: timestamp,
username: usernames[idx],
})),
editable: canEdit,
};
};
SocketPosts.showPostAt = async function (socket, data) {
websockets.warnDeprecated(socket, 'GET /api/v3/posts/:pid/diffs/:since');
return await api.posts.loadDiff(socket, data);
await privilegeCheck(data.pid, socket.uid);
return await posts.diffs.load(data.pid, data.since, socket.uid);
};
async function privilegeCheck(pid, uid) {
const [deleted, privilegesData] = await Promise.all([
posts.getPostField(pid, 'deleted'),
privileges.posts.get([pid], uid),
]);
const allowed = privilegesData[0]['posts:history'] && (deleted ? privilegesData[0]['posts:view_deleted'] : true);
if (!allowed) {
throw new Error('[[error:no-privileges]]');
}
}
SocketPosts.restoreDiff = async function (socket, data) {
websockets.warnDeprecated(socket, 'PUT /api/v3/posts/:pid/diffs/:since');
return await api.posts.restoreDiff(socket, data);
const cid = await posts.getCidByPid(data.pid);
const canEdit = await privileges.categories.can('edit', cid, socket.uid);
if (!canEdit) {
throw new Error('[[error:no-privileges]]');
}
const edit = await posts.diffs.restore(data.pid, data.since, socket.uid, apiHelpers.buildReqObject(socket));
websockets.in('topic_' + edit.topic.tid).emit('event:post_edited', edit);
};
};

View File

@@ -1,33 +1,45 @@
'use strict';
const api = require('../../api');
const sockets = require('..');
const privileges = require('../../privileges');
const topics = require('../../topics');
const posts = require('../../posts');
const socketHelpers = require('../helpers');
module.exports = function (SocketPosts) {
function moveChecks(socket, typeCheck, data) {
SocketPosts.movePost = async function (socket, data) {
await SocketPosts.movePosts(socket, { pids: [data.pid], tid: data.tid });
};
SocketPosts.movePosts = async function (socket, data) {
if (!socket.uid) {
throw new Error('[[error:not-logged-in]]');
}
if (!data || !typeCheck || !data.tid) {
if (!data || !Array.isArray(data.pids) || !data.tid) {
throw new Error('[[error:invalid-data]]');
}
}
SocketPosts.movePost = async function (socket, data) {
sockets.warnDeprecated(socket, 'PUT /api/v3/posts/:pid/move');
const canMove = await privileges.topics.isAdminOrMod(data.tid, socket.uid);
if (!canMove) {
throw new Error('[[error:no-privileges]]');
}
moveChecks(socket, isFinite(data.pid), data);
await api.posts.move(socket, data);
};
for (const pid of data.pids) {
/* eslint-disable no-await-in-loop */
const canMove = await privileges.posts.canMove(pid, socket.uid);
if (!canMove) {
throw new Error('[[error:no-privileges]]');
}
await topics.movePostToTopic(socket.uid, pid, data.tid);
SocketPosts.movePosts = async function (socket, data) {
sockets.warnDeprecated(socket, 'PUT /api/v3/posts/:pid/move');
const [postDeleted, topicDeleted] = await Promise.all([
posts.getPostField(pid, 'deleted'),
topics.getTopicField(data.tid, 'deleted'),
]);
moveChecks(socket, !Array.isArray(data.pids), data);
await Promise.all(data.pids.map(async pid => api.posts.move(socket, {
tid: data.tid,
pid,
})));
if (!postDeleted && !topicDeleted) {
socketHelpers.sendNotificationToPostOwner(pid, socket.uid, 'move', 'notifications:moved_your_post');
}
}
};
};

View File

@@ -16,7 +16,7 @@ module.exports = {
const userData = await user.getUsersFields(uids, ['uid', 'fullname']);
const bulkAdd = userData
.filter(u => u.uid && u.fullname)
.map(u => ['fullname:sorted', 0, String(u.fullname).substr(0, 255).toLowerCase() + ':' + u.uid]);
.map(u => ['fullname:sorted', 0, u.fullname.substr(0, 255).toLowerCase() + ':' + u.uid]);
await db.sortedSetAddBulk(bulkAdd);
}, {
batch: 500,

View File

@@ -13,9 +13,6 @@ module.exports = {
timestamp: Date.UTC(2020, 9, 13),
method: async function () {
const progress = this.progress;
const maxGroupLength = meta.config.maximumGroupNameLength;
meta.config.maximumGroupNameLength = 30;
const timestamp = await db.getObjectField('group:administrators', 'timestamp');
const verifiedExists = await groups.exists('verified-users');
if (!verifiedExists) {
@@ -41,8 +38,7 @@ module.exports = {
timestamp: timestamp + 1,
});
}
// restore setting
meta.config.maximumGroupNameLength = maxGroupLength;
await batch.processSortedSet('users:joindate', async function (uids) {
progress.incr(uids.length);
const userData = await user.getUsersFields(uids, ['uid', 'email:confirmed']);

View File

@@ -135,12 +135,6 @@ describe('API', async () => {
title: 'Test Topic 2',
content: 'Test topic 2 content',
});
await topics.post({
uid: unprivUid,
cid: testCategory.cid,
title: 'Test Topic 3',
content: 'Test topic 3 content',
});
// Create a sample flag
await flags.create('post', 1, unprivUid, 'sample reasons', Date.now());

View File

@@ -135,16 +135,6 @@ describe('new Translator(language)', function () {
});
});
it('should translate escaped translation arguments properly', function () {
// https://github.com/NodeBB/NodeBB/issues/9206
var translator = Translator.create('en-GB');
var key = '[[notifications:upvoted_your_post_in, test1, error: Error: [[error:group-name-too-long]] on NodeBB Upgrade]]';
return translator.translate(key).then(function (translated) {
assert.strictEqual(translated, '<strong>test1</strong> has upvoted your post in <strong>error: Error: &lsqb;&lsqb;error:group-name-too-long&rsqb;&rsqb; on NodeBB Upgrade</strong>.');
});
});
it('should properly escape and ignore % and \\, in arguments', function () {
var translator = Translator.create('en-GB');