From c1e7a1b292221adad28c24f964c584d5aa528d09 Mon Sep 17 00:00:00 2001 From: Dan Ungureanu Date: Mon, 3 Jun 2019 05:23:23 +0300 Subject: [PATCH] UX: Merge settings related to muted tags. (#7656) --- .../controllers/preferences/categories.js.es6 | 5 ++++ .../templates/preferences/categories.hbs | 2 +- ...ove_muted_tags_from_latest_site_setting.rb | 26 +++++++++++++++++++ config/locales/client.en.yml | 7 +++++ config/locales/server.en.yml | 1 - config/site_settings.yml | 7 ++--- ...ve_muted_tags_from_latest_site_settings.rb | 13 ++++++++++ lib/topic_query.rb | 4 +-- spec/components/topic_query_spec.rb | 16 +++++++++--- 9 files changed, 70 insertions(+), 11 deletions(-) create mode 100644 app/models/remove_muted_tags_from_latest_site_setting.rb create mode 100644 db/migrate/20190531101648_merge_remove_muted_tags_from_latest_site_settings.rb diff --git a/app/assets/javascripts/discourse/controllers/preferences/categories.js.es6 b/app/assets/javascripts/discourse/controllers/preferences/categories.js.es6 index 0be1508dae6..d45e3fad89e 100644 --- a/app/assets/javascripts/discourse/controllers/preferences/categories.js.es6 +++ b/app/assets/javascripts/discourse/controllers/preferences/categories.js.es6 @@ -29,6 +29,11 @@ export default Ember.Controller.extend(PreferencesTabController, { return this.get("currentUser.id") === this.get("model.id"); }, + @computed("siteSettings.remove_muted_tags_from_latest") + hideMutedTags() { + return this.siteSettings.remove_muted_tags_from_latest !== "never"; + }, + canSave: Ember.computed.or("canSee", "currentUser.admin"), actions: { diff --git a/app/assets/javascripts/discourse/templates/preferences/categories.hbs b/app/assets/javascripts/discourse/templates/preferences/categories.hbs index f76b48e8271..aaf5572a220 100644 --- a/app/assets/javascripts/discourse/templates/preferences/categories.hbs +++ b/app/assets/javascripts/discourse/templates/preferences/categories.hbs @@ -33,7 +33,7 @@ {{category-selector categories=model.mutedCategories blacklist=selectedCategories}} -
{{i18n 'user.muted_categories_instructions'}}
+
{{i18n (if hideMutedTags 'user.muted_categories_instructions' 'user.muted_categories_instructions_dont_hide')}}
{{#if canSee}}
{{i18n 'user.muted_topics_link'}} diff --git a/app/models/remove_muted_tags_from_latest_site_setting.rb b/app/models/remove_muted_tags_from_latest_site_setting.rb new file mode 100644 index 00000000000..5c23198e246 --- /dev/null +++ b/app/models/remove_muted_tags_from_latest_site_setting.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require_dependency 'enum_site_setting' + +class RemoveMutedTagsFromLatestSiteSetting < EnumSiteSetting + + ALWAYS ||= "always" + ONLY_MUTED ||= "only_muted" + NEVER ||= "never" + + def self.valid_value?(val) + values.any? { |v| v[:value] == val } + end + + def self.values + @values ||= [ + { name: "admin.tags.remove_muted_tags_from_latest.always", value: ALWAYS }, + { name: "admin.tags.remove_muted_tags_from_latest.only_muted", value: ONLY_MUTED }, + { name: "admin.tags.remove_muted_tags_from_latest.never", value: NEVER } + ] + end + + def self.translate_names? + true + end +end diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index e8741f3327c..1fef32c25db 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -844,6 +844,7 @@ en: muted_categories: "Muted" muted_categories_instructions: "You will not be notified of anything about new topics in these categories, and they will not appear on the categories or latest pages." + muted_categories_instructions_dont_hide: "You will not be notified of anything about new topics in these categories." no_category_access: "As a moderator you have limited category access, save is disabled." delete_account: "Delete My Account" delete_account_confirm: "Are you sure you want to permanently delete your account? This action cannot be undone!" @@ -3007,6 +3008,12 @@ en: title: "Discourse Admin" moderator: "Moderator" + tags: + remove_muted_tags_from_latest: + always: "always" + only_muted: "when used alone or with other muted tags" + never: "never" + reports: title: "List of available reports" diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index fb67313716e..7efd5d3ee02 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -2019,7 +2019,6 @@ en: min_trust_level_to_tag_topics: "Minimum trust level required to tag topics" suppress_overlapping_tags_in_list: "If tags match exact words in topic titles, don't show the tag" remove_muted_tags_from_latest: "Don't show topics tagged only with muted tags in the latest topic list." - mute_other_present_tags: "Don't show topics tagged with both muted and unmuted tags in the latest topic list." force_lowercase_tags: "Force all new tags to be entirely lowercase." company_name: "Company Name" diff --git a/config/site_settings.yml b/config/site_settings.yml index 1a9e57d9a51..a8091384273 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -2059,9 +2059,10 @@ tags: default: false client: true remove_muted_tags_from_latest: - default: false - mute_other_present_tags: - default: true + client: true + type: enum + default: always + enum: RemoveMutedTagsFromLatestSiteSetting force_lowercase_tags: default: true client: true diff --git a/db/migrate/20190531101648_merge_remove_muted_tags_from_latest_site_settings.rb b/db/migrate/20190531101648_merge_remove_muted_tags_from_latest_site_settings.rb new file mode 100644 index 00000000000..0a7629a0d52 --- /dev/null +++ b/db/migrate/20190531101648_merge_remove_muted_tags_from_latest_site_settings.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +class MergeRemoveMutedTagsFromLatestSiteSettings < ActiveRecord::Migration[5.2] + def up + execute "UPDATE site_settings SET value = 'always', data_type = 7 WHERE name = 'remove_muted_tags_from_latest' AND value = 't'" + execute "UPDATE site_settings SET value = 'never', data_type = 7 WHERE name = 'remove_muted_tags_from_latest' AND value = 'f'" + execute "DELETE FROM site_settings WHERE name = 'mute_other_present_tags'" + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/lib/topic_query.rb b/lib/topic_query.rb index 34b4c260e40..33547952805 100644 --- a/lib/topic_query.rb +++ b/lib/topic_query.rb @@ -875,7 +875,7 @@ class TopicQuery list end def remove_muted_tags(list, user, opts = nil) - if user.nil? || !SiteSetting.tagging_enabled || !SiteSetting.remove_muted_tags_from_latest + if user.nil? || !SiteSetting.tagging_enabled || SiteSetting.remove_muted_tags_from_latest == 'never' return list end @@ -896,7 +896,7 @@ class TopicQuery return list end - if SiteSetting.mute_other_present_tags + if SiteSetting.remove_muted_tags_from_latest == 'always' list = list.where(" NOT EXISTS( SELECT 1 diff --git a/spec/components/topic_query_spec.rb b/spec/components/topic_query_spec.rb index 56b8b6ce128..273c64081d7 100644 --- a/spec/components/topic_query_spec.rb +++ b/spec/components/topic_query_spec.rb @@ -244,7 +244,7 @@ describe TopicQuery do context 'muted tags' do it 'is removed from new and latest lists' do SiteSetting.tagging_enabled = true - SiteSetting.remove_muted_tags_from_latest = true + SiteSetting.remove_muted_tags_from_latest = 'always' muted_tag, other_tag = Fabricate(:tag), Fabricate(:tag) @@ -263,13 +263,21 @@ describe TopicQuery do topic_ids = topic_query.list_new.topics.map(&:id) expect(topic_ids).to contain_exactly(tagged_topic.id, untagged_topic.id) - SiteSetting.mute_other_present_tags = false + SiteSetting.remove_muted_tags_from_latest = 'only_muted' topic_ids = topic_query.list_latest.topics.map(&:id) - expect(topic_ids).to contain_exactly(muted_tagged_topic.id, tagged_topic.id, untagged_topic.id) + expect(topic_ids).to contain_exactly(tagged_topic.id, muted_tagged_topic.id, untagged_topic.id) topic_ids = topic_query.list_new.topics.map(&:id) - expect(topic_ids).to contain_exactly(muted_tagged_topic.id, tagged_topic.id, untagged_topic.id) + expect(topic_ids).to contain_exactly(tagged_topic.id, muted_tagged_topic.id, untagged_topic.id) + + SiteSetting.remove_muted_tags_from_latest = 'never' + + topic_ids = topic_query.list_latest.topics.map(&:id) + expect(topic_ids).to contain_exactly(muted_topic.id, tagged_topic.id, muted_tagged_topic.id, untagged_topic.id) + + topic_ids = topic_query.list_new.topics.map(&:id) + expect(topic_ids).to contain_exactly(muted_topic.id, tagged_topic.id, muted_tagged_topic.id, untagged_topic.id) end end