refactor out profile url generation into local_or_remote_person_path and use it everywhere. closes #2471
This commit is contained in:
parent
7a474e8199
commit
a892ea41eb
13 changed files with 51 additions and 23 deletions
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
module LikesHelper
|
||||
def likes_list(likes)
|
||||
links = likes.collect { |like| link_to "#{h(like.author.name.titlecase)}", person_path(like.author) }
|
||||
links = likes.collect { |like| link_to "#{h(like.author.name.titlecase)}", local_or_remote_person_path(like.author) }
|
||||
links.join(", ").html_safe
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -52,17 +52,30 @@ module PeopleHelper
|
|||
end
|
||||
|
||||
def person_href(person, opts={})
|
||||
if opts[:absolute]
|
||||
link = "href='#{AppConfig.pod_url}"
|
||||
else
|
||||
link = "href='/"
|
||||
end
|
||||
"href=\"#{local_or_remote_person_path(person, opts)}\""
|
||||
end
|
||||
|
||||
|
||||
# Rails.application.routes.url_helpers is needed since this is indirectly called from a model
|
||||
def local_or_remote_person_path(person, opts={})
|
||||
opts.merge!(:protocol => AppConfig[:pod_uri].scheme, :host => AppConfig[:pod_uri].authority)
|
||||
|
||||
if person.local?
|
||||
username = person.diaspora_handle.split('@')[0]
|
||||
unless username.include?('.')
|
||||
return link+"u/#{person.diaspora_handle.split('@')[0]}'"
|
||||
opts.merge!(:username => username)
|
||||
if opts[:absolute]
|
||||
return Rails.application.routes.url_helpers.user_profile_url(opts)
|
||||
else
|
||||
return Rails.application.routes.url_helpers.user_profile_path(opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
return link+"people/#{person.id}'"
|
||||
|
||||
if opts[:absolute]
|
||||
return Rails.application.routes.url_helpers.person_url(person, opts)
|
||||
else
|
||||
return Rails.application.routes.url_helpers.person_path(person, opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ module StreamHelper
|
|||
elsif controller.instance_of?(AppsController)
|
||||
"/apps/1?#{{:max_time => @posts.last.created_at.to_i}.to_param}"
|
||||
elsif controller.instance_of?(PeopleController)
|
||||
person_path(@person, :max_time => time_for_scroll(opts[:ajax_stream], @stream))
|
||||
local_or_remote_person_path(@person, :max_time => time_for_scroll(opts[:ajax_stream], @stream))
|
||||
elsif controller.instance_of?(TagFollowingsController)
|
||||
tag_followings_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :sort_order => session[:sort_order])
|
||||
elsif controller.instance_of?(CommunitySpotlightController)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ class Notifier < ActionMailer::Base
|
|||
helper :application
|
||||
helper :markdownify
|
||||
helper :notifier
|
||||
helper :people
|
||||
|
||||
def self.admin(string, recipients, opts = {})
|
||||
mails = []
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@
|
|||
#home_user_badge
|
||||
= owner_image_link
|
||||
%h4
|
||||
= link_to current_user.first_name, "/u/#{current_user.username}"
|
||||
= link_to current_user.first_name, local_or_remote_person_path(current_user.person)
|
||||
|
||||
.section
|
||||
%ul.left_nav
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@
|
|||
.avatar
|
||||
= owner_image_tag(:thumb_small)
|
||||
= link_to current_user.name, '#', :title => current_user.diaspora_handle
|
||||
%li= link_to t('.profile'), current_user.person
|
||||
%li= link_to t('.profile'), local_or_remote_person_path(current_user.person)
|
||||
%li= link_to t('_contacts'), contacts_link
|
||||
%li= link_to t('.settings'), edit_user_path
|
||||
-if current_user.admin?
|
||||
|
|
|
|||
|
|
@ -2,4 +2,4 @@
|
|||
= @notification.sender.name
|
||||
= t('.sharing')
|
||||
%p
|
||||
= link_to t('.view_profile', :name => @notification.sender.first_name), person_url(@notification.sender)
|
||||
= link_to t('.view_profile', :name => @notification.sender.first_name), local_or_remote_person_path(@notification.sender, :absolute => true)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
!= "#{@notification.sender.name}"
|
||||
!= t('notifier.started_sharing.sharing')
|
||||
!= t('.view_profile', :name => @notification.sender.first_name)
|
||||
!= person_url(@notification.sender)
|
||||
!= local_or_remote_person_path(@notification.sender, :absolute => true)
|
||||
|
|
|
|||
|
|
@ -10,4 +10,4 @@
|
|||
=person_link(person)
|
||||
|
||||
.info
|
||||
= link_to person.diaspora_handle, person_path(person), :class => 'black'
|
||||
= link_to person.diaspora_handle, local_or_remote_person_path(person), :class => 'black'
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
.span-12.prepend-5.last
|
||||
- content_for :submit_block do
|
||||
= link_to t('cancel'), person_path(current_user.person), :class => "button"
|
||||
= link_to t('cancel'), local_or_remote_person_path(current_user.person), :class => "button"
|
||||
= submit_tag t('.update_profile'), :class => "creation"
|
||||
= render :partial => 'edit', :locals => {:person => @person,
|
||||
:profile => @profile, :aspect => @aspect, :step => @step}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
.content
|
||||
%span.from.name
|
||||
- if friend.on_diaspora?
|
||||
= link_to friend.name, person_path(friend.person)
|
||||
= link_to friend.name, local_or_remote_person_path(friend.person)
|
||||
- else
|
||||
= friend.name
|
||||
|
||||
|
|
|
|||
|
|
@ -5,5 +5,5 @@
|
|||
= person.name
|
||||
|
||||
#person_nav_links
|
||||
= link_to t('layouts.header.profile'), person_path(person)
|
||||
= link_to t('layouts.header.profile'), local_or_remote_person_path(person)
|
||||
= link_to t('_photos'), person_photos_path(person)
|
||||
|
|
|
|||
|
|
@ -59,10 +59,25 @@ describe PeopleHelper do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#person_href' do
|
||||
describe "#person_href" do
|
||||
it "calls local_or_remote_person_path and passes through the options" do
|
||||
opts = {:absolute => true}
|
||||
|
||||
self.should_receive(:local_or_remote_person_path).with(@person, opts).exactly(1).times
|
||||
|
||||
person_href(@person, opts)
|
||||
end
|
||||
|
||||
it "returns a href attribute" do
|
||||
person_href(@person).should include "href="
|
||||
end
|
||||
end
|
||||
|
||||
describe '#local_or_remote_person_path' do
|
||||
before do
|
||||
@user = Factory(:user)
|
||||
end
|
||||
|
||||
it "links by id if there is a period in the user's username" do
|
||||
@user.username = "invalid.username"
|
||||
@user.save(:validate => false).should == true
|
||||
|
|
@ -70,17 +85,16 @@ describe PeopleHelper do
|
|||
person.diaspora_handle = "#{@user.username}@#{AppConfig[:pod_uri].authority}"
|
||||
person.save!
|
||||
|
||||
person_href(@user.person).should include("href='/people/#{@user.person.id}'")
|
||||
local_or_remote_person_path(@user.person).should == person_path(@user.person)
|
||||
end
|
||||
|
||||
it 'links by username for a local user' do
|
||||
person_href(@user.person).should include(@user.username)
|
||||
local_or_remote_person_path(@user.person).should == user_profile_path(:username => @user.username)
|
||||
end
|
||||
|
||||
it 'links by id for a remote person' do
|
||||
person = Factory(:person)
|
||||
person_href(person).should include("/people/#{person.id}")
|
||||
local_or_remote_person_path(@person).should == person_path(@person)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue