From a475d5fb6288681a1c44d167080cfe26d2fe99de Mon Sep 17 00:00:00 2001 From: Lukas Matt <lukas@zauberstuhl.de> Date: Thu, 12 Feb 2015 18:24:47 +0100 Subject: [PATCH] Add the ability to link to remote user profile related to diaspora/jsxc#77 --- app/controllers/people_controller.rb | 16 ++++++++++++---- config/routes.rb | 4 ++-- spec/controllers/people_controller_spec.rb | 10 ++++++++++ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index e788c85298..baae6217de 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 7d6e9785f0..1c245599bf 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 734c19e9ea..f19222f8dc 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 -- GitLab