mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-27 09:06:15 +01:00
breaking: remove socket.emit('posts.delete')
remove socket.emit('posts.restore')
remove socket.emit('posts.purge')
remove socket.emit('posts.deletePosts')
remove socket.emit('posts.purgePosts')
This commit is contained in:
@@ -1,7 +1,8 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
define('forum/topic/delete-posts', [
|
||||||
define('forum/topic/delete-posts', ['postSelect', 'alerts'], function (postSelect, alerts) {
|
'postSelect', 'alerts', 'api',
|
||||||
|
], function (postSelect, alerts, api) {
|
||||||
const DeletePosts = {};
|
const DeletePosts = {};
|
||||||
let modal;
|
let modal;
|
||||||
let deleteBtn;
|
let deleteBtn;
|
||||||
@@ -34,10 +35,10 @@ define('forum/topic/delete-posts', ['postSelect', 'alerts'], function (postSelec
|
|||||||
showPostsSelected();
|
showPostsSelected();
|
||||||
|
|
||||||
deleteBtn.on('click', function () {
|
deleteBtn.on('click', function () {
|
||||||
deletePosts(deleteBtn, 'posts.deletePosts');
|
deletePosts(deleteBtn, pid => `/posts/${pid}/state`);
|
||||||
});
|
});
|
||||||
purgeBtn.on('click', function () {
|
purgeBtn.on('click', function () {
|
||||||
deletePosts(purgeBtn, 'posts.purgePosts');
|
deletePosts(purgeBtn, pid => `/posts/${pid}`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -49,17 +50,13 @@ define('forum/topic/delete-posts', ['postSelect', 'alerts'], function (postSelec
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function deletePosts(btn, command) {
|
function deletePosts(btn, route) {
|
||||||
btn.attr('disabled', true);
|
btn.attr('disabled', true);
|
||||||
socket.emit(command, {
|
Promise.all(postSelect.pids.map(pid => api.delete(route(pid), {})))
|
||||||
pids: postSelect.pids,
|
.then(closeModal)
|
||||||
}, function (err) {
|
.catch(alerts.error)
|
||||||
|
.finally(() => {
|
||||||
btn.removeAttr('disabled');
|
btn.removeAttr('disabled');
|
||||||
if (err) {
|
|
||||||
return alerts.error(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
closeModal();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,9 +9,6 @@ const plugins = require('../../plugins');
|
|||||||
const social = require('../../social');
|
const social = require('../../social');
|
||||||
const user = require('../../user');
|
const user = require('../../user');
|
||||||
const utils = require('../../utils');
|
const utils = require('../../utils');
|
||||||
const api = require('../../api');
|
|
||||||
|
|
||||||
const sockets = require('..');
|
|
||||||
|
|
||||||
module.exports = function (SocketPosts) {
|
module.exports = function (SocketPosts) {
|
||||||
SocketPosts.loadPostTools = async function (socket, data) {
|
SocketPosts.loadPostTools = async function (socket, data) {
|
||||||
@@ -68,39 +65,6 @@ module.exports = function (SocketPosts) {
|
|||||||
return results;
|
return results;
|
||||||
};
|
};
|
||||||
|
|
||||||
SocketPosts.delete = async function (socket, data) {
|
|
||||||
sockets.warnDeprecated(socket, 'DELETE /api/v3/posts/:pid/state');
|
|
||||||
await api.posts.delete(socket, data);
|
|
||||||
};
|
|
||||||
|
|
||||||
SocketPosts.restore = async function (socket, data) {
|
|
||||||
sockets.warnDeprecated(socket, 'PUT /api/v3/posts/:pid/state');
|
|
||||||
await api.posts.restore(socket, data);
|
|
||||||
};
|
|
||||||
|
|
||||||
SocketPosts.deletePosts = async function (socket, data) {
|
|
||||||
await deletePurgePosts(socket, data, 'delete');
|
|
||||||
};
|
|
||||||
|
|
||||||
SocketPosts.purgePosts = async function (socket, data) {
|
|
||||||
await deletePurgePosts(socket, data, 'purge');
|
|
||||||
};
|
|
||||||
|
|
||||||
async function deletePurgePosts(socket, data, command) {
|
|
||||||
if (!data || !Array.isArray(data.pids)) {
|
|
||||||
throw new Error('[[error:invalid-data]]');
|
|
||||||
}
|
|
||||||
for (const pid of data.pids) {
|
|
||||||
/* eslint-disable no-await-in-loop */
|
|
||||||
await SocketPosts[command](socket, { pid: pid });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SocketPosts.purge = async function (socket, data) {
|
|
||||||
sockets.warnDeprecated(socket, 'DELETE /api/v3/posts/:pid');
|
|
||||||
await api.posts.purge(socket, data);
|
|
||||||
};
|
|
||||||
|
|
||||||
SocketPosts.changeOwner = async function (socket, data) {
|
SocketPosts.changeOwner = async function (socket, data) {
|
||||||
if (!data || !Array.isArray(data.pids) || !data.toUid) {
|
if (!data || !Array.isArray(data.pids) || !data.toUid) {
|
||||||
throw new Error('[[error:invalid-data]]');
|
throw new Error('[[error:invalid-data]]');
|
||||||
|
|||||||
112
test/posts.js
112
test/posts.js
@@ -308,55 +308,48 @@ describe('Post\'s', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('delete/restore/purge', () => {
|
describe('delete/restore/purge', () => {
|
||||||
function createTopicWithReply(callback) {
|
async function createTopicWithReply() {
|
||||||
topics.post({
|
const topicPostData = await topics.post({
|
||||||
uid: voterUid,
|
uid: voterUid,
|
||||||
cid: cid,
|
cid: cid,
|
||||||
title: 'topic to delete/restore/purge',
|
title: 'topic to delete/restore/purge',
|
||||||
content: 'A post to delete/restore/purge',
|
content: 'A post to delete/restore/purge',
|
||||||
}, (err, topicPostData) => {
|
});
|
||||||
assert.ifError(err);
|
|
||||||
topics.reply({
|
const replyData = await topics.reply({
|
||||||
uid: voterUid,
|
uid: voterUid,
|
||||||
tid: topicPostData.topicData.tid,
|
tid: topicPostData.topicData.tid,
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
content: 'A post to delete/restore and purge',
|
content: 'A post to delete/restore and purge',
|
||||||
}, (err, replyData) => {
|
|
||||||
assert.ifError(err);
|
|
||||||
callback(topicPostData, replyData);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
return [topicPostData, replyData];
|
||||||
}
|
}
|
||||||
|
|
||||||
let tid;
|
let tid;
|
||||||
let mainPid;
|
let mainPid;
|
||||||
let replyPid;
|
let replyPid;
|
||||||
|
|
||||||
before((done) => {
|
before(async () => {
|
||||||
createTopicWithReply((topicPostData, replyData) => {
|
const [topicPostData, replyData] = await createTopicWithReply();
|
||||||
tid = topicPostData.topicData.tid;
|
tid = topicPostData.topicData.tid;
|
||||||
mainPid = topicPostData.postData.pid;
|
mainPid = topicPostData.postData.pid;
|
||||||
replyPid = replyData.pid;
|
replyPid = replyData.pid;
|
||||||
privileges.categories.give(['groups:purge'], cid, 'registered-users', done);
|
await privileges.categories.give(['groups:purge'], cid, 'registered-users');
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should error with invalid data', (done) => {
|
it('should error with invalid data', async () => {
|
||||||
socketPosts.delete({ uid: voterUid }, null, (err) => {
|
try {
|
||||||
assert.equal(err.message, '[[error:invalid-data]]');
|
await apiPosts.delete({ uid: voterUid }, null);
|
||||||
done();
|
} catch (err) {
|
||||||
});
|
return assert.equal(err.message, '[[error:invalid-data]]');
|
||||||
|
}
|
||||||
|
assert(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should delete a post', (done) => {
|
it('should delete a post', async () => {
|
||||||
socketPosts.delete({ uid: voterUid }, { pid: replyPid, tid: tid }, (err) => {
|
await apiPosts.delete({ uid: voterUid }, { pid: replyPid, tid: tid });
|
||||||
assert.ifError(err);
|
const isDeleted = await posts.getPostField(replyPid, 'deleted');
|
||||||
posts.getPostField(replyPid, 'deleted', (err, isDeleted) => {
|
|
||||||
assert.ifError(err);
|
|
||||||
assert.strictEqual(isDeleted, 1);
|
assert.strictEqual(isDeleted, 1);
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not see post content if global mod does not have posts:view_deleted privilege', (done) => {
|
it('should not see post content if global mod does not have posts:view_deleted privilege', (done) => {
|
||||||
@@ -383,64 +376,27 @@ describe('Post\'s', () => {
|
|||||||
], done);
|
], done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should restore a post', (done) => {
|
it('should restore a post', async () => {
|
||||||
socketPosts.restore({ uid: voterUid }, { pid: replyPid, tid: tid }, (err) => {
|
await apiPosts.restore({ uid: voterUid }, { pid: replyPid, tid: tid });
|
||||||
assert.ifError(err);
|
const isDeleted = await posts.getPostField(replyPid, 'deleted');
|
||||||
posts.getPostField(replyPid, 'deleted', (err, isDeleted) => {
|
|
||||||
assert.ifError(err);
|
|
||||||
assert.strictEqual(isDeleted, 0);
|
assert.strictEqual(isDeleted, 0);
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should delete posts', (done) => {
|
it('should delete topic if last main post is deleted', async () => {
|
||||||
socketPosts.deletePosts({ uid: globalModUid }, { pids: [replyPid, mainPid] }, (err) => {
|
const data = await topics.post({ uid: voterUid, cid: cid, title: 'test topic', content: 'test topic' });
|
||||||
assert.ifError(err);
|
await apiPosts.delete({ uid: globalModUid }, { pid: data.postData.pid });
|
||||||
posts.getPostField(replyPid, 'deleted', (err, deleted) => {
|
const deleted = await topics.getTopicField(data.topicData.tid, 'deleted');
|
||||||
assert.ifError(err);
|
|
||||||
assert.strictEqual(deleted, 1);
|
assert.strictEqual(deleted, 1);
|
||||||
posts.getPostField(mainPid, 'deleted', (err, deleted) => {
|
|
||||||
assert.ifError(err);
|
|
||||||
assert.strictEqual(deleted, 1);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should delete topic if last main post is deleted', (done) => {
|
it('should purge posts and purge topic', async () => {
|
||||||
topics.post({ uid: voterUid, cid: cid, title: 'test topic', content: 'test topic' }, (err, data) => {
|
const [topicPostData, replyData] = await createTopicWithReply();
|
||||||
assert.ifError(err);
|
await apiPosts.purge({ uid: voterUid }, { pid: replyData.pid });
|
||||||
socketPosts.deletePosts({ uid: globalModUid }, { pids: [data.postData.pid] }, (err) => {
|
await apiPosts.purge({ uid: voterUid }, { pid: topicPostData.postData.pid });
|
||||||
assert.ifError(err);
|
const pidExists = await posts.exists(replyData.pid);
|
||||||
topics.getTopicField(data.topicData.tid, 'deleted', (err, deleted) => {
|
assert.strictEqual(pidExists, false);
|
||||||
assert.ifError(err);
|
const tidExists = await topics.exists(topicPostData.topicData.tid);
|
||||||
assert.strictEqual(deleted, 1);
|
assert.strictEqual(tidExists, false);
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should purge posts and purge topic', (done) => {
|
|
||||||
createTopicWithReply((topicPostData, replyData) => {
|
|
||||||
socketPosts.purgePosts({ uid: voterUid }, {
|
|
||||||
pids: [replyData.pid, topicPostData.postData.pid],
|
|
||||||
tid: topicPostData.topicData.tid,
|
|
||||||
}, (err) => {
|
|
||||||
assert.ifError(err);
|
|
||||||
posts.exists(`post:${replyData.pid}`, (err, exists) => {
|
|
||||||
assert.ifError(err);
|
|
||||||
assert.equal(exists, false);
|
|
||||||
topics.exists(topicPostData.topicData.tid, (err, exists) => {
|
|
||||||
assert.ifError(err);
|
|
||||||
assert(!exists);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user