mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
Merge pull request #5410 from discourse/disable-mentions
FEATURE: Disable mentions
This commit is contained in:
commit
94d58320fc
14 changed files with 154 additions and 89 deletions
|
@ -77,6 +77,7 @@ export default Ember.Component.extend({
|
||||||
const $input = this.$('.d-editor-input');
|
const $input = this.$('.d-editor-input');
|
||||||
const $preview = this.$('.d-editor-preview-wrapper');
|
const $preview = this.$('.d-editor-preview-wrapper');
|
||||||
|
|
||||||
|
if (this.siteSettings.enable_mentions) {
|
||||||
$input.autocomplete({
|
$input.autocomplete({
|
||||||
template: findRawTemplate('user-selector-autocomplete'),
|
template: findRawTemplate('user-selector-autocomplete'),
|
||||||
dataSource: term => userSearch({
|
dataSource: term => userSearch({
|
||||||
|
@ -87,6 +88,7 @@ export default Ember.Component.extend({
|
||||||
key: "@",
|
key: "@",
|
||||||
transformComplete: v => v.username || v.name
|
transformComplete: v => v.username || v.name
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (this._enableAdvancedEditorPreviewSync()) {
|
if (this._enableAdvancedEditorPreviewSync()) {
|
||||||
this._initInputPreviewSync($input, $preview);
|
this._initInputPreviewSync($input, $preview);
|
||||||
|
|
|
@ -154,6 +154,7 @@ export function applySearchAutocomplete($input, siteSettings, appEvents, options
|
||||||
afterComplete
|
afterComplete
|
||||||
}, options));
|
}, options));
|
||||||
|
|
||||||
|
if (Discourse.SiteSettings.enable_mentions) {
|
||||||
$input.autocomplete(_.merge({
|
$input.autocomplete(_.merge({
|
||||||
template: findRawTemplate('user-selector-autocomplete'),
|
template: findRawTemplate('user-selector-autocomplete'),
|
||||||
key: "@",
|
key: "@",
|
||||||
|
@ -163,4 +164,5 @@ export function applySearchAutocomplete($input, siteSettings, appEvents, options
|
||||||
dataSource: term => userSearch({ term, includeGroups: true }),
|
dataSource: term => userSearch({ term, includeGroups: true }),
|
||||||
afterComplete
|
afterComplete
|
||||||
}, options));
|
}, options));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
{{#mobile-nav class='group-activity-nav' desktopClass="pull-left nav nav-stacked" currentPath=application.currentPath}}
|
{{#mobile-nav class='group-activity-nav' desktopClass="pull-left nav nav-stacked" currentPath=application.currentPath}}
|
||||||
{{group-activity-filter filter="posts" categoryId=category_id}}
|
{{group-activity-filter filter="posts" categoryId=category_id}}
|
||||||
{{group-activity-filter filter="topics" categoryId=category_id}}
|
{{group-activity-filter filter="topics" categoryId=category_id}}
|
||||||
|
{{#if siteSettings.enable_mentions}}
|
||||||
{{group-activity-filter filter="mentions" categoryId=category_id}}
|
{{group-activity-filter filter="mentions" categoryId=category_id}}
|
||||||
|
{{/if}}
|
||||||
{{#if showGroupMessages}}
|
{{#if showGroupMessages}}
|
||||||
{{group-activity-filter filter="messages"}}
|
{{group-activity-filter filter="messages"}}
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
|
@ -15,11 +15,13 @@
|
||||||
{{i18n 'user_action_groups.2'}}
|
{{i18n 'user_action_groups.2'}}
|
||||||
{{/link-to}}
|
{{/link-to}}
|
||||||
</li>
|
</li>
|
||||||
|
{{#if siteSettings.enable_mentions}}
|
||||||
<li>
|
<li>
|
||||||
{{#link-to 'userNotifications.mentions'}}
|
{{#link-to 'userNotifications.mentions'}}
|
||||||
{{i18n 'user_action_groups.7'}}
|
{{i18n 'user_action_groups.7'}}
|
||||||
{{/link-to}}
|
{{/link-to}}
|
||||||
</li>
|
</li>
|
||||||
|
{{/if}}
|
||||||
<li>
|
<li>
|
||||||
{{#link-to 'userNotifications.edits'}}
|
{{#link-to 'userNotifications.edits'}}
|
||||||
{{i18n 'user_action_groups.11'}}
|
{{i18n 'user_action_groups.11'}}
|
||||||
|
|
|
@ -38,6 +38,10 @@ function addMention(buffer, matches, state) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function setup(helper) {
|
export function setup(helper) {
|
||||||
|
helper.registerOptions((opts, siteSettings) => {
|
||||||
|
opts.features.mentions = !!siteSettings.enable_mentions;
|
||||||
|
});
|
||||||
|
|
||||||
helper.registerPlugin(md => {
|
helper.registerPlugin(md => {
|
||||||
|
|
||||||
const rule = {
|
const rule = {
|
||||||
|
|
|
@ -98,6 +98,7 @@ class GroupsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def mentions
|
def mentions
|
||||||
|
raise Discourse::NotFound unless SiteSetting.enable_mentions?
|
||||||
group = find_group(:group_id)
|
group = find_group(:group_id)
|
||||||
posts = group.mentioned_posts_for(
|
posts = group.mentioned_posts_for(
|
||||||
guardian,
|
guardian,
|
||||||
|
@ -107,6 +108,7 @@ class GroupsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def mentions_feed
|
def mentions_feed
|
||||||
|
raise Discourse::NotFound unless SiteSetting.enable_mentions?
|
||||||
group = find_group(:group_id)
|
group = find_group(:group_id)
|
||||||
@posts = group.mentioned_posts_for(
|
@posts = group.mentioned_posts_for(
|
||||||
guardian,
|
guardian,
|
||||||
|
|
|
@ -7,12 +7,13 @@ class UserActionsController < ApplicationController
|
||||||
per_chunk = 30
|
per_chunk = 30
|
||||||
|
|
||||||
user = fetch_user_from_params(include_inactive: current_user.try(:staff?) || (current_user && SiteSetting.show_inactive_accounts))
|
user = fetch_user_from_params(include_inactive: current_user.try(:staff?) || (current_user && SiteSetting.show_inactive_accounts))
|
||||||
|
action_types = (params[:filter] || "").split(",").map(&:to_i)
|
||||||
|
|
||||||
opts = { user_id: user.id,
|
opts = { user_id: user.id,
|
||||||
user: user,
|
user: user,
|
||||||
offset: params[:offset].to_i,
|
offset: params[:offset].to_i,
|
||||||
limit: per_chunk,
|
limit: per_chunk,
|
||||||
action_types: (params[:filter] || "").split(",").map(&:to_i),
|
action_types: action_types,
|
||||||
guardian: guardian,
|
guardian: guardian,
|
||||||
ignore_private_messages: params[:filter] ? false : true }
|
ignore_private_messages: params[:filter] ? false : true }
|
||||||
|
|
||||||
|
|
|
@ -209,6 +209,11 @@ SQL
|
||||||
else
|
else
|
||||||
builder.where("a.user_id = :user_id", user_id: user_id.to_i)
|
builder.where("a.user_id = :user_id", user_id: user_id.to_i)
|
||||||
builder.where("a.action_type in (:action_types)", action_types: action_types) if action_types && action_types.length > 0
|
builder.where("a.action_type in (:action_types)", action_types: action_types) if action_types && action_types.length > 0
|
||||||
|
|
||||||
|
unless SiteSetting.enable_mentions?
|
||||||
|
builder.where("a.action_type <> :mention_type", mention_type: UserAction::MENTION)
|
||||||
|
end
|
||||||
|
|
||||||
builder
|
builder
|
||||||
.order_by("a.created_at desc")
|
.order_by("a.created_at desc")
|
||||||
.offset(offset.to_i)
|
.offset(offset.to_i)
|
||||||
|
|
|
@ -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."
|
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_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)"
|
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."
|
create_thumbnails: "Create thumbnails and lightbox images that are too large to fit in a post."
|
||||||
|
|
||||||
|
|
|
@ -537,6 +537,9 @@ posting:
|
||||||
default: 1
|
default: 1
|
||||||
client: true
|
client: true
|
||||||
post_undo_action_window_mins: 10
|
post_undo_action_window_mins: 10
|
||||||
|
enable_mentions:
|
||||||
|
default: true
|
||||||
|
client: true
|
||||||
max_mentions_per_post: 10
|
max_mentions_per_post: 10
|
||||||
max_users_notified_per_group_mention: 100
|
max_users_notified_per_group_mention: 100
|
||||||
newuser_max_replies_per_topic: 3
|
newuser_max_replies_per_topic: 3
|
||||||
|
|
|
@ -83,6 +83,12 @@ describe GroupsController do
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
expect(response.content_type).to eq('application/rss+xml')
|
expect(response.content_type).to eq('application/rss+xml')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'fails when disabled' do
|
||||||
|
SiteSetting.enable_mentions = false
|
||||||
|
get :mentions_feed, params: { group_id: group.name }, format: :rss
|
||||||
|
expect(response).not_to be_success
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,6 +33,7 @@ describe UserAction do
|
||||||
}.merge(opts))
|
}.merge(opts))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "integration" do
|
||||||
before do
|
before do
|
||||||
# Create some test data using a helper
|
# Create some test data using a helper
|
||||||
log_test_action
|
log_test_action
|
||||||
|
@ -100,9 +101,36 @@ describe UserAction do
|
||||||
expect(action.acting_user_id).to eq(admin.id)
|
expect(action.acting_user_id).to eq(admin.id)
|
||||||
expect(action.action_type).to eq(UserAction::EDIT)
|
expect(action.action_type).to eq(UserAction::EDIT)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "mentions" do
|
||||||
|
before do
|
||||||
|
log_test_action(action_type: UserAction::MENTION)
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:stream) do
|
||||||
|
UserAction.stream(
|
||||||
|
user_id: user.id,
|
||||||
|
guardian: Guardian.new(user)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "is returned by the stream" do
|
||||||
|
expect(stream).to be_present
|
||||||
|
end
|
||||||
|
|
||||||
|
it "isn't returned when mentions aren't enabled" do
|
||||||
|
SiteSetting.enable_mentions = false
|
||||||
|
expect(stream).to be_blank
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "mentions" do
|
||||||
|
it "returns the mention in the stream" do
|
||||||
|
end
|
||||||
|
end
|
||||||
describe 'when user likes' do
|
describe 'when user likes' do
|
||||||
|
|
||||||
let(:post) { Fabricate(:post) }
|
let(:post) { Fabricate(:post) }
|
||||||
|
|
|
@ -88,6 +88,7 @@ Discourse.SiteSettingsOriginal = {
|
||||||
"highlighted_languages":"apache|bash|cs|cpp|css|coffeescript|diff|xml|http|ini|json|java|javascript|makefile|markdown|nginx|objectivec|ruby|perl|php|python|sql|handlebars",
|
"highlighted_languages":"apache|bash|cs|cpp|css|coffeescript|diff|xml|http|ini|json|java|javascript|makefile|markdown|nginx|objectivec|ruby|perl|php|python|sql|handlebars",
|
||||||
"enable_emoji":true,
|
"enable_emoji":true,
|
||||||
"emoji_set":"emoji_one",
|
"emoji_set":"emoji_one",
|
||||||
"desktop_category_page_style":"categories_and_latest_topics"
|
"desktop_category_page_style":"categories_and_latest_topics",
|
||||||
|
"enable_mentions":true
|
||||||
};
|
};
|
||||||
Discourse.SiteSettings = jQuery.extend(true, {}, Discourse.SiteSettingsOriginal);
|
Discourse.SiteSettings = jQuery.extend(true, {}, Discourse.SiteSettingsOriginal);
|
||||||
|
|
|
@ -8,6 +8,7 @@ QUnit.module("lib:pretty-text");
|
||||||
const rawOpts = {
|
const rawOpts = {
|
||||||
siteSettings: {
|
siteSettings: {
|
||||||
enable_emoji: true,
|
enable_emoji: true,
|
||||||
|
enable_mentions: true,
|
||||||
emoji_set: 'emoji_one',
|
emoji_set: 'emoji_one',
|
||||||
highlighted_languages: 'json|ruby|javascript',
|
highlighted_languages: 'json|ruby|javascript',
|
||||||
default_code_lang: 'auto',
|
default_code_lang: 'auto',
|
||||||
|
@ -282,7 +283,6 @@ QUnit.test("Quotes", assert => {
|
||||||
});
|
});
|
||||||
|
|
||||||
QUnit.test("Mentions", assert => {
|
QUnit.test("Mentions", assert => {
|
||||||
|
|
||||||
const alwaysTrue = { mentionLookup: (function() { return "user"; }) };
|
const alwaysTrue = { mentionLookup: (function() { return "user"; }) };
|
||||||
|
|
||||||
assert.cookedOptions("Hello @sam", alwaysTrue,
|
assert.cookedOptions("Hello @sam", alwaysTrue,
|
||||||
|
@ -370,6 +370,12 @@ QUnit.test("Mentions", assert => {
|
||||||
"it allows mentions within HTML tags");
|
"it allows mentions within HTML tags");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QUnit.test("Mentions - disabled", assert => {
|
||||||
|
assert.cookedOptions("@eviltrout",
|
||||||
|
{ siteSettings : { enable_mentions: false }},
|
||||||
|
"<p>@eviltrout</p>");
|
||||||
|
});
|
||||||
|
|
||||||
QUnit.test("Category hashtags", assert => {
|
QUnit.test("Category hashtags", assert => {
|
||||||
const alwaysTrue = { categoryHashtagLookup: (function() { return ["http://test.discourse.org/category-hashtag", "category-hashtag"]; }) };
|
const alwaysTrue = { categoryHashtagLookup: (function() { return ["http://test.discourse.org/category-hashtag", "category-hashtag"]; }) };
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue