i am not a number! include username in the main url of a local user!

This commit is contained in:
Maxwell Salzberg 2011-07-29 18:19:55 -07:00
parent 540a3e68a6
commit d407be036e
3 changed files with 32 additions and 8 deletions

View file

@ -61,7 +61,7 @@ class PeopleController < ApplicationController
end
def show
@person = Person.where(:id => params[:id]).first
@person = find_person_from_id_or_username
if @person && @person.remote? && !user_signed_in?
render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
return
@ -156,4 +156,13 @@ class PeopleController < ApplicationController
Resque.enqueue(Job::SocketWebfinger, current_user.id, account, opts)
end
def find_person_from_id_or_username
if params[:id].present?
Person.where(:id => params[:id]).first
elsif params[:username].present?
User.find_by_username(params[:username]).person
else
nil
end
end
end

View file

@ -3,6 +3,9 @@
# the COPYRIGHT file.
module ApplicationHelper
def how_long_ago(obj)
timeago(obj.created_at)
end
@ -48,9 +51,15 @@ module ApplicationHelper
def person_link(person, opts={})
opts[:class] ||= ""
opts[:class] << " self" if defined?(user_signed_in?) && user_signed_in? && current_user.person == person
"<a href='/people/#{person.id}' class='#{opts[:class]}'>
#{h(person.name)}
</a>".html_safe
if person.local?
"<a href='#{person.diaspora_handle.split('@')[0]}' class='#{opts[:class]}'>
#{h(person.name)}
</a>".html_safe
else
"<a href='/people/#{person.id}'>
#{h(person.name)}
</a>".html_safe
end
end
def hard_link(string, path)
@ -62,9 +71,15 @@ module ApplicationHelper
if opts[:to] == :photos
link_to person_image_tag(person, opts[:size]), person_photos_path(person)
else
"<a href='/people/#{person.id}'>
#{person_image_tag(person)}
</a>".html_safe
if person.local?
"<a href='#{person.diaspora_handle.split('@')[0]}' class='#{opts[:class]}'>
#{person_image_tag(person)}
</a>".html_safe
else
"<a href='/people/#{person.id}'>
#{person_image_tag(person)}
</a>".html_safe
end
end
end

View file

@ -154,7 +154,7 @@ Diaspora::Application.routes.draw do
get 'mobile/toggle', :to => 'home#toggle_mobile', :as => 'toggle_mobile'
get ':username' => 'people#show', :as => 'user_profile'
# Startpage
root :to => 'home#show'