From 3d595a52caf196f54d3bf1705127669116a760ae Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Fri, 26 Jan 2018 18:12:23 +0100 Subject: [PATCH] FIX: improves UI state when no extensions are allowed for upload --- .../components/composer-editor.js.es6 | 24 +++++++++++++------ .../discourse/lib/utilities.js.es6 | 17 +++++++++++++ .../templates/components/composer-editor.hbs | 2 +- config/locales/client.en.yml | 1 + 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/discourse/components/composer-editor.js.es6 b/app/assets/javascripts/discourse/components/composer-editor.js.es6 index 968e1ade9a3..09767831405 100644 --- a/app/assets/javascripts/discourse/components/composer-editor.js.es6 +++ b/app/assets/javascripts/discourse/components/composer-editor.js.es6 @@ -13,6 +13,8 @@ import { tinyAvatar, displayErrorForUpload, getUploadMarkdown, validateUploadedFiles, + authorizesOneOrMoreExtensions, + authorizesOneOrMoreImageExtensions, formatUsername, clipboardData } from 'discourse/lib/utilities'; @@ -36,6 +38,12 @@ export default Ember.Component.extend({ return `[${I18n.t('uploading')}]() `; }, + @computed() + replyPlaceholder() { + const key = authorizesOneOrMoreImageExtensions() ? "reply_placeholder" : "reply_placeholder_no_images"; + return `composer.${key}`; + }, + @observes('composer.uploadCancelled') _cancelUpload() { if (!this.get('composer.uploadCancelled')) { return; } @@ -662,13 +670,15 @@ export default Ember.Component.extend({ unshift: true }); - toolbar.addButton({ - id: 'upload', - group: 'insertions', - icon: 'upload', - title: 'upload', - sendAction: 'showUploadModal' - }); + if (authorizesOneOrMoreExtensions()) { + toolbar.addButton({ + id: 'upload', + group: 'insertions', + icon: 'upload', + title: 'upload', + sendAction: 'showUploadModal' + }); + } toolbar.addButton({ id: 'options', diff --git a/app/assets/javascripts/discourse/lib/utilities.js.es6 b/app/assets/javascripts/discourse/lib/utilities.js.es6 index 9d35e18fc9a..1d24485e0fc 100644 --- a/app/assets/javascripts/discourse/lib/utilities.js.es6 +++ b/app/assets/javascripts/discourse/lib/utilities.js.es6 @@ -193,6 +193,8 @@ export function validateUploadedFiles(files, opts) { } export function validateUploadedFile(file, opts) { + if (!authorizesOneOrMoreExtensions()) return false; + opts = opts || {}; const name = file && file.name; @@ -277,6 +279,21 @@ export function authorizesAllExtensions() { return Discourse.SiteSettings.authorized_extensions.indexOf("*") >= 0; } +export function authorizesOneOrMoreExtensions() { + if (authorizesAllExtensions()) return true; + + return Discourse.SiteSettings.authorized_extensions + .split("|") + .filter(ext => ext) + .length > 0; +} + +export function authorizesOneOrMoreImageExtensions() { + if (authorizesAllExtensions()) return true; + + return imagesExtensions().length > 0; +} + export function isAnImage(path) { return (/\.(png|jpe?g|gif|bmp|tiff?|svg|webp|ico)$/i).test(path); } diff --git a/app/assets/javascripts/discourse/templates/components/composer-editor.hbs b/app/assets/javascripts/discourse/templates/components/composer-editor.hbs index a118ad5841f..037ee5440ff 100644 --- a/app/assets/javascripts/discourse/templates/components/composer-editor.hbs +++ b/app/assets/javascripts/discourse/templates/components/composer-editor.hbs @@ -1,7 +1,7 @@ {{d-editor tabindex="4" value=composer.reply - placeholder="composer.reply_placeholder" + placeholder=replyPlaceholder previewUpdated="previewUpdated" markdownOptions=markdownOptions extraButtons="extraButtons" diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 6d8082a229e..69184d393fc 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -1247,6 +1247,7 @@ en: topic_featured_link_placeholder: "Enter link shown with title." remove_featured_link: "Remove link from topic." reply_placeholder: "Type here. Use Markdown, BBCode, or HTML to format. Drag or paste images." + reply_placeholder_no_images: "Type here. Use Markdown, BBCode, or HTML to format." view_new_post: "View your new post." saving: "Saving" saved: "Saved!"