Loading Changelog.md +1 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ ## Features * Add a manifest.json file as a first step to make diaspora* a Progressive Web App [#7998](https://github.com/diaspora/diaspora/pull/7998) * Allow `web+diaspora://` links to link to a profile with only the diaspora ID [#8000](https://github.com/diaspora/diaspora/pull/8000) # 0.7.10.0 Loading app/services/diaspora_link_service.rb +10 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,8 @@ class DiasporaLinkService def find_or_fetch_entity if type && guid entity_finder.find || fetch_entity elsif author find_or_fetch_person end end Loading @@ -30,6 +32,12 @@ class DiasporaLinkService @entity_finder ||= Diaspora::EntityFinder.new(type, guid) end def find_or_fetch_person Person.find_or_fetch_by_identifier(author) rescue DiasporaFederation::Discovery::DiscoveryError nil end def normalize link.gsub!(%r{^web\+diaspora://}, "diaspora://") || link.gsub!(%r{^//}, "diaspora://") || Loading @@ -42,6 +50,8 @@ class DiasporaLinkService match = DiasporaFederation::Federation::DiasporaUrlParser::DIASPORA_URL_REGEX.match(link) if match @author, @type, @guid = match.captures else @author = %r{^diaspora://(#{Validation::Rule::DiasporaId::DIASPORA_ID_REGEX})$}u.match(link)&.captures&.first end end end spec/services/diaspora_link_service_spec.rb +16 −0 Original line number Diff line number Diff line Loading @@ -52,5 +52,21 @@ describe DiasporaLinkService do expect(service.find_or_fetch_entity).to be_nil end end context "with only a diaspora ID" do let(:person) { FactoryGirl.create(:person) } let(:link) { "diaspora://#{person.diaspora_handle}" } it "returns the person" do expect(service.find_or_fetch_entity).to eq(person) end it "returns nil when person is non fetchable" do expect(Person).to receive(:find_or_fetch_by_identifier) .with(person.diaspora_handle).and_raise(DiasporaFederation::Discovery::DiscoveryError) expect(service.find_or_fetch_entity).to be_nil end end end end Loading
Changelog.md +1 −0 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ ## Features * Add a manifest.json file as a first step to make diaspora* a Progressive Web App [#7998](https://github.com/diaspora/diaspora/pull/7998) * Allow `web+diaspora://` links to link to a profile with only the diaspora ID [#8000](https://github.com/diaspora/diaspora/pull/8000) # 0.7.10.0 Loading
app/services/diaspora_link_service.rb +10 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,8 @@ class DiasporaLinkService def find_or_fetch_entity if type && guid entity_finder.find || fetch_entity elsif author find_or_fetch_person end end Loading @@ -30,6 +32,12 @@ class DiasporaLinkService @entity_finder ||= Diaspora::EntityFinder.new(type, guid) end def find_or_fetch_person Person.find_or_fetch_by_identifier(author) rescue DiasporaFederation::Discovery::DiscoveryError nil end def normalize link.gsub!(%r{^web\+diaspora://}, "diaspora://") || link.gsub!(%r{^//}, "diaspora://") || Loading @@ -42,6 +50,8 @@ class DiasporaLinkService match = DiasporaFederation::Federation::DiasporaUrlParser::DIASPORA_URL_REGEX.match(link) if match @author, @type, @guid = match.captures else @author = %r{^diaspora://(#{Validation::Rule::DiasporaId::DIASPORA_ID_REGEX})$}u.match(link)&.captures&.first end end end
spec/services/diaspora_link_service_spec.rb +16 −0 Original line number Diff line number Diff line Loading @@ -52,5 +52,21 @@ describe DiasporaLinkService do expect(service.find_or_fetch_entity).to be_nil end end context "with only a diaspora ID" do let(:person) { FactoryGirl.create(:person) } let(:link) { "diaspora://#{person.diaspora_handle}" } it "returns the person" do expect(service.find_or_fetch_entity).to eq(person) end it "returns nil when person is non fetchable" do expect(Person).to receive(:find_or_fetch_by_identifier) .with(person.diaspora_handle).and_raise(DiasporaFederation::Discovery::DiscoveryError) expect(service.find_or_fetch_entity).to be_nil end end end end