FIX: Outgoing emails were not disabled after restoring backup

FIX: Outgoing emails were not disabled after restoring backup

diff --git a/app/controllers/admin/backups_controller.rb b/app/controllers/admin/backups_controller.rb
index 9071b06..3fe1141 100644
--- a/app/controllers/admin/backups_controller.rb
+++ b/app/controllers/admin/backups_controller.rb
@@ -114,7 +114,6 @@ class Admin::BackupsController < Admin::AdminController
       client_id: params.fetch(:client_id),
       publish_to_message_bus: true,
     }
-    SiteSetting.set_and_log(:disable_emails, 'yes', current_user)
     BackupRestore.restore!(current_user.id, opts)
   rescue BackupRestore::OperationRunningError
     render_error("backup.operation_already_running")
diff --git a/lib/backup_restore/restorer.rb b/lib/backup_restore/restorer.rb
index 5dcc377..5d39e5e 100644
--- a/lib/backup_restore/restorer.rb
+++ b/lib/backup_restore/restorer.rb
@@ -401,6 +401,10 @@ module BackupRestore
     def reload_site_settings
       log "Reloading site settings..."
       SiteSetting.refresh!
+
+      log "Disabling outgoing emails for non-stuff users..."
+      user = User.find_by_email(@user_info[:email]) || Discourse.system_user
+      SiteSetting.set_and_log(:disable_emails, 'non-staff', user)
     end
 
     def clear_emoji_cache
diff --git a/spec/requests/admin/backups_controller_spec.rb b/spec/requests/admin/backups_controller_spec.rb
index 6a6b60c..96a7b63 100644
--- a/spec/requests/admin/backups_controller_spec.rb
+++ b/spec/requests/admin/backups_controller_spec.rb
@@ -162,12 +162,10 @@ RSpec.describe Admin::BackupsController do
 
   describe '#restore' do
     it "starts a restore" do
-      expect(SiteSetting.disable_emails).to eq("no")
       BackupRestore.expects(:restore!).with(admin.id, filename: backup_filename, publish_to_message_bus: true, client_id: "foo")
 
       post "/admin/backups/#{backup_filename}/restore.json", params: { client_id: "foo" }
 
-      expect(SiteSetting.disable_emails).to eq("yes")
       expect(response.status).to eq(200)
     end
   end

GitHub sha: dc961fec

1 Like

This commit has been mentioned on Discourse Meta. There might be relevant details there:

Typo?

Has already been fixed in 42df20e4f09aa947c0bc76daa3fc4af6dc59f9d9

1 Like

This commit has been mentioned on Discourse Meta. There might be relevant details there:

This commit has been mentioned on Discourse Meta. There might be relevant details there: