Merge pull request #5659 from Zauberstuhl/link_to_remote_profile

Add the ability to link remote user profiles
This commit is contained in:
Jonne Haß 2015-02-13 20:35:14 +01:00
commit 84cfaa1cfb
3 changed files with 24 additions and 6 deletions

View file

@ -184,13 +184,21 @@ class PeopleController < ApplicationController
private private
def find_person def find_person
@person = Person.find_from_guid_or_username({ username = params[:username]
@person = if diaspora_id?(username)
Person.where({
diaspora_handle: username.downcase
}).first
else
Person.find_from_guid_or_username({
id: params[:id] || params[:person_id], id: params[:id] || params[:person_id],
username: params[:username] username: username
}) })
end
# view this profile on the home pod, if you don't want to sign in... # view this profile on the home pod, if you don't want to sign in...
authenticate_user! if remote_profile_with_no_user_session? authenticate_user! if remote_profile_with_no_user_session?
raise ActiveRecord::RecordNotFound if @person.nil?
raise Diaspora::AccountClosed if @person.closed_account? raise Diaspora::AccountClosed if @person.closed_account?
end end

View file

@ -175,8 +175,8 @@ Diaspora::Application.routes.draw do
get :tag_index get :tag_index
end end
end end
get '/u/:username' => 'people#show', :as => 'user_profile' get '/u/:username' => 'people#show', :as => 'user_profile', :constraints => { :username => /[^\/]+/ }
get '/u/:username/profile_photo' => 'users#user_photo' get '/u/:username/profile_photo' => 'users#user_photo', :constraints => { :username => /[^\/]+/ }
# Federation # Federation

View file

@ -179,6 +179,16 @@ describe PeopleController, :type => :controller do
expect(assigns(:person)).to eq(@user.person) expect(assigns(:person)).to eq(@user.person)
end end
it "404s if no person is found via diaspora handle" do
get :show, :username => 'delicious@pod.net'
expect(response.code).to eq("404")
end
it 'finds a person via diaspora handle' do
get :show, username: @user.diaspora_handle
expect(assigns(:person)).to eq(@user.person)
end
it 'redirects home for closed account' do it 'redirects home for closed account' do
@person = FactoryGirl.create(:person, :closed_account => true) @person = FactoryGirl.create(:person, :closed_account => true)
get :show, :id => @person.to_param get :show, :id => @person.to_param