A platform for community discussion. Free, open, simple.
FIX: Keep profile backgrounds through unrelated user updates (#42732)
Régis Hanol65e9d2096c45
diff --git a/app/services/user_updater.rb b/app/services/user_updater.rbindex 2e494ce7a9c..3fa283b1642 100644--- a/app/services/user_updater.rb+++ b/app/services/user_updater.rb@@ -106,18 +106,22 @@ class UserUpdateruser_profile.website = format_url(attributes.fetch(:website) { user_profile.website })end- if attributes[:profile_background_upload_url] == "" ||- !guardian.can_upload_profile_header?(user)- user_profile.profile_background_upload_id = nil- elsif upload = Upload.get_from_url(attributes[:profile_background_upload_url])- user_profile.profile_background_upload_id = upload.id+ if attributes.key?(:profile_background_upload_url)+ if attributes[:profile_background_upload_url] == "" ||+ !guardian.can_upload_profile_header?(user)+ user_profile.profile_background_upload_id = nil+ elsif upload = Upload.get_from_url(attributes[:profile_background_upload_url])+ user_profile.profile_background_upload_id = upload.id+ endend- if attributes[:card_background_upload_url] == "" ||- !guardian.can_upload_user_card_background?(user)- user_profile.card_background_upload_id = nil- elsif upload = Upload.get_from_url(attributes[:card_background_upload_url])- user_profile.card_background_upload_id = upload.id+ if attributes.key?(:card_background_upload_url)+ if attributes[:card_background_upload_url] == "" ||+ !guardian.can_upload_user_card_background?(user)+ user_profile.card_background_upload_id = nil+ elsif upload = Upload.get_from_url(attributes[:card_background_upload_url])+ user_profile.card_background_upload_id = upload.id+ endendif attributes[:user_notification_schedule]diff --git a/spec/services/user_updater_spec.rb b/spec/services/user_updater_spec.rbindex ce6d5c21194..436c0a00643 100644--- a/spec/services/user_updater_spec.rb+++ b/spec/services/user_updater_spec.rb@@ -278,6 +278,39 @@ RSpec.describe UserUpdater doexpect(user.card_background_upload).to eq(nil)end+ context "with profile and card backgrounds" do+ fab!(:profile_background, :upload)+ fab!(:card_background, :upload)+ fab!(:target, :user)+ fab!(:other, :user)++ before do+ target.user_profile.update!(+ profile_background_upload_id: profile_background.id,+ card_background_upload_id: card_background.id,+ )+ end++ it "keeps them when the update does not mention them" do+ UserUpdater.new(other, target).update(bio_raw: "edited by someone else")++ target.user_profile.reload+ expect(target.user_profile.profile_background_upload_id).to eq(profile_background.id)+ expect(target.user_profile.card_background_upload_id).to eq(card_background.id)+ end++ it "still clears them when the update asks and the actor may not upload" do+ UserUpdater.new(other, target).update(+ profile_background_upload_url: profile_background.url,+ card_background_upload_url: card_background.url,+ )++ target.user_profile.reload+ expect(target.user_profile.profile_background_upload_id).to be_nil+ expect(target.user_profile.card_background_upload_id).to be_nil+ end+ end+it "disables email_digests when enabling mailing_list_mode" doupdater = UserUpdater.new(acting_user, user)SiteSetting.disable_mailing_list_mode = false