Allow links with only the diaspora ID to link to a profile
closes #8000
This commit is contained in:
parent
91aae4d755
commit
17af65e22c
3 changed files with 27 additions and 0 deletions
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
## Features
|
## 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)
|
* 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
|
# 0.7.10.0
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ class DiasporaLinkService
|
||||||
def find_or_fetch_entity
|
def find_or_fetch_entity
|
||||||
if type && guid
|
if type && guid
|
||||||
entity_finder.find || fetch_entity
|
entity_finder.find || fetch_entity
|
||||||
|
elsif author
|
||||||
|
find_or_fetch_person
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -30,6 +32,12 @@ class DiasporaLinkService
|
||||||
@entity_finder ||= Diaspora::EntityFinder.new(type, guid)
|
@entity_finder ||= Diaspora::EntityFinder.new(type, guid)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def find_or_fetch_person
|
||||||
|
Person.find_or_fetch_by_identifier(author)
|
||||||
|
rescue DiasporaFederation::Discovery::DiscoveryError
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
def normalize
|
def normalize
|
||||||
link.gsub!(%r{^web\+diaspora://}, "diaspora://") ||
|
link.gsub!(%r{^web\+diaspora://}, "diaspora://") ||
|
||||||
link.gsub!(%r{^//}, "diaspora://") ||
|
link.gsub!(%r{^//}, "diaspora://") ||
|
||||||
|
|
@ -42,6 +50,8 @@ class DiasporaLinkService
|
||||||
match = DiasporaFederation::Federation::DiasporaUrlParser::DIASPORA_URL_REGEX.match(link)
|
match = DiasporaFederation::Federation::DiasporaUrlParser::DIASPORA_URL_REGEX.match(link)
|
||||||
if match
|
if match
|
||||||
@author, @type, @guid = match.captures
|
@author, @type, @guid = match.captures
|
||||||
|
else
|
||||||
|
@author = %r{^diaspora://(#{Validation::Rule::DiasporaId::DIASPORA_ID_REGEX})$}u.match(link)&.captures&.first
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -52,5 +52,21 @@ describe DiasporaLinkService do
|
||||||
expect(service.find_or_fetch_entity).to be_nil
|
expect(service.find_or_fetch_entity).to be_nil
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue