Commit fddec628 authored by Dennis Schubert's avatar Dennis Schubert

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

fetch unknown persons to generate url
parents 82c601c9 3bfc4003
......@@ -215,6 +215,12 @@ class Person < ActiveRecord::Base
url_to "/receive/users/#{guid}"
end
# @param path [String]
# @return [String]
def url_to(path)
local? ? AppConfig.url_to(path) : pod.url_to(path)
end
def public_key_hash
Base64.encode64(OpenSSL::Digest::SHA256.new(serialized_public_key).to_s)
end
......@@ -286,12 +292,6 @@ class Person < ActiveRecord::Base
private
# @param path [String]
# @return [String]
def url_to(path)
local? ? AppConfig.url_to(path) : pod.url_to(path)
end
def fix_profile
logger.info "fix profile for account: #{diaspora_handle}"
DiasporaFederation::Discovery::Discovery.new(diaspora_handle).fetch_and_save
......
......@@ -111,7 +111,7 @@ DiasporaFederation.configure do |config|
end
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
on :update_pod do |url, status|
......
......@@ -428,6 +428,26 @@ describe "diaspora federation callbacks" do
DiasporaFederation.callbacks.trigger(:fetch_person_url_to, person.diaspora_handle, "/path/on/pod")
).to eq("https://#{pod.host}/path/on/pod")
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
describe ":update_pod" do
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment