Fix relayable import when parent is not fetchable
This commit is contained in:
parent
1ec0314752
commit
9723bd37a7
3 changed files with 28 additions and 0 deletions
|
|
@ -16,6 +16,7 @@ class ArchiveImporter
|
|||
DiasporaFederation::Discovery::InvalidDocument,
|
||||
DiasporaFederation::Discovery::DiscoveryError,
|
||||
DiasporaFederation::Federation::Fetcher::NotFetchable,
|
||||
OwnRelayableImporter::NoParentError,
|
||||
ActiveRecord::RecordInvalid => e
|
||||
logger.warn "#{self}: #{e}"
|
||||
self.persisted_object = nil
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
class ArchiveImporter
|
||||
class OwnRelayableImporter < OwnEntityImporter
|
||||
class NoParentError < RuntimeError; end
|
||||
|
||||
def entity
|
||||
fetch_parent(symbolized_entity_data)
|
||||
entity_class.new(symbolized_entity_data)
|
||||
|
|
@ -19,6 +21,8 @@ class ArchiveImporter
|
|||
break entity_class::PARENT_TYPE if entity_class.const_defined?(:PARENT_TYPE)
|
||||
}
|
||||
entity = Diaspora::Federation::Mappings.model_class_for(type).find_by(guid: data.fetch(:parent_guid))
|
||||
raise NoParentError if entity.nil?
|
||||
|
||||
data[:parent] = Diaspora::Federation::Entities.related_entity(entity)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -28,4 +28,27 @@ describe ArchiveImporter::OwnRelayableImporter do
|
|||
).to_json
|
||||
}
|
||||
end
|
||||
|
||||
context "with comment with unknown parent" do
|
||||
let(:new_user) { FactoryBot.create(:user) }
|
||||
let(:instance) { described_class.new(entity_json, new_user) }
|
||||
let(:entity_json) { JSON.parse(<<~JSON) }
|
||||
{
|
||||
"entity_data" : {
|
||||
"created_at" : "2015-10-19T13:58:16Z",
|
||||
"guid" : "#{UUID.generate(:compact)}",
|
||||
"text" : "test post",
|
||||
"author" : "author@example.com",
|
||||
"parent_guid": "#{UUID.generate(:compact)}"
|
||||
},
|
||||
"entity_type": "comment"
|
||||
}
|
||||
JSON
|
||||
|
||||
it "doesn't raise error" do
|
||||
expect {
|
||||
instance.import
|
||||
}.not_to raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue