Post queue write api (#13473)

* move post queue from socket.io to rest api

* move harmony post-queue to core

add canEdit, allow users to edit their queued posts

* fix: openapi spec

* lint: whitespace
This commit is contained in:
Barış Uşaklı
2025-06-05 07:15:45 -04:00
committed by GitHub
parent 6d40a2118c
commit 4fbcfae8b1
13 changed files with 521 additions and 259 deletions

View File

@@ -985,15 +985,15 @@ describe('Post\'s', () => {
assert.equal(posts[1].data.content, 'this is a queued reply');
});
it('should error if data is invalid', (done) => {
socketPosts.editQueuedContent({ uid: globalModUid }, null, (err) => {
assert.equal(err.message, '[[error:invalid-data]]');
done();
});
it('should error if data is invalid', async () => {
await assert.rejects(
apiPosts.editQueuedPost({ uid: globalModUid }, null),
{ message: '[[error:invalid-data]]' },
);
});
it('should edit post in queue', async () => {
await socketPosts.editQueuedContent({ uid: globalModUid }, { id: queueId, content: 'newContent' });
await apiPosts.editQueuedPost({ uid: globalModUid }, { id: queueId, content: 'newContent' });
const { body } = await request.get(`${nconf.get('url')}/api/post-queue`, { jar });
const { posts } = body;
assert.equal(posts[1].type, 'reply');
@@ -1001,7 +1001,7 @@ describe('Post\'s', () => {
});
it('should edit topic title in queue', async () => {
await socketPosts.editQueuedContent({ uid: globalModUid }, { id: topicQueueId, title: 'new topic title' });
await apiPosts.editQueuedPost({ uid: globalModUid }, { id: topicQueueId, title: 'new topic title' });
const { body } = await request.get(`${nconf.get('url')}/api/post-queue`, { jar });
const { posts } = body;
assert.equal(posts[0].type, 'topic');
@@ -1009,39 +1009,39 @@ describe('Post\'s', () => {
});
it('should edit topic category in queue', async () => {
await socketPosts.editQueuedContent({ uid: globalModUid }, { id: topicQueueId, cid: 2 });
await apiPosts.editQueuedPost({ uid: globalModUid }, { id: topicQueueId, cid: 2 });
const { body } = await request.get(`${nconf.get('url')}/api/post-queue`, { jar });
const { posts } = body;
assert.equal(posts[0].type, 'topic');
assert.equal(posts[0].data.cid, 2);
await socketPosts.editQueuedContent({ uid: globalModUid }, { id: topicQueueId, cid: cid });
await apiPosts.editQueuedPost({ uid: globalModUid }, { id: topicQueueId, cid: cid });
});
it('should prevent regular users from approving posts', (done) => {
socketPosts.accept({ uid: uid }, { id: queueId }, (err) => {
assert.equal(err.message, '[[error:no-privileges]]');
done();
});
it('should prevent regular users from approving posts', async () => {
await assert.rejects(
apiPosts.acceptQueuedPost({ uid: uid }, { id: queueId }),
{ message: '[[error:no-privileges]]' },
);
});
it('should prevent regular users from approving non existing posts', (done) => {
socketPosts.accept({ uid: uid }, { id: 123123 }, (err) => {
assert.equal(err.message, '[[error:no-post]]');
done();
});
it('should prevent regular users from approving non existing posts', async () => {
await assert.rejects(
apiPosts.acceptQueuedPost({ uid: uid }, { id: 123123 }),
{ message: '[[error:no-post]]' },
);
});
it('should accept queued posts and submit', async () => {
const ids = await db.getSortedSetRange('post:queue', 0, -1);
await socketPosts.accept({ uid: globalModUid }, { id: ids[0] });
await socketPosts.accept({ uid: globalModUid }, { id: ids[1] });
await apiPosts.acceptQueuedPost({ uid: globalModUid }, { id: ids[0] });
await apiPosts.acceptQueuedPost({ uid: globalModUid }, { id: ids[1] });
});
it('should not crash if id does not exist', (done) => {
socketPosts.reject({ uid: globalModUid }, { id: '123123123' }, (err) => {
assert.equal(err.message, '[[error:no-post]]');
done();
});
it('should not crash if id does not exist', async () => {
await assert.rejects(
apiPosts.removeQueuedPost({ uid: globalModUid }, { id: '123123123' }),
{ message: '[[error:no-post]]' },
);
});
it('should bypass post queue if user is in exempt group', async () => {