diff --git a/app/models/site_setting.rb b/app/models/site_setting.rb index fbe1b782d55..70b62602eec 100644 --- a/app/models/site_setting.rb +++ b/app/models/site_setting.rb @@ -94,6 +94,7 @@ class SiteSetting < ActiveRecord::Base SiteSetting.default_categories_watching.split("|"), SiteSetting.default_categories_tracking.split("|"), SiteSetting.default_categories_muted.split("|"), + SiteSetting.default_categories_watching_first_post.split("|") ].flatten.to_set end diff --git a/app/models/user.rb b/app/models/user.rb index 3de3020d17e..2d623817cc6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -988,7 +988,7 @@ class User < ActiveRecord::Base values = [] - %w{watching tracking muted}.each do |s| + %w{watching watching_first_post tracking muted}.each do |s| category_ids = SiteSetting.send("default_categories_#{s}").split("|") category_ids.each do |category_id| values << "(#{self.id}, #{category_id}, #{CategoryUser.notification_levels[s.to_sym]})" diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 04b2e4d94e6..fb314c4dd00 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -1393,6 +1393,7 @@ en: default_categories_watching: "List of categories that are watched by default." default_categories_tracking: "List of categories that are tracked by default." default_categories_muted: "List of categories that are muted by default." + default_categories_watching_first_post: "List of first post in each new topic in these categories that are watched by default." max_user_api_reqs_per_day: "Maximum number of user API requests per key per day" max_user_api_reqs_per_minute: "Maximum number of user API requests per key per minute" diff --git a/config/site_settings.yml b/config/site_settings.yml index 92776b8eeae..57661444a80 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -1293,6 +1293,9 @@ user_preferences: default_categories_muted: type: category_list default: '' + default_categories_watching_first_post: + type: category_list + default: '' user_api: max_user_api_reqs_per_day: diff --git a/lib/site_setting_validations.rb b/lib/site_setting_validations.rb index e69bfc2f95d..0380c457a0a 100644 --- a/lib/site_setting_validations.rb +++ b/lib/site_setting_validations.rb @@ -21,6 +21,7 @@ module SiteSettingValidations def validate_default_categories_watching(new_val) default_categories_selected = [ + SiteSetting.default_categories_watching_first_post.split("|"), SiteSetting.default_categories_tracking.split("|"), SiteSetting.default_categories_muted.split("|"), ].flatten.to_set @@ -31,6 +32,7 @@ module SiteSettingValidations def validate_default_categories_tracking(new_val) default_categories_selected = [ SiteSetting.default_categories_watching.split("|"), + SiteSetting.default_categories_watching_first_post.split("|"), SiteSetting.default_categories_muted.split("|"), ].flatten.to_set @@ -40,12 +42,23 @@ module SiteSettingValidations def validate_default_categories_muted(new_val) default_categories_selected = [ SiteSetting.default_categories_watching.split("|"), + SiteSetting.default_categories_watching_first_post.split("|"), SiteSetting.default_categories_tracking.split("|"), ].flatten.to_set validate_default_categories(new_val, default_categories_selected) end + def validate_default_categories_watching_first_post(new_val) + default_categories_selected = [ + SiteSetting.default_categories_watching.split("|"), + SiteSetting.default_categories_tracking.split("|"), + SiteSetting.default_categories_muted.split("|"), + ].flatten.to_set + + validate_default_categories(new_val, default_categories_selected) + end + def validate_enable_s3_uploads(new_val) validate_error :s3_upload_bucket_is_required if new_val == "t" && SiteSetting.s3_upload_bucket.blank? end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index cddc4b50a89..3a32c5e4854 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -1257,6 +1257,7 @@ describe User do SiteSetting.default_categories_watching = "1" SiteSetting.default_categories_tracking = "2" SiteSetting.default_categories_muted = "3" + SiteSetting.default_categories_watching_first_post = "4" end it "has overriden preferences" do @@ -1279,6 +1280,7 @@ describe User do expect(CategoryUser.lookup(user, :watching).pluck(:category_id)).to eq([1]) expect(CategoryUser.lookup(user, :tracking).pluck(:category_id)).to eq([2]) expect(CategoryUser.lookup(user, :muted).pluck(:category_id)).to eq([3]) + expect(CategoryUser.lookup(user, :watching_first_post).pluck(:category_id)).to eq([4]) end it "does not set category preferences for staged users" do @@ -1286,6 +1288,7 @@ describe User do expect(CategoryUser.lookup(user, :watching).pluck(:category_id)).to eq([]) expect(CategoryUser.lookup(user, :tracking).pluck(:category_id)).to eq([]) expect(CategoryUser.lookup(user, :muted).pluck(:category_id)).to eq([]) + expect(CategoryUser.lookup(user, :watching_first_post).pluck(:category_id)).to eq([]) end end