FEATURE: watch first post default site setting

This commit is contained in:
Arpit Jalan 2016-11-10 00:07:54 +05:30
parent b0c6cd8afd
commit 9e69798285
6 changed files with 22 additions and 1 deletions

View File

@ -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

View File

@ -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]})"

View File

@ -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"

View File

@ -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:

View File

@ -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

View File

@ -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