mirror of
https://github.com/discourse/discourse.git
synced 2025-02-24 10:58:39 +08:00
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:
parent
262575f4e2
commit
afda973070
@ -3,6 +3,11 @@
|
|||||||
class UserExportSerializer < ApplicationSerializer
|
class UserExportSerializer < ApplicationSerializer
|
||||||
attributes :id, :filename, :uri, :filesize, :extension, :retain_hours, :human_filesize
|
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
|
def filename
|
||||||
object.upload.original_filename
|
object.upload.original_filename
|
||||||
end
|
end
|
||||||
|
@ -28,4 +28,24 @@ RSpec.describe UserExportSerializer do
|
|||||||
expect(json_data["retain_hours"]).to eql user_export.retain_hours
|
expect(json_data["retain_hours"]).to eql user_export.retain_hours
|
||||||
expect(json_data["human_filesize"]).to eql user_export.upload.human_filesize
|
expect(json_data["human_filesize"]).to eql user_export.upload.human_filesize
|
||||||
end
|
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
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user