breaking: remove socket.emit('posts.move')

isekai-main
Barış Soner Uşaklı 3 years ago
parent 4247f62441
commit 8427c5d9db

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

@ -17,7 +17,6 @@ const sockets = require('.');
const SocketPosts = module.exports;
require('./posts/move')(SocketPosts);
require('./posts/votes')(SocketPosts);
require('./posts/tools')(SocketPosts);

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

@ -683,72 +683,62 @@ describe('Post\'s', () => {
let tid;
let moveTid;
before((done) => {
async.waterfall([
function (next) {
topics.post({
before(async () => {
const topic1 = await topics.post({
uid: voterUid,
cid: cid,
title: 'topic 1',
content: 'some content',
}, next);
},
function (data, next) {
tid = data.topicData.tid;
topics.post({
});
tid = topic1.topicData.tid;
const topic2 = await topics.post({
uid: voterUid,
cid: cid,
title: 'topic 2',
content: 'some content',
}, next);
},
function (data, next) {
moveTid = data.topicData.tid;
topics.reply({
});
moveTid = topic2.topicData.tid;
const reply = await topics.reply({
uid: voterUid,
tid: tid,
timestamp: Date.now(),
content: 'A reply to move',
}, (err, data) => {
assert.ifError(err);
replyPid = data.pid;
next();
});
},
], done);
replyPid = reply.pid;
});
it('should error if uid is not logged in', (done) => {
socketPosts.movePost({ uid: 0 }, {}, (err) => {
assert.equal(err.message, '[[error:not-logged-in]]');
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 data is invalid', (done) => {
socketPosts.movePost({ uid: globalModUid }, {}, (err) => {
assert.equal(err.message, '[[error:invalid-data]]');
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', (done) => {
socketPosts.movePost({ uid: voterUid }, { pid: replyPid, tid: moveTid }, (err) => {
assert.equal(err.message, '[[error:no-privileges]]');
done();
});
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);
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);
done();
});
});
});
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;
}

Loading…
Cancel
Save