From f359a76702165169b536b733feca1bd268cd6cb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Wed, 26 Jul 2023 09:58:16 -0400 Subject: [PATCH] feat: #11814, dont check content len for admins --- public/src/modules/uploadHelpers.js | 2 +- src/controllers/uploads.js | 4 ++-- src/topics/create.js | 26 ++++++++++++++++---------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/public/src/modules/uploadHelpers.js b/public/src/modules/uploadHelpers.js index e532054288..ce6cb08476 100644 --- a/public/src/modules/uploadHelpers.js +++ b/public/src/modules/uploadHelpers.js @@ -160,7 +160,7 @@ define('uploadHelpers', ['alerts'], function (alerts) { if ((isImage && !app.user.privileges['upload:post:image']) || (!isImage && !app.user.privileges['upload:post:file'])) { return alerts.error('[[error:no-privileges]]'); } - if (files[i].size > parseInt(config.maximumFileSize, 10) * 1024) { + if (!app.user.isAdmin && files[i].size > parseInt(config.maximumFileSize, 10) * 1024) { options.uploadForm[0].reset(); return alerts.error('[[error:file-too-big, ' + config.maximumFileSize + ']]'); } diff --git a/src/controllers/uploads.js b/src/controllers/uploads.js index 46871ca076..d5105d25f1 100644 --- a/src/controllers/uploads.js +++ b/src/controllers/uploads.js @@ -163,8 +163,8 @@ uploadsController.uploadFile = async function (uid, uploadedFile) { if (!uploadedFile) { throw new Error('[[error:invalid-file]]'); } - - if (uploadedFile.size > meta.config.maximumFileSize * 1024) { + const isAdmin = await user.isAdministrator(uid); + if (!isAdmin && uploadedFile.size > meta.config.maximumFileSize * 1024) { throw new Error(`[[error:file-too-big, ${meta.config.maximumFileSize}]]`); } diff --git a/src/topics/create.js b/src/topics/create.js index 5d631cce27..f962b21ddf 100644 --- a/src/topics/create.js +++ b/src/topics/create.js @@ -80,23 +80,26 @@ module.exports = function (Topics) { data = await plugins.hooks.fire('filter:topic.post', data); const { uid } = data; + const [categoryExists, canCreate, canTag, isAdmin] = await Promise.all([ + categories.exists(data.cid), + privileges.categories.can('topics:create', data.cid, uid), + privileges.categories.can('topics:tag', data.cid, uid), + privileges.users.isAdministrator(uid), + ]); + data.title = String(data.title).trim(); data.tags = data.tags || []; data.content = String(data.content || '').trimEnd(); + if (!isAdmin) { + Topics.checkTitle(data.title); + } - Topics.checkTitle(data.title); await Topics.validateTags(data.tags, data.cid, uid); data.tags = await Topics.filterTags(data.tags, data.cid); - if (!data.fromQueue) { + if (!data.fromQueue && !isAdmin) { Topics.checkContent(data.content); } - const [categoryExists, canCreate, canTag] = await Promise.all([ - categories.exists(data.cid), - privileges.categories.can('topics:create', data.cid, uid), - privileges.categories.can('topics:tag', data.cid, uid), - ]); - if (!categoryExists) { throw new Error('[[error:no-category]]'); } @@ -159,7 +162,10 @@ module.exports = function (Topics) { const { tid } = data; const { uid } = data; - const topicData = await Topics.getTopicData(tid); + const [topicData, isAdmin] = await Promise.all([ + Topics.getTopicData(tid), + privileges.users.isAdministrator(uid), + ]); await canReply(data, topicData); @@ -168,7 +174,7 @@ module.exports = function (Topics) { await guestHandleValid(data); data.content = String(data.content || '').trimEnd(); - if (!data.fromQueue) { + if (!data.fromQueue && !isAdmin) { await user.isReadyToPost(uid, data.cid); Topics.checkContent(data.content); }