Merge pull request #6894 from SuperTux88/fetch-missing-persons

fetch unknown persons to generate url
This commit is contained in:
Dennis Schubert 2016-06-27 15:01:18 +02:00
commit fddec62828
No known key found for this signature in database
GPG key ID: 5A0304BEA7966D7E
3 changed files with 27 additions and 7 deletions

View file

@ -215,6 +215,12 @@ class Person < ActiveRecord::Base
url_to "/receive/users/#{guid}" url_to "/receive/users/#{guid}"
end end
# @param path [String]
# @return [String]
def url_to(path)
local? ? AppConfig.url_to(path) : pod.url_to(path)
end
def public_key_hash def public_key_hash
Base64.encode64(OpenSSL::Digest::SHA256.new(serialized_public_key).to_s) Base64.encode64(OpenSSL::Digest::SHA256.new(serialized_public_key).to_s)
end end
@ -286,12 +292,6 @@ class Person < ActiveRecord::Base
private private
# @param path [String]
# @return [String]
def url_to(path)
local? ? AppConfig.url_to(path) : pod.url_to(path)
end
def fix_profile def fix_profile
logger.info "fix profile for account: #{diaspora_handle}" logger.info "fix profile for account: #{diaspora_handle}"
DiasporaFederation::Discovery::Discovery.new(diaspora_handle).fetch_and_save DiasporaFederation::Discovery::Discovery.new(diaspora_handle).fetch_and_save

View file

@ -111,7 +111,7 @@ DiasporaFederation.configure do |config|
end end
on :fetch_person_url_to do |diaspora_id, path| on :fetch_person_url_to do |diaspora_id, path|
Pod.joins(:people).find_by(people: {diaspora_handle: diaspora_id}).url_to(path) Person.find_or_fetch_by_identifier(diaspora_id).url_to(path)
end end
on :update_pod do |url, status| on :update_pod do |url, status|

View file

@ -428,6 +428,26 @@ describe "diaspora federation callbacks" do
DiasporaFederation.callbacks.trigger(:fetch_person_url_to, person.diaspora_handle, "/path/on/pod") DiasporaFederation.callbacks.trigger(:fetch_person_url_to, person.diaspora_handle, "/path/on/pod")
).to eq("https://#{pod.host}/path/on/pod") ).to eq("https://#{pod.host}/path/on/pod")
end end
it "fetches an unknown user" do
pod = FactoryGirl.build(:pod)
person = FactoryGirl.build(:person, pod: pod)
expect(Person).to receive(:find_or_fetch_by_identifier).with(person.diaspora_handle).and_return(person)
expect(
DiasporaFederation.callbacks.trigger(:fetch_person_url_to, person.diaspora_handle, "/path/on/pod")
).to eq("https://#{pod.host}/path/on/pod")
end
it "forwards the DiscoveryError" do
diaspora_id = FactoryGirl.generate(:diaspora_id)
expect(Person).to receive(:find_or_fetch_by_identifier).with(diaspora_id)
.and_raise(DiasporaFederation::Discovery::DiscoveryError)
expect {
DiasporaFederation.callbacks.trigger(:fetch_person_url_to, diaspora_id, "/path/on/pod")
}.to raise_error DiasporaFederation::Discovery::DiscoveryError
end
end end
describe ":update_pod" do describe ":update_pod" do