2017-08-06 21:43:09 -04:00
|
|
|
module SiteSettings; end
|
2015-08-20 21:27:19 -04:00
|
|
|
|
2017-08-06 21:43:09 -04:00
|
|
|
module SiteSettings::Validations
|
2018-10-10 23:08:12 -04:00
|
|
|
def validate_error(key)
|
|
|
|
raise Discourse::InvalidParameters.new(I18n.t("errors.site_settings.#{key}"))
|
2015-08-20 21:27:19 -04:00
|
|
|
end
|
|
|
|
|
2015-08-26 16:40:16 -04:00
|
|
|
def validate_default_categories(new_val, default_categories_selected)
|
|
|
|
validate_error :default_categories_already_selected if (new_val.split("|").to_set & default_categories_selected).size > 0
|
2015-08-21 14:39:21 -04:00
|
|
|
end
|
|
|
|
|
2015-08-26 16:40:16 -04:00
|
|
|
def validate_default_categories_watching(new_val)
|
|
|
|
default_categories_selected = [
|
|
|
|
SiteSetting.default_categories_tracking.split("|"),
|
|
|
|
SiteSetting.default_categories_muted.split("|"),
|
2016-11-09 13:45:14 -05:00
|
|
|
SiteSetting.default_categories_watching_first_post.split("|")
|
2015-08-26 16:40:16 -04:00
|
|
|
].flatten.to_set
|
|
|
|
|
|
|
|
validate_default_categories(new_val, default_categories_selected)
|
|
|
|
end
|
|
|
|
|
|
|
|
def validate_default_categories_tracking(new_val)
|
|
|
|
default_categories_selected = [
|
|
|
|
SiteSetting.default_categories_watching.split("|"),
|
|
|
|
SiteSetting.default_categories_muted.split("|"),
|
2016-11-09 13:45:14 -05:00
|
|
|
SiteSetting.default_categories_watching_first_post.split("|")
|
2015-08-26 16:40:16 -04:00
|
|
|
].flatten.to_set
|
|
|
|
|
|
|
|
validate_default_categories(new_val, default_categories_selected)
|
|
|
|
end
|
|
|
|
|
|
|
|
def validate_default_categories_muted(new_val)
|
|
|
|
default_categories_selected = [
|
|
|
|
SiteSetting.default_categories_watching.split("|"),
|
|
|
|
SiteSetting.default_categories_tracking.split("|"),
|
2016-11-09 13:45:14 -05:00
|
|
|
SiteSetting.default_categories_watching_first_post.split("|")
|
2015-08-26 16:40:16 -04:00
|
|
|
].flatten.to_set
|
|
|
|
|
|
|
|
validate_default_categories(new_val, default_categories_selected)
|
|
|
|
end
|
2015-08-21 14:39:21 -04:00
|
|
|
|
2016-11-09 13:37:54 -05:00
|
|
|
def validate_default_categories_watching_first_post(new_val)
|
|
|
|
default_categories_selected = [
|
|
|
|
SiteSetting.default_categories_watching.split("|"),
|
|
|
|
SiteSetting.default_categories_tracking.split("|"),
|
2016-11-09 13:45:14 -05:00
|
|
|
SiteSetting.default_categories_muted.split("|")
|
2016-11-09 13:37:54 -05:00
|
|
|
].flatten.to_set
|
|
|
|
|
|
|
|
validate_default_categories(new_val, default_categories_selected)
|
|
|
|
end
|
|
|
|
|
2015-09-16 09:55:26 -04:00
|
|
|
def validate_enable_s3_uploads(new_val)
|
|
|
|
validate_error :s3_upload_bucket_is_required if new_val == "t" && SiteSetting.s3_upload_bucket.blank?
|
|
|
|
end
|
|
|
|
|
2015-08-20 21:27:19 -04:00
|
|
|
end
|