Merge pull request #8010 from cmrd-senya/fix-archive-edge-cases
Fix archive edge cases closes #8017 closes #8257
This commit is contained in:
commit
2081f39a72
6 changed files with 63 additions and 2 deletions
|
|
@ -32,7 +32,7 @@ Although the chat was never enabled per default and was marked as experimental,
|
||||||
## Features
|
## Features
|
||||||
* Add client-side cropping of profile image uploads [#7581](https://github.com/diaspora/diaspora/pull/7581)
|
* Add client-side cropping of profile image uploads [#7581](https://github.com/diaspora/diaspora/pull/7581)
|
||||||
* Add client-site rescaling of post images if they exceed the maximum possible size [#7734](https://github.com/diaspora/diaspora/pull/7734)
|
* Add client-site rescaling of post images if they exceed the maximum possible size [#7734](https://github.com/diaspora/diaspora/pull/7734)
|
||||||
* Add backend for archive import [#7660](https://github.com/diaspora/diaspora/pull/7660) [#8254](https://github.com/diaspora/diaspora/pull/8254) [#8264](https://github.com/diaspora/diaspora/pull/8264)
|
* Add backend for archive import [#7660](https://github.com/diaspora/diaspora/pull/7660) [#8254](https://github.com/diaspora/diaspora/pull/8254) [#8264](https://github.com/diaspora/diaspora/pull/8264) [#8010](https://github.com/diaspora/diaspora/pull/8010)
|
||||||
* For pods running PostgreSQL, make sure that no upper-case/mixed-case tags exist, and create a `lower(name)` index on tags to speed up ActsAsTaggableOn [#8206](https://github.com/diaspora/diaspora/pull/8206)
|
* For pods running PostgreSQL, make sure that no upper-case/mixed-case tags exist, and create a `lower(name)` index on tags to speed up ActsAsTaggableOn [#8206](https://github.com/diaspora/diaspora/pull/8206)
|
||||||
* Allow podmins/moderators to see all local public posts to improve moderation [#8232](https://github.com/diaspora/diaspora/pull/8232)
|
* Allow podmins/moderators to see all local public posts to improve moderation [#8232](https://github.com/diaspora/diaspora/pull/8232)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,11 @@ class ArchiveImporter
|
||||||
rescue DiasporaFederation::Entities::Signable::SignatureVerificationFailed,
|
rescue DiasporaFederation::Entities::Signable::SignatureVerificationFailed,
|
||||||
DiasporaFederation::Discovery::InvalidDocument,
|
DiasporaFederation::Discovery::InvalidDocument,
|
||||||
DiasporaFederation::Discovery::DiscoveryError,
|
DiasporaFederation::Discovery::DiscoveryError,
|
||||||
|
DiasporaFederation::Federation::Fetcher::NotFetchable,
|
||||||
|
OwnRelayableImporter::NoParentError,
|
||||||
ActiveRecord::RecordInvalid => e
|
ActiveRecord::RecordInvalid => e
|
||||||
logger.warn "#{self}: #{e}"
|
logger.warn "#{self}: #{e}"
|
||||||
|
self.persisted_object = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :json
|
attr_reader :json
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,9 @@ class ArchiveImporter
|
||||||
attr_reader :old_author_id
|
attr_reader :old_author_id
|
||||||
|
|
||||||
def persisted_object
|
def persisted_object
|
||||||
@persisted_object ||= (instance if real_author == old_author_id)
|
return @persisted_object if defined?(@persisted_object)
|
||||||
|
|
||||||
|
@persisted_object = (instance if real_author == old_author_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def real_author
|
def real_author
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
class ArchiveImporter
|
class ArchiveImporter
|
||||||
class OwnRelayableImporter < OwnEntityImporter
|
class OwnRelayableImporter < OwnEntityImporter
|
||||||
|
class NoParentError < RuntimeError; end
|
||||||
|
|
||||||
def entity
|
def entity
|
||||||
fetch_parent(symbolized_entity_data)
|
fetch_parent(symbolized_entity_data)
|
||||||
entity_class.new(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)
|
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))
|
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)
|
data[:parent] = Diaspora::Federation::Entities.related_entity(entity)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -28,4 +28,27 @@ describe ArchiveImporter::OwnRelayableImporter do
|
||||||
).to_json
|
).to_json
|
||||||
}
|
}
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
|
|
@ -113,5 +113,34 @@ describe ArchiveImporter::PostImporter do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with reshare" do
|
||||||
|
let(:guid) { UUID.generate(:compact) }
|
||||||
|
let(:entity_json) { JSON.parse(<<~JSON) }
|
||||||
|
{
|
||||||
|
"entity_data" : {
|
||||||
|
"created_at" : "2015-10-19T13:58:16Z",
|
||||||
|
"guid" : "#{guid}",
|
||||||
|
"author" : "#{new_user.diaspora_handle}",
|
||||||
|
"root_author": "root_author@remote-pod.com",
|
||||||
|
"root_guid": "#{UUID.generate(:compact)}"
|
||||||
|
},
|
||||||
|
"entity_type": "reshare"
|
||||||
|
}
|
||||||
|
JSON
|
||||||
|
|
||||||
|
context "with fetch problems" do
|
||||||
|
it "handles unfetchable root post" do
|
||||||
|
allow(DiasporaFederation::Federation::Fetcher).to receive(:fetch_public)
|
||||||
|
.and_raise(DiasporaFederation::Federation::Fetcher::NotFetchable)
|
||||||
|
|
||||||
|
expect {
|
||||||
|
instance.import
|
||||||
|
}.not_to raise_error
|
||||||
|
|
||||||
|
expect(Reshare.find_by(guid: guid)).to be_nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue