FIX: User profile not loading with an empty export (#31290)

If a user has an export that doesn't have a file it can cause their
profile page to not load.
This commit is contained in:
Blake Erickson 2025-02-11 16:18:06 -07:00 committed by GitHub
parent 262575f4e2
commit afda973070
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 0 deletions

View File

@ -3,6 +3,11 @@
class UserExportSerializer < ApplicationSerializer
attributes :id, :filename, :uri, :filesize, :extension, :retain_hours, :human_filesize
def serializable_hash(adapter_options = nil, options = {})
return {} unless object.upload
super()
end
def filename
object.upload.original_filename
end

View File

@ -28,4 +28,24 @@ RSpec.describe UserExportSerializer do
expect(json_data["retain_hours"]).to eql user_export.retain_hours
expect(json_data["human_filesize"]).to eql user_export.upload.human_filesize
end
context "when upload is nil" do
fab!(:user_export) do
user = Fabricate(:user)
topic = Fabricate(:topic, created_at: 1.day.ago)
Fabricate(:post, topic: topic)
UserExport.create!(
file_name: "test",
user: user,
upload_id: nil,
topic_id: topic.id,
created_at: 1.day.ago,
)
end
it "returns an empty hash" do
json_data = JSON.parse(serializer.to_json)
expect(json_data).to eq({})
end
end
end