diff --git a/src/topics/create.js b/src/topics/create.js index 0d6ee1bc19..a141a2b722 100644 --- a/src/topics/create.js +++ b/src/topics/create.js @@ -15,6 +15,8 @@ const privileges = require('../privileges'); const categories = require('../categories'); const translator = require('../translator'); +console.log('Al Anoud'); + module.exports = function (Topics) { Topics.create = async function (data) { // This is an internal method, consider using Topics.post instead @@ -104,14 +106,21 @@ module.exports = function (Topics) { } } + // Check if the category exists if (!categoryExists) { throw new Error('[[error:no-category]]'); } - if (!canCreate || (!canTag && data.tags.length)) { + // Check if the user has the necessary privileges to create or tag + const cannotCreate = !canCreate; + const cannotTag = !canTag && data.tags.length; + + if (cannotCreate || cannotTag) { throw new Error('[[error:no-privileges]]'); } + console.log('Al Anoud: Refactored code executed'); + await guestHandleValid(data); if (!data.fromQueue) { await user.isReadyToPost(uid, data.cid);