From a5f61729e0593804051047df86f1a8e1d271794a Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Fri, 6 Mar 2020 08:49:28 -0500 Subject: [PATCH] Revert "Revert "FIX: Don't allow people to clear the upload bucket while it's enabled"" This reverts commit d4fc76b335d012275b06b7ce80d0c1b98f9db33d. --- lib/site_settings/validations.rb | 2 ++ spec/lib/site_settings/validations_spec.rb | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/site_settings/validations.rb b/lib/site_settings/validations.rb index 56987b0dfed..0bf13f7606e 100644 --- a/lib/site_settings/validations.rb +++ b/lib/site_settings/validations.rb @@ -143,6 +143,8 @@ module SiteSettings::Validations def validate_s3_upload_bucket(new_val) validate_bucket_setting("s3_upload_bucket", new_val, SiteSetting.s3_backup_bucket) + + validate_error(:s3_upload_bucket_is_required, setting_name: 's3_upload_bucket') if new_val.blank? && SiteSetting.enable_s3_uploads? end def validate_s3_backup_bucket(new_val) diff --git a/spec/lib/site_settings/validations_spec.rb b/spec/lib/site_settings/validations_spec.rb index 7f346d4d5cb..69ab73920b2 100644 --- a/spec/lib/site_settings/validations_spec.rb +++ b/spec/lib/site_settings/validations_spec.rb @@ -103,6 +103,15 @@ describe SiteSettings::Validations do SiteSetting.s3_backup_bucket = "my-awesome-bucket/foo" expect { validate("my-awesome-bucket/foo/uploads") }.to raise_error(Discourse::InvalidParameters, error_message) end + + it "cannot be made blank unless the setting is false" do + SiteSetting.s3_backup_bucket = "really-real-cool-bucket" + SiteSetting.enable_s3_uploads = true + + expect { validate("") }.to raise_error(Discourse::InvalidParameters) + SiteSetting.enable_s3_uploads = false + validate("") + end end end