mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 02:22:40 +08:00
FIX: Don't update user_profile URLs unless upload is persisted.
This commit is contained in:
@ -64,7 +64,7 @@ class UploadRecovery
|
|||||||
puts "#{background}"
|
puts "#{background}"
|
||||||
else
|
else
|
||||||
recover_user_profile_background(sha1, user_profile.user_id) do |upload|
|
recover_user_profile_background(sha1, user_profile.user_id) do |upload|
|
||||||
user_profile.update!("#{column}" => upload.url)
|
user_profile.update!("#{column}" => upload.url) if upload.persisted?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -36,6 +36,7 @@ RSpec.describe UploadRecovery do
|
|||||||
|
|
||||||
after do
|
after do
|
||||||
[upload, upload2].each do |u|
|
[upload, upload2].each do |u|
|
||||||
|
next if u
|
||||||
public_path = "#{Discourse.store.public_dir}#{u.url}"
|
public_path = "#{Discourse.store.public_dir}#{u.url}"
|
||||||
|
|
||||||
[
|
[
|
||||||
@ -140,5 +141,31 @@ RSpec.describe UploadRecovery do
|
|||||||
expect(user_profile.profile_background).to eq(upload.url)
|
expect(user_profile.profile_background).to eq(upload.url)
|
||||||
expect(user_profile.card_background).to eq(upload.url)
|
expect(user_profile.card_background).to eq(upload.url)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'for a bad upload' do
|
||||||
|
it 'should not update the urls' do
|
||||||
|
user_profile = user.user_profile
|
||||||
|
upload.destroy!
|
||||||
|
|
||||||
|
profile_background = user_profile.profile_background.sub("default", "X")
|
||||||
|
card_background = user_profile.card_background.sub("default", "X")
|
||||||
|
|
||||||
|
user_profile.update_columns(
|
||||||
|
profile_background: profile_background,
|
||||||
|
card_background: card_background
|
||||||
|
)
|
||||||
|
|
||||||
|
SiteSetting.authorized_extensions = ''
|
||||||
|
|
||||||
|
expect do
|
||||||
|
upload_recovery.recover_user_profile_backgrounds
|
||||||
|
end.to_not change { Upload.count }
|
||||||
|
|
||||||
|
user_profile.reload
|
||||||
|
|
||||||
|
expect(user_profile.profile_background).to eq(profile_background)
|
||||||
|
expect(user_profile.card_background).to eq(card_background)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user