diff --git a/install/data/defaults.json b/install/data/defaults.json index ae67dab4c6..090a1d4026 100644 --- a/install/data/defaults.json +++ b/install/data/defaults.json @@ -32,7 +32,6 @@ "registrationType": "normal", "registrationApprovalType": "normal", "allowAccountDelete": 1, - "allowFileUploads": 0, "privateUploads": 0, "allowedFileExtensions": "png,jpg,bmp,txt", "allowUserHomePage": 1, diff --git a/public/openapi/read.yaml b/public/openapi/read.yaml index 30f81ebc3c..7a7d1ce091 100644 --- a/public/openapi/read.yaml +++ b/public/openapi/read.yaml @@ -2795,8 +2795,6 @@ paths: type: boolean allowGuestHandles: type: boolean - allowFileUploads: - type: boolean allowTopicsThumbnail: type: boolean usePagination: diff --git a/src/controllers/api.js b/src/controllers/api.js index 7b9b404de1..faf4695533 100644 --- a/src/controllers/api.js +++ b/src/controllers/api.js @@ -34,7 +34,6 @@ apiController.loadConfig = async function (req) { useOutgoingLinksPage: meta.config.useOutgoingLinksPage === 1, outgoingLinksWhitelist: meta.config.useOutgoingLinksPage === 1 ? meta.config['outgoingLinks:whitelist'] : undefined, allowGuestHandles: meta.config.allowGuestHandles === 1, - allowFileUploads: meta.config.allowFileUploads === 1, allowTopicsThumbnail: meta.config.allowTopicsThumbnail === 1, usePagination: meta.config.usePagination === 1, disableChat: meta.config.disableChat === 1, diff --git a/src/controllers/uploads.js b/src/controllers/uploads.js index 36ca7959e8..efb93c196e 100644 --- a/src/controllers/uploads.js +++ b/src/controllers/uploads.js @@ -84,10 +84,6 @@ async function uploadAsFile(req, uploadedFile) { throw new Error('[[error:no-privileges]]'); } - if (!meta.config.allowFileUploads) { - throw new Error('[[error:uploads-are-disabled]]'); - } - const fileObj = await uploadsController.uploadFile(req.uid, uploadedFile); return { url: fileObj.url, diff --git a/src/upgrade.js b/src/upgrade.js index 73d489bcba..f85ca13f19 100644 --- a/src/upgrade.js +++ b/src/upgrade.js @@ -2,6 +2,7 @@ var async = require('async'); var path = require('path'); +var util = require('util'); var semver = require('semver'); var readline = require('readline'); var winston = require('winston'); @@ -140,7 +141,7 @@ Upgrade.process = function (files, skipCount, callback) { }, next); }, function (results, next) { - async.eachSeries(files, function (file, next) { + async.eachSeries(files, async (file) => { var scriptExport = require(file); var date = new Date(scriptExport.timestamp); var version = path.dirname(file).split('/').pop(); @@ -152,35 +153,34 @@ Upgrade.process = function (files, skipCount, callback) { date: date, }; - console.log(' → '.white + String('[' + [date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate()].join('/') + '] ').gray + String(scriptExport.name).reset + '...'); + process.stdout.write(' → '.white + String('[' + [date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate()].join('/') + '] ').gray + String(scriptExport.name).reset + '...'); // For backwards compatibility, cross-reference with schemaDate (if found). If a script's date is older, skip it if ((!results.schemaDate && !results.schemaLogCount) || (scriptExport.timestamp <= results.schemaDate && semver.lt(version, '1.5.0'))) { - readline.clearLine(process.stdout, 0); - readline.cursorTo(process.stdout, 0); - readline.moveCursor(process.stdout, 0, -1); - console.log(' → '.white + String('[' + [date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate()].join('/') + '] ').gray + String(scriptExport.name).reset + '... ' + 'skipped'.grey); - db.sortedSetAdd('schemaLog', Date.now(), path.basename(file, '.js'), next); + process.stdout.write(' skipped\n'.grey); + await db.sortedSetAdd('schemaLog', Date.now(), path.basename(file, '.js')); return; } + // Promisify method if necessary + if (scriptExport.method.constructor && scriptExport.method.constructor.name !== 'AsyncFunction') { + scriptExport.method = util.promisify(scriptExport.method); + } + // Do the upgrade... - scriptExport.method.bind({ - progress: progress, - })(function (err) { - if (err) { - console.error('Error occurred'); - return next(err); - } + try { + await scriptExport.method.bind({ + progress: progress, + })(); + } catch (err) { + console.error('Error occurred'); + throw err; + } - readline.clearLine(process.stdout, 0); - readline.cursorTo(process.stdout, 0); - readline.moveCursor(process.stdout, 0, -1); - console.log(' → '.white + String('[' + [date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate()].join('/') + '] ').gray + String(scriptExport.name).reset + '... ' + 'OK'.green); + process.stdout.write(' OK\n'.green); - // Record success in schemaLog - db.sortedSetAdd('schemaLog', Date.now(), path.basename(file, '.js'), next); - }); + // Record success in schemaLog + await db.sortedSetAdd('schemaLog', Date.now(), path.basename(file, '.js')); }, next); }, function (next) { diff --git a/src/upgrades/1.13.0/clean_flag_byCid.js b/src/upgrades/1.13.0/clean_flag_byCid.js index a8ea7188a8..ab350c417e 100644 --- a/src/upgrades/1.13.0/clean_flag_byCid.js +++ b/src/upgrades/1.13.0/clean_flag_byCid.js @@ -6,7 +6,7 @@ const batch = require('../../batch'); module.exports = { name: 'Clean flag byCid zsets', timestamp: Date.UTC(2019, 8, 24), - method: async function (callback) { + method: async function () { const progress = this.progress; await batch.processSortedSet('flags:datetime', async function (flagIds) { @@ -23,6 +23,5 @@ module.exports = { }, { progress: progress, }); - callback(); }, }; diff --git a/src/upgrades/1.13.0/clean_post_topic_hash.js b/src/upgrades/1.13.0/clean_post_topic_hash.js index 3b5c5cef36..8b35b50dac 100644 --- a/src/upgrades/1.13.0/clean_post_topic_hash.js +++ b/src/upgrades/1.13.0/clean_post_topic_hash.js @@ -6,11 +6,10 @@ const batch = require('../../batch'); module.exports = { name: 'Clean up post hash data', timestamp: Date.UTC(2019, 9, 7), - method: async function (callback) { + method: async function () { const progress = this.progress; await cleanPost(progress); await cleanTopic(progress); - callback(); }, }; diff --git a/src/upgrades/1.13.0/cleanup_old_notifications.js b/src/upgrades/1.13.0/cleanup_old_notifications.js index dcc1f28a42..95d446d810 100644 --- a/src/upgrades/1.13.0/cleanup_old_notifications.js +++ b/src/upgrades/1.13.0/cleanup_old_notifications.js @@ -7,7 +7,7 @@ const user = require('../../user'); module.exports = { name: 'Clean up old notifications and hash data', timestamp: Date.UTC(2019, 9, 7), - method: async function (callback) { + method: async function () { const progress = this.progress; const week = 604800000; const cutoffTime = Date.now() - week; @@ -47,6 +47,5 @@ module.exports = { batch: 500, progress: progress, }); - callback(); }, }; diff --git a/src/upgrades/1.13.3/fix_users_sorted_sets.js b/src/upgrades/1.13.3/fix_users_sorted_sets.js index 9afd97915f..9cf90bd855 100644 --- a/src/upgrades/1.13.3/fix_users_sorted_sets.js +++ b/src/upgrades/1.13.3/fix_users_sorted_sets.js @@ -6,7 +6,7 @@ const batch = require('../../batch'); module.exports = { name: 'Fix user sorted sets', timestamp: Date.UTC(2020, 4, 2), - method: async function (callback) { + method: async function () { const progress = this.progress; const nextUid = await db.getObjectField('global', 'nextUid'); const allUids = []; @@ -58,6 +58,5 @@ module.exports = { }); await db.setObjectField('global', 'userCount', totalUserCount); - callback(); }, }; diff --git a/src/upgrades/1.13.4/remove_allowFileUploads_priv.js b/src/upgrades/1.13.4/remove_allowFileUploads_priv.js new file mode 100644 index 0000000000..f75cbd078e --- /dev/null +++ b/src/upgrades/1.13.4/remove_allowFileUploads_priv.js @@ -0,0 +1,22 @@ +'use strict'; + +const db = require('../../database'); +const privileges = require('../../privileges'); + +module.exports = { + name: 'Removing file upload privilege if file uploads were disabled (`allowFileUploads`)', + timestamp: Date.UTC(2020, 4, 21), + method: async () => { + const allowFileUploads = parseInt(await db.getObjectField('config', 'allowFileUploads'), 10); + if (allowFileUploads === 1) { + await db.deleteObjectField('config', 'allowFileUploads'); + return; + } + + // Remove `upload:post:file` privilege for all groups + await privileges.categories.rescind(['upload:post:file'], 0, ['guests', 'registered-users', 'Global Moderators']); + + // Clean up the old option from the config hash + await db.deleteObjectField('config', 'allowFileUploads'); + }, +}; diff --git a/src/upgrades/TEMPLATE b/src/upgrades/TEMPLATE index 60722ab70c..98eb0288a6 100644 --- a/src/upgrades/TEMPLATE +++ b/src/upgrades/TEMPLATE @@ -1,17 +1,15 @@ 'use strict'; -var db = require('../../database'); - -var async = require('async'); -var winston = require('winston'); +const db = require('../../database'); +const winston = require('winston'); module.exports = { // you should use spaces // the underscores are there so you can double click to select the whole thing name: 'User_friendly_upgrade_script_name', // remember, month is zero-indexed (so January is 0, December is 11) - timestamp: Date.UTC(2019, 0, 1), - method: function (callback) { + timestamp: Date.UTC(2020, 0, 1), + method: async () => { // Do stuff here... }, }; diff --git a/src/views/admin/settings/uploads.tpl b/src/views/admin/settings/uploads.tpl index 3d63f999a1..dca5f135f4 100644 --- a/src/views/admin/settings/uploads.tpl +++ b/src/views/admin/settings/uploads.tpl @@ -6,13 +6,6 @@
-
- -
-