Skip to content

Node.js based forum software built for the modern web

fix: closes #14566, fix topics:tag privilege

Barış Soner Uşaklı427d86fd5c5e
diff --git a/src/api/topics.js b/src/api/topics.js
index 5eb4c22219..94dcb6695c 100644
--- a/src/api/topics.js
+++ b/src/api/topics.js
@@ -175,7 +175,7 @@ topicsAPI.unfollow = async function (caller, data) {
};
topicsAPI.updateTags = async (caller, { tid, tags }) => {
- if (!await privileges.topics.canEdit(tid, caller.uid)) {
+ if (!await privileges.topics.canTag(tid, caller.uid)) {
throw new Error('[[error:no-privileges]]');
}
@@ -186,7 +186,7 @@ topicsAPI.updateTags = async (caller, { tid, tags }) => {
};
topicsAPI.addTags = async (caller, { tid, tags }) => {
- if (!await privileges.topics.canEdit(tid, caller.uid)) {
+ if (!await privileges.topics.canTag(tid, caller.uid)) {
throw new Error('[[error:no-privileges]]');
}
@@ -199,7 +199,7 @@ topicsAPI.addTags = async (caller, { tid, tags }) => {
};
topicsAPI.deleteTags = async (caller, { tid }) => {
- if (!await privileges.topics.canEdit(tid, caller.uid)) {
+ if (!await privileges.topics.canTag(tid, caller.uid)) {
throw new Error('[[error:no-privileges]]');
}
diff --git a/src/privileges/topics.js b/src/privileges/topics.js
index 78f25fd3b9..a929f7bd5d 100644
--- a/src/privileges/topics.js
+++ b/src/privileges/topics.js
@@ -199,6 +199,15 @@ privsTopics.canDelete = async function (tid, uid) {
return allowedTo[0] && ((isOwner && (deleterUid === 0 || deleterUid === topicData.uid)) || isModerator);
};
+privsTopics.canTag = async function (tid, uid) {
+ const [isOwner, canTag, isAdminOrMod] = await Promise.all([
+ topics.isOwner(tid, uid),
+ privsTopics.can('topics:tag', tid, uid),
+ privsTopics.isAdminOrMod(tid, uid),
+ ]);
+ return (isOwner && canTag) || isAdminOrMod;
+};
+
privsTopics.canEdit = async function (tid, uid) {
return await privsTopics.isOwnerOrAdminOrMod(tid, uid);
};