Add the ability to link to remote user profile

related to diaspora/jsxc#77
This commit is contained in:
Lukas Matt 2015-02-12 18:24:47 +01:00
parent a5d9d779ff
commit a475d5fb62
3 changed files with 24 additions and 6 deletions

View file

@ -184,13 +184,21 @@ class PeopleController < ApplicationController
private
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],
username: params[:username]
username: username
})
end
# view this profile on the home pod, if you don't want to sign in...
authenticate_user! if remote_profile_with_no_user_session?
raise ActiveRecord::RecordNotFound if @person.nil?
raise Diaspora::AccountClosed if @person.closed_account?
end

View file

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

View file

@ -179,6 +179,16 @@ describe PeopleController, :type => :controller do
expect(assigns(:person)).to eq(@user.person)
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
@person = FactoryGirl.create(:person, :closed_account => true)
get :show, :id => @person.to_param