feat: #9506, allow seeing and editing your queued posts

allow regular users access to post queue
allow regular users to edit their queued post/topic title
allow regular users to remove their post from post queue
ability to send a notification to user without removing from post queue
allow accessing single post queue items from notifications
This commit is contained in:
Barış Soner Uşaklı
2021-12-16 22:25:39 -05:00
parent b8896d1328
commit c4042c70de
10 changed files with 96 additions and 41 deletions

View File

@@ -42,7 +42,9 @@ module.exports = function (Posts) {
});
cache.set('post-queue', _.cloneDeep(postData));
}
if (filter.id) {
postData = postData.filter(p => p.id === filter.id);
}
if (options.metadata) {
await Promise.all(postData.map(p => addMetaData(p)));
}
@@ -161,7 +163,7 @@ module.exports = function (Posts) {
mergeId: 'post-queue',
bodyShort: '[[notifications:post_awaiting_review]]',
bodyLong: bodyLong,
path: '/post-queue',
path: `/post-queue/${id}`,
});
await notifications.push(notifObj, uids);
return {
@@ -235,7 +237,7 @@ module.exports = function (Posts) {
Posts.removeFromQueue = async function (id) {
const data = await getParsedObject(id);
if (!data) {
return;
return null;
}
await removeQueueNotification(id);
await db.sortedSetRemove('post:queue', id);
@@ -247,7 +249,7 @@ module.exports = function (Posts) {
Posts.submitFromQueue = async function (id) {
const data = await getParsedObject(id);
if (!data) {
return;
return null;
}
if (data.type === 'topic') {
const result = await createTopic(data.data);
@@ -260,6 +262,10 @@ module.exports = function (Posts) {
return data;
};
Posts.getFromQueue = async function (id) {
return await getParsedObject(id);
};
async function getParsedObject(id) {
const data = await db.getObject(`post:queue:${id}`);
if (!data) {
@@ -288,7 +294,7 @@ module.exports = function (Posts) {
}
Posts.editQueuedContent = async function (uid, editData) {
const canEditQueue = await Posts.canEditQueue(uid, editData);
const canEditQueue = await Posts.canEditQueue(uid, editData, 'edit');
if (!canEditQueue) {
throw new Error('[[error:no-privileges]]');
}
@@ -309,7 +315,7 @@ module.exports = function (Posts) {
cache.del('post-queue');
};
Posts.canEditQueue = async function (uid, editData) {
Posts.canEditQueue = async function (uid, editData, action) {
const [isAdminOrGlobalMod, data] = await Promise.all([
user.isAdminOrGlobalMod(uid),
getParsedObject(editData.id),
@@ -317,8 +323,8 @@ module.exports = function (Posts) {
if (!data) {
return false;
}
if (isAdminOrGlobalMod) {
const selfPost = parseInt(uid, 10) === parseInt(data.uid, 10);
if (isAdminOrGlobalMod || ((action === 'reject' || action === 'edit') && selfPost)) {
return true;
}