Node.js based forum software built for the modern web
breaking: remove socket.emit('posts.move')
Barış Soner Uşaklı8427c5d9db84
diff --git a/src/api/posts.js b/src/api/posts.jsindex 34c4c304eb..ef664c10e7 100644--- a/src/api/posts.js+++ b/src/api/posts.js@@ -208,6 +208,12 @@ async function isMainAndLastPost(pid) {}postsAPI.move = async function (caller, data) {+ if (!caller.uid) {+ throw new Error('[[error:not-logged-in]]');+ }+ if (!data || !data.pid || !data.tid) {+ throw new Error('[[error:invalid-data]]');+ }const canMove = await Promise.all([privileges.topics.isAdminOrMod(data.tid, caller.uid),privileges.posts.canMove(data.pid, caller.uid),diff --git a/src/socket.io/posts.js b/src/socket.io/posts.jsindex 236f360dc6..e838a06c41 100644--- a/src/socket.io/posts.js+++ b/src/socket.io/posts.js@@ -17,7 +17,6 @@ const sockets = require('.');const SocketPosts = module.exports;-require('./posts/move')(SocketPosts);require('./posts/votes')(SocketPosts);require('./posts/tools')(SocketPosts);diff --git a/src/socket.io/posts/move.js b/src/socket.io/posts/move.jsdeleted file mode 100644index 9424d73a06..0000000000--- a/src/socket.io/posts/move.js+++ /dev/null@@ -1,33 +0,0 @@-'use strict';--const api = require('../../api');-const sockets = require('..');--module.exports = function (SocketPosts) {- function moveChecks(socket, typeCheck, data) {- if (!socket.uid) {- throw new Error('[[error:not-logged-in]]');- }-- if (!data || !typeCheck || !data.tid) {- throw new Error('[[error:invalid-data]]');- }- }-- SocketPosts.movePost = async function (socket, data) {- sockets.warnDeprecated(socket, 'PUT /api/v3/posts/:pid/move');-- moveChecks(socket, isFinite(data.pid), data);- await api.posts.move(socket, data);- };-- SocketPosts.movePosts = async function (socket, data) {- sockets.warnDeprecated(socket, 'PUT /api/v3/posts/:pid/move');-- moveChecks(socket, !Array.isArray(data.pids), data);- await Promise.all(data.pids.map(async pid => api.posts.move(socket, {- tid: data.tid,- pid,- })));- };-};diff --git a/test/posts.js b/test/posts.jsindex bac34f4b92..1d20e01ecd 100644--- a/test/posts.js+++ b/test/posts.js@@ -683,72 +683,62 @@ describe('Post\'s', () => {let tid;let moveTid;- before((done) => {- async.waterfall([- function (next) {- topics.post({- uid: voterUid,- cid: cid,- title: 'topic 1',- content: 'some content',- }, next);- },- function (data, next) {- tid = data.topicData.tid;- topics.post({- uid: voterUid,- cid: cid,- title: 'topic 2',- content: 'some content',- }, next);- },- function (data, next) {- moveTid = data.topicData.tid;- topics.reply({- uid: voterUid,- tid: tid,- timestamp: Date.now(),- content: 'A reply to move',- }, (err, data) => {- assert.ifError(err);- replyPid = data.pid;- next();- });- },- ], done);- });+ before(async () => {+ const topic1 = await topics.post({+ uid: voterUid,+ cid: cid,+ title: 'topic 1',+ content: 'some content',+ });+ tid = topic1.topicData.tid;+ const topic2 = await topics.post({+ uid: voterUid,+ cid: cid,+ title: 'topic 2',+ content: 'some content',+ });+ moveTid = topic2.topicData.tid;- it('should error if uid is not logged in', (done) => {- socketPosts.movePost({ uid: 0 }, {}, (err) => {- assert.equal(err.message, '[[error:not-logged-in]]');- done();+ const reply = await topics.reply({+ uid: voterUid,+ tid: tid,+ timestamp: Date.now(),+ content: 'A reply to move',});+ replyPid = reply.pid;});- it('should error if data is invalid', (done) => {- socketPosts.movePost({ uid: globalModUid }, {}, (err) => {- assert.equal(err.message, '[[error:invalid-data]]');- done();- });+ it('should error if uid is not logged in', async () => {+ try {+ await apiPosts.move({ uid: 0 }, {});+ } catch (err) {+ return assert.equal(err.message, '[[error:not-logged-in]]');+ }+ assert(false);});- it('should error if user does not have move privilege', (done) => {- socketPosts.movePost({ uid: voterUid }, { pid: replyPid, tid: moveTid }, (err) => {- assert.equal(err.message, '[[error:no-privileges]]');- done();- });+ it('should error if data is invalid', async () => {+ try {+ await apiPosts.move({ uid: globalModUid }, {});+ } catch (err) {+ return assert.equal(err.message, '[[error:invalid-data]]');+ }+ assert(false);});+ it('should error if user does not have move privilege', async () => {+ try {+ await apiPosts.move({ uid: voterUid }, { pid: replyPid, tid: moveTid });+ } catch (err) {+ return assert.equal(err.message, '[[error:no-privileges]]');+ }+ assert(false);+ });- it('should move a post', (done) => {- socketPosts.movePost({ uid: globalModUid }, { pid: replyPid, tid: moveTid }, (err) => {- assert.ifError(err);- posts.getPostField(replyPid, 'tid', (err, tid) => {- assert.ifError(err);- assert(tid, moveTid);- done();- });- });+ it('should move a post', async () => {+ await apiPosts.move({ uid: globalModUid }, { pid: replyPid, tid: moveTid });+ const tid = await posts.getPostField(replyPid, 'tid');+ assert(tid, moveTid);});it('should fail to move post if not moderator of target category', async () => {@@ -759,7 +749,7 @@ describe('Post\'s', () => {await privileges.categories.give(privileges.categories.userPrivilegeList, cat1.cid, modUid);let err;try {- await socketPosts.movePost({ uid: modUid }, { pid: replyPid, tid: result.tid });+ await apiPosts.move({ uid: modUid }, { pid: replyPid, tid: result.tid });} catch (_err) {err = _err;}