diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index e788c85298a92d8215727741edcef39c1fab6a6d..baae6217de85913e2638f76477e6a5d7b2d5d089 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -184,13 +184,21 @@ class PeopleController < ApplicationController private def find_person - @person = Person.find_from_guid_or_username({ - id: params[:id] || params[:person_id], - username: params[: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: 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 diff --git a/config/routes.rb b/config/routes.rb index 7d6e9785f056f0ace97b9e83ed4ecef1efbecdbe..1c245599bf60188d587e0fc6f092837619dd89c2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb index 734c19e9ead5b416add104f43883c41c9574dd87..f19222f8dced58b83c55f259d6ee7806c7c07184 100644 --- a/spec/controllers/people_controller_spec.rb +++ b/spec/controllers/people_controller_spec.rb @@ -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