A platform for community discussion. Free, open, simple.
UX: Merge settings related to muted tags. (#7656)
Dan Ungureanuc1e7a1b29222
diff --git a/app/assets/javascripts/discourse/controllers/preferences/categories.js.es6 b/app/assets/javascripts/discourse/controllers/preferences/categories.js.es6index 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.hbsindex 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 @@<label>{{d-icon "d-muted"}} {{i18n 'user.muted_categories'}}</label>{{category-selector categories=model.mutedCategories blacklist=selectedCategories}}</div>- <div class="instructions">{{i18n 'user.muted_categories_instructions'}}</div>+ <div class="instructions">{{i18n (if hideMutedTags 'user.muted_categories_instructions' 'user.muted_categories_instructions_dont_hide')}}</div>{{#if canSee}}<div class="controls"><a href="{{unbound model.mutedTopicsPath}}">{{i18n 'user.muted_topics_link'}}</a>diff --git a/app/models/remove_muted_tags_from_latest_site_setting.rb b/app/models/remove_muted_tags_from_latest_site_setting.rbnew file mode 100644index 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+enddiff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex 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.ymlindex 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.ymlindex 1a9e57d9a51..a8091384273 100644--- a/config/site_settings.yml+++ b/config/site_settings.yml@@ -2059,9 +2059,10 @@ tags:default: falseclient: trueremove_muted_tags_from_latest:- default: false- mute_other_present_tags:- default: true+ client: true+ type: enum+ default: always+ enum: RemoveMutedTagsFromLatestSiteSettingforce_lowercase_tags:default: trueclient: truediff --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.rbnew file mode 100644index 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+enddiff --git a/lib/topic_query.rb b/lib/topic_query.rbindex 34b4c260e40..33547952805 100644--- a/lib/topic_query.rb+++ b/lib/topic_query.rb@@ -875,7 +875,7 @@ class TopicQuerylistenddef 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 listend@@ -896,7 +896,7 @@ class TopicQueryreturn listend- if SiteSetting.mute_other_present_tags+ if SiteSetting.remove_muted_tags_from_latest == 'always'list = list.where("NOT EXISTS(SELECT 1diff --git a/spec/components/topic_query_spec.rb b/spec/components/topic_query_spec.rbindex 56b8b6ce128..273c64081d7 100644--- a/spec/components/topic_query_spec.rb+++ b/spec/components/topic_query_spec.rb@@ -244,7 +244,7 @@ describe TopicQuery docontext 'muted tags' doit 'is removed from new and latest lists' doSiteSetting.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 dotopic_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)endend