diff --git a/app/assets/javascripts/discourse/components/composer-editor.js.es6 b/app/assets/javascripts/discourse/components/composer-editor.js.es6 index 3d25c3a4f35..29e2d313aa9 100644 --- a/app/assets/javascripts/discourse/components/composer-editor.js.es6 +++ b/app/assets/javascripts/discourse/components/composer-editor.js.es6 @@ -77,16 +77,18 @@ export default Ember.Component.extend({ const $input = this.$('.d-editor-input'); const $preview = this.$('.d-editor-preview-wrapper'); - $input.autocomplete({ - template: findRawTemplate('user-selector-autocomplete'), - dataSource: term => userSearch({ - term, - topicId, - includeMentionableGroups: true - }), - key: "@", - transformComplete: v => v.username || v.name - }); + if (this.siteSettings.enable_mentions) { + $input.autocomplete({ + template: findRawTemplate('user-selector-autocomplete'), + dataSource: term => userSearch({ + term, + topicId, + includeMentionableGroups: true + }), + key: "@", + transformComplete: v => v.username || v.name + }); + } if (this._enableAdvancedEditorPreviewSync()) { this._initInputPreviewSync($input, $preview); diff --git a/app/assets/javascripts/discourse/lib/search.js.es6 b/app/assets/javascripts/discourse/lib/search.js.es6 index 266f374a65d..f64b74db943 100644 --- a/app/assets/javascripts/discourse/lib/search.js.es6 +++ b/app/assets/javascripts/discourse/lib/search.js.es6 @@ -154,13 +154,15 @@ export function applySearchAutocomplete($input, siteSettings, appEvents, options afterComplete }, options)); - $input.autocomplete(_.merge({ - template: findRawTemplate('user-selector-autocomplete'), - key: "@", - width: '100%', - treatAsTextarea: true, - transformComplete: v => v.username || v.name, - dataSource: term => userSearch({ term, includeGroups: true }), - afterComplete - }, options)); + if (Discourse.SiteSettings.enable_mentions) { + $input.autocomplete(_.merge({ + template: findRawTemplate('user-selector-autocomplete'), + key: "@", + width: '100%', + treatAsTextarea: true, + transformComplete: v => v.username || v.name, + dataSource: term => userSearch({ term, includeGroups: true }), + afterComplete + }, options)); + } }; diff --git a/app/assets/javascripts/pretty-text/engines/discourse-markdown/mentions.js.es6 b/app/assets/javascripts/pretty-text/engines/discourse-markdown/mentions.js.es6 index 7314bc1f98d..8484f7ba6c0 100644 --- a/app/assets/javascripts/pretty-text/engines/discourse-markdown/mentions.js.es6 +++ b/app/assets/javascripts/pretty-text/engines/discourse-markdown/mentions.js.es6 @@ -38,6 +38,10 @@ function addMention(buffer, matches, state) { } export function setup(helper) { + helper.registerOptions((opts, siteSettings) => { + opts.features.mentions = !!siteSettings.enable_mentions; + }); + helper.registerPlugin(md => { const rule = { diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 07c38b521ff..7bb5823f9e5 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1283,6 +1283,7 @@ en: newuser_max_replies_per_topic: "Maximum number of replies a new user can make in a single topic until someone replies to them." max_mentions_per_post: "Maximum number of @name notifications anyone can use in a post." max_users_notified_per_group_mention: "Maximum number of users that may receive a notification if a group is mentioned (if threshold is met no notifications will be raised)" + enable_mentions: "Allow users to mention other users." create_thumbnails: "Create thumbnails and lightbox images that are too large to fit in a post." diff --git a/config/site_settings.yml b/config/site_settings.yml index 38c102a19f6..3d004c32674 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -537,6 +537,9 @@ posting: default: 1 client: true post_undo_action_window_mins: 10 + enable_mentions: + default: true + client: true max_mentions_per_post: 10 max_users_notified_per_group_mention: 100 newuser_max_replies_per_topic: 3 diff --git a/test/javascripts/lib/pretty-text-test.js.es6 b/test/javascripts/lib/pretty-text-test.js.es6 index f68de877be8..65803e8b188 100644 --- a/test/javascripts/lib/pretty-text-test.js.es6 +++ b/test/javascripts/lib/pretty-text-test.js.es6 @@ -8,6 +8,7 @@ QUnit.module("lib:pretty-text"); const rawOpts = { siteSettings: { enable_emoji: true, + enable_mentions: true, emoji_set: 'emoji_one', highlighted_languages: 'json|ruby|javascript', default_code_lang: 'auto', @@ -282,7 +283,6 @@ QUnit.test("Quotes", assert => { }); QUnit.test("Mentions", assert => { - const alwaysTrue = { mentionLookup: (function() { return "user"; }) }; assert.cookedOptions("Hello @sam", alwaysTrue, @@ -370,6 +370,12 @@ QUnit.test("Mentions", assert => { "it allows mentions within HTML tags"); }); +QUnit.test("Mentions - disabled", assert => { + assert.cookedOptions("@eviltrout", + { siteSettings : { enable_mentions: false }}, + "
@eviltrout
"); +}); + QUnit.test("Category hashtags", assert => { const alwaysTrue = { categoryHashtagLookup: (function() { return ["http://test.discourse.org/category-hashtag", "category-hashtag"]; }) };