use guid instead of id for /people/ urls

This commit is contained in:
Jonne Haß 2012-01-23 23:35:31 +01:00
parent 8f38a19976
commit 7aaaf4f43b
18 changed files with 58 additions and 51 deletions

View file

@ -84,7 +84,7 @@ class PeopleController < ApplicationController
end end
def show def show
@person = Person.find_from_id_or_username(params) @person = Person.find_from_guid_or_username(params)
if remote_profile_with_no_user_session? if remote_profile_with_no_user_session?
raise ActiveRecord::RecordNotFound raise ActiveRecord::RecordNotFound
@ -139,7 +139,7 @@ class PeopleController < ApplicationController
end end
def contacts def contacts
@person = Person.find_by_id(params[:person_id]) @person = Person.find_by_guid(params[:person_id])
if @person if @person
@contact = current_user.contact_for(@person) @contact = current_user.contact_for(@person)
@aspect = :profile @aspect = :profile
@ -154,7 +154,7 @@ class PeopleController < ApplicationController
end end
def aspect_membership_dropdown def aspect_membership_dropdown
@person = Person.find(params[:person_id]) @person = Person.find_by_guid(params[:person_id])
if @person == current_user.person if @person == current_user.person
render :text => I18n.t('people.person.thats_you') render :text => I18n.t('people.person.thats_you')
else else

View file

@ -108,7 +108,7 @@ class UsersController < ApplicationController
render :xml => director.build(ostatus_builder), :content_type => 'application/atom+xml' render :xml => director.build(ostatus_builder), :content_type => 'application/atom+xml'
end end
format.any { redirect_to person_path(user.person.id) } format.any { redirect_to person_path(user.person) }
end end
else else
redirect_to multi_stream_path, :error => I18n.t('users.public.does_not_exist', :username => params[:username]) redirect_to multi_stream_path, :error => I18n.t('users.public.does_not_exist', :username => params[:username])

View file

@ -31,7 +31,7 @@ module PeopleHelper
def person_link(person, opts={}) def person_link(person, opts={})
opts[:class] ||= "" opts[:class] ||= ""
opts[:class] << " self" if defined?(user_signed_in?) && user_signed_in? && current_user.person == person opts[:class] << " self" if defined?(user_signed_in?) && user_signed_in? && current_user.person == person
remote_or_hovercard_link = "/people/#{person.id}".html_safe remote_or_hovercard_link = Rails.application.routes.url_helpers.person_path(person).html_safe
"<a data-hovercard='#{remote_or_hovercard_link}' #{person_href(person)} class='#{opts[:class]}' #{ ("target=" + opts[:target]) if opts[:target]}>#{h(person.name)}</a>".html_safe "<a data-hovercard='#{remote_or_hovercard_link}' #{person_href(person)} class='#{opts[:class]}' #{ ("target=" + opts[:target]) if opts[:target]}>#{h(person.name)}</a>".html_safe
end end

View file

@ -14,6 +14,7 @@ class Person < ActiveRecord::Base
acts_as_api acts_as_api
api_accessible :backbone do |t| api_accessible :backbone do |t|
t.add :id t.add :id
t.add :guid
t.add :name t.add :name
t.add lambda { |person| t.add lambda { |person|
person.diaspora_handle person.diaspora_handle
@ -61,7 +62,7 @@ class Person < ActiveRecord::Base
scope :searchable, joins(:profile).where(:profiles => {:searchable => true}) scope :searchable, joins(:profile).where(:profiles => {:searchable => true})
scope :remote, where('people.owner_id IS NULL') scope :remote, where('people.owner_id IS NULL')
scope :local, where('people.owner_id IS NOT NULL') scope :local, where('people.owner_id IS NOT NULL')
scope :for_json, select('DISTINCT people.id, people.diaspora_handle').includes(:profile) scope :for_json, select('DISTINCT people.id, people.guid, people.diaspora_handle').includes(:profile)
# @note user is passed in here defensively # @note user is passed in here defensively
scope :all_from_aspects, lambda { |aspect_ids, user| scope :all_from_aspects, lambda { |aspect_ids, user|
@ -95,9 +96,9 @@ class Person < ActiveRecord::Base
self.profile ||= Profile.new unless profile_set self.profile ||= Profile.new unless profile_set
end end
def self.find_from_id_or_username(params) def self.find_from_guid_or_username(params)
p = if params[:id].present? p = if params[:id].present?
Person.where(:id => params[:id]).first Person.where(:guid => params[:id]).first
elsif params[:username].present? && u = User.find_by_username(params[:username]) elsif params[:username].present? && u = User.find_by_username(params[:username])
u.person u.person
else else
@ -107,6 +108,10 @@ class Person < ActiveRecord::Base
p p
end end
def to_param
self.guid
end
def self.search_query_string(query) def self.search_query_string(query)
query = query.downcase query = query.downcase
like_operator = postgres? ? "ILIKE" : "LIKE" like_operator = postgres? ? "ILIKE" : "LIKE"
@ -273,10 +278,11 @@ class Person < ActiveRecord::Base
opts ||= {} opts ||= {}
json = { json = {
:id => self.id, :id => self.id,
:guid => self.guid,
:name => self.name, :name => self.name,
:avatar => self.profile.image_url(:thumb_medium), :avatar => self.profile.image_url(:thumb_medium),
:handle => self.diaspora_handle, :handle => self.diaspora_handle,
:url => "/people/#{self.id}", :url => Rails.application.routes.url_helpers.person_path(self),
} }
json.merge!(:tags => self.profile.tags.map{|t| "##{t.name}"}) if opts[:includes] == "tags" json.merge!(:tags => self.profile.tags.map{|t| "##{t.name}"}) if opts[:includes] == "tags"
json json

View file

@ -7,13 +7,13 @@
{{/if}} {{/if}}
</div> </div>
<a href="/people/{{author.id}}"> <a href="/people/{{author.guid}}">
<img src="{{author.avatar.small}}" class="avatar" /> <img src="{{author.avatar.small}}" class="avatar" />
</a> </a>
<div class="content"> <div class="content">
<span class="from"> <span class="from">
<a href="/people/{{author.id}}"> <a href="/people/{{author.guid}}">
{{author.name}} {{author.name}}
</a> </a>
</span> </span>

View file

@ -13,7 +13,7 @@
<% if(current_user) { %> <% if(current_user) { %>
<div class="new_comment_form_wrapper <%= comments_count > 0 ? '' : 'hidden' %>"> <div class="new_comment_form_wrapper <%= comments_count > 0 ? '' : 'hidden' %>">
<form accept-charset="UTF-8" action="/posts/<%= id %>/comments" class="new_comment" id="new_comment_on_<%= id %>" method="post"> <form accept-charset="UTF-8" action="/posts/<%= id %>/comments" class="new_comment" id="new_comment_on_<%= id %>" method="post">
<a href="/people/<%= current_user.id %>"> <a href="/people/<%= current_user.guid %>">
<img src="<%= current_user.avatar.small %>" class="avatar" data-person-id="<%= current_user.id %>"/> <img src="<%= current_user.avatar.small %>" class="avatar" data-person-id="<%= current_user.id %>"/>
</a> </a>

View file

@ -84,7 +84,7 @@
<img alt="{{current_user.name}}" class="avatar" src="{{current_user.avatar.small}}" title="{{current_user.name}}" /> <img alt="{{current_user.name}}" class="avatar" src="{{current_user.avatar.small}}" title="{{current_user.name}}" />
<a href="#">{{current_user.name}}</a> <a href="#">{{current_user.name}}</a>
</li> </li>
<li><a href="/people/{{current_user.id}}">{{t "header.profile"}}</a></li> <li><a href="/people/{{current_user.guid}}">{{t "header.profile"}}</a></li>
<li><a href="/contacts">{{t "header.contacts"}}</a></li> <li><a href="/contacts">{{t "header.contacts"}}</a></li>
<li><a href="/user/edit">{{t "header.settings"}}</a></li> <li><a href="/user/edit">{{t "header.settings"}}</a></li>
{{#if current_user.admin}} {{#if current_user.admin}}

View file

@ -7,7 +7,7 @@
<% } else { %> <% } else { %>
<span class="likes_list"> <span class="likes_list">
<% _.each(likes, function(like){ %> <% _.each(likes, function(like){ %>
<a href="/people/<%= like.get("author").id %>"> <a href="/people/<%= like.get("author").guid %>">
<img src="<%= like.get("author").avatar.small %>" class="avatar" title="<%= like.get("author").name %>"/> <img src="<%= like.get("author").avatar.small %>" class="avatar" title="<%= like.get("author").name %>"/>
</a> </a>
<% }) %> <% }) %>

View file

@ -2,14 +2,14 @@
<% if(root) { %> <% if(root) { %>
<a href="/people/<%= root.author.id %>"> <a href="/people/<%= root.author.guid %>">
<img src="<%= root.author.avatar.small %>" class="avatar" data-person-id="<%= root.author.id %>"/> <img src="<%= root.author.avatar.small %>" class="avatar" data-person-id="<%= root.author.id %>"/>
</a> </a>
<div class="content"> <div class="content">
<div class="post_initial_info"> <div class="post_initial_info">
<span class="from"> <span class="from">
<a href="/people/<%= root.author.id %>"> <a href="/people/<%= root.author.guid %>">
<%= root.author.name %> <%= root.author.name %>
</a> </a>
</span> </span>

View file

@ -13,7 +13,7 @@
</div> </div>
<div class="sm_body"> <div class="sm_body">
<a href="/people/<%= author.id %>"> <a href="/people/<%= author.guid %>">
<img src="<%= author.avatar.small %>" class="avatar" /> <img src="<%= author.avatar.small %>" class="avatar" />
</a> </a>
@ -21,7 +21,7 @@
<div class="post_initial_info"> <div class="post_initial_info">
<span class="from"> <span class="from">
<a href="/people/<%= author.id %>"> <a href="/people/<%= author.guid %>">
<%= author.name %> <%= author.name %>
</a> </a>
</span> </span>

View file

@ -1,5 +1,5 @@
{{#people}} {{#people}}
<a href="/people/{{id}}"> <a href="/people/{{guid}}">
<img class="avatar" src="{{avatar.small}}" title="{{name}}"/> <img class="avatar" src="{{avatar.small}}" title="{{name}}"/>
</a> </a>
{{/people}} {{/people}}

View file

@ -19,7 +19,7 @@
.span-24.last{:style => "text-align:right;"} .span-24.last{:style => "text-align:right;"}
%p.subtle %p.subtle
!= t('.screenshot_explanation', :link1 => link_to(t('.typical_userpage'), "http://cubbi.es/daniel"), :link2 => link_to(t('.daniels_account'), "https://joindiaspora.com/people/29")) != t('.screenshot_explanation', :link1 => link_to(t('.typical_userpage'), "http://cubbi.es/daniel"), :link2 => link_to(t('.daniels_account'), "https://joindiaspora.com/u/daniel"))
%br %br
%hr %hr

View file

@ -95,7 +95,7 @@ ActiveRecord::Schema.define(:version => 20120114191018) do
t.datetime "updated_at" t.datetime "updated_at"
end end
add_index "conversation_visibilities", ["conversation_id", "person_id"], :name => "index_conversation_visibilities_usefully", :unique => true add_index "conversation_visibilities", ["conversation_id", "person_id"], :name => "index_conversation_visibilities_on_conversation_id_and_person_id", :unique => true
add_index "conversation_visibilities", ["conversation_id"], :name => "index_conversation_visibilities_on_conversation_id" add_index "conversation_visibilities", ["conversation_id"], :name => "index_conversation_visibilities_on_conversation_id"
add_index "conversation_visibilities", ["person_id"], :name => "index_conversation_visibilities_on_person_id" add_index "conversation_visibilities", ["person_id"], :name => "index_conversation_visibilities_on_person_id"
@ -309,9 +309,9 @@ ActiveRecord::Schema.define(:version => 20120114191018) do
t.string "provider_display_name" t.string "provider_display_name"
t.string "actor_url" t.string "actor_url"
t.string "objectId" t.string "objectId"
t.string "root_guid", :limit => 30
t.string "status_message_guid" t.string "status_message_guid"
t.integer "likes_count", :default => 0 t.integer "likes_count", :default => 0
t.string "root_guid", :limit => 30
t.integer "comments_count", :default => 0 t.integer "comments_count", :default => 0
t.integer "o_embed_cache_id" t.integer "o_embed_cache_id"
t.integer "reshares_count", :default => 0 t.integer "reshares_count", :default => 0
@ -457,9 +457,9 @@ ActiveRecord::Schema.define(:version => 20120114191018) do
t.integer "invited_by_id" t.integer "invited_by_id"
t.string "invited_by_type" t.string "invited_by_type"
t.string "authentication_token", :limit => 30 t.string "authentication_token", :limit => 30
t.datetime "locked_at"
t.string "unconfirmed_email" t.string "unconfirmed_email"
t.string "confirm_email_token", :limit => 30 t.string "confirm_email_token", :limit => 30
t.datetime "locked_at"
t.boolean "show_community_spotlight_in_stream", :default => true, :null => false t.boolean "show_community_spotlight_in_stream", :default => true, :null => false
t.boolean "auto_follow_back", :default => false t.boolean "auto_follow_back", :default => false
t.integer "auto_follow_back_aspect_id" t.integer "auto_follow_back_aspect_id"

View file

@ -29,7 +29,7 @@
return person.diaspora_id == diasporaId return person.diaspora_id == diasporaId
}) })
return person ? "<a href='/people/" + person.id + "' class='mention'>" + fullName + "</a>" : fullName; return person ? "<a href='/people/" + person.guid + "' class='mention'>" + fullName + "</a>" : fullName;
}) })
} }

View file

@ -140,7 +140,7 @@ describe PeopleController do
it 'takes time' do it 'takes time' do
Benchmark.realtime { Benchmark.realtime {
get :show, :id => @user.person.id get :show, :id => @user.person.to_param
}.should < 1.0 }.should < 1.0
end end
end end
@ -163,7 +163,7 @@ describe PeopleController do
it 'redirects home for closed account' do it 'redirects home for closed account' do
@person = Factory(:person, :closed_account => true) @person = Factory(:person, :closed_account => true)
get :show, :id => @person.id get :show, :id => @person.to_param
response.should be_redirect response.should be_redirect
flash[:notice].should_not be_blank flash[:notice].should_not be_blank
end end
@ -173,7 +173,7 @@ describe PeopleController do
profile = user2.profile profile = user2.profile
profile.first_name = "<script> alert('xss attack');</script>" profile.first_name = "<script> alert('xss attack');</script>"
profile.save profile.save
get :show, :id => user2.person.id get :show, :id => user2.person.to_param
response.should be_success response.should be_success
response.body.match(profile.first_name).should be_false response.body.match(profile.first_name).should be_false
end end
@ -208,7 +208,7 @@ describe PeopleController do
it "renders the comments on the user's posts" do it "renders the comments on the user's posts" do
message = @user.post :status_message, :text => 'test more', :to => @aspect.id message = @user.post :status_message, :text => 'test more', :to => @aspect.id
@user.comment 'I mean it', :post => message @user.comment 'I mean it', :post => message
get :show, :id => @user.person.id get :show, :id => @user.person.to_param
response.should be_success response.should be_success
end end
end end
@ -220,12 +220,12 @@ describe PeopleController do
end end
it "succeeds" do it "succeeds" do
get :show, :id => @person.id get :show, :id => @person.to_param
response.status.should == 200 response.status.should == 200
end end
it 'succeeds on the mobile site' do it 'succeeds on the mobile site' do
get :show, :id => @person.id, :format => :mobile get :show, :id => @person.to_param, :format => :mobile
response.should be_success response.should be_success
end end
@ -242,17 +242,17 @@ describe PeopleController do
it "posts include reshares" do it "posts include reshares" do
reshare = @user.post(:reshare, :public => true, :root_guid => Factory(:status_message, :public => true).guid, :to => alice.aspects) reshare = @user.post(:reshare, :public => true, :root_guid => Factory(:status_message, :public => true).guid, :to => alice.aspects)
get :show, :id => @user.person.id get :show, :id => @user.person.to_param
assigns[:stream].posts.map{|x| x.id}.should include(reshare.id) assigns[:stream].posts.map{|x| x.id}.should include(reshare.id)
end end
it "assigns only public posts" do it "assigns only public posts" do
get :show, :id => @person.id get :show, :id => @person.to_param
assigns[:stream].posts.map(&:id).should =~ @public_posts.map(&:id) assigns[:stream].posts.map(&:id).should =~ @public_posts.map(&:id)
end end
it 'is sorted by created_at desc' do it 'is sorted by created_at desc' do
get :show, :id => @person.id get :show, :id => @person.to_param
assigns[:stream].stream_posts.should == @public_posts.sort_by{|p| p.created_at}.reverse assigns[:stream].stream_posts.should == @public_posts.sort_by{|p| p.created_at}.reverse
end end
end end
@ -271,12 +271,12 @@ describe PeopleController do
end end
it "succeeds" do it "succeeds" do
get :show, :id => @person.id get :show, :id => @person.to_param
response.should be_success response.should be_success
end end
it 'succeeds on the mobile site' do it 'succeeds on the mobile site' do
get :show, :id => @person.id, :format => :mobile get :show, :id => @person.to_param, :format => :mobile
response.should be_success response.should be_success
end end
@ -291,13 +291,13 @@ describe PeopleController do
posts_user_can_see << bob.post(:status_message, :text => "public", :to => 'all', :public => true) posts_user_can_see << bob.post(:status_message, :text => "public", :to => 'all', :public => true)
bob.reload.posts.length.should == 4 bob.reload.posts.length.should == 4
get :show, :id => @person.id get :show, :id => @person.to_param
assigns(:stream).posts.map(&:id).should =~ posts_user_can_see.map(&:id) assigns(:stream).posts.map(&:id).should =~ posts_user_can_see.map(&:id)
end end
it "posts include reshares" do it "posts include reshares" do
reshare = @user.post(:reshare, :public => true, :root_guid => Factory(:status_message, :public => true).guid, :to => alice.aspects) reshare = @user.post(:reshare, :public => true, :root_guid => Factory(:status_message, :public => true).guid, :to => alice.aspects)
get :show, :id => @user.person.id get :show, :id => @user.person.to_param
assigns[:stream].posts.map{|x| x.id}.should include(reshare.id) assigns[:stream].posts.map{|x| x.id}.should include(reshare.id)
end end
end end
@ -308,12 +308,12 @@ describe PeopleController do
end end
it "succeeds" do it "succeeds" do
get :show, :id => @person.id get :show, :id => @person.to_param
response.should be_success response.should be_success
end end
it 'succeeds on the mobile site' do it 'succeeds on the mobile site' do
get :show, :id => @person.id, :format => :mobile get :show, :id => @person.to_param, :format => :mobile
response.should be_success response.should be_success
end end
@ -324,13 +324,13 @@ describe PeopleController do
public_post = eve.post(:status_message, :text => "public", :to => 'all', :public => true) public_post = eve.post(:status_message, :text => "public", :to => 'all', :public => true)
eve.reload.posts.length.should == 3 eve.reload.posts.length.should == 3
get :show, :id => @person.id get :show, :id => @person.to_param
assigns[:stream].posts.map(&:id).should =~ [public_post].map(&:id) assigns[:stream].posts.map(&:id).should =~ [public_post].map(&:id)
end end
it "posts include reshares" do it "posts include reshares" do
reshare = @user.post(:reshare, :public => true, :root_guid => Factory(:status_message, :public => true).guid, :to => alice.aspects) reshare = @user.post(:reshare, :public => true, :root_guid => Factory(:status_message, :public => true).guid, :to => alice.aspects)
get :show, :id => @user.person.id get :show, :id => @user.person.to_param
assigns[:stream].posts.map{|x| x.id}.should include(reshare.id) assigns[:stream].posts.map{|x| x.id}.should include(reshare.id)
end end
end end
@ -340,7 +340,7 @@ describe PeopleController do
it 'assigns the contacts of a person' do it 'assigns the contacts of a person' do
contact = alice.contact_for(bob.person) contact = alice.contact_for(bob.person)
contacts = contact.contacts contacts = contact.contacts
get :contacts, :person_id => bob.person.id get :contacts, :person_id => bob.person.to_param
assigns(:contacts_of_contact).should =~ contacts assigns(:contacts_of_contact).should =~ contacts
response.should be_success response.should be_success
end end

View file

@ -189,7 +189,7 @@ describe PhotosController do
it "redirects when the user does not own the photo" do it "redirects when the user does not own the photo" do
get :edit, :id => @bobs_photo.id get :edit, :id => @bobs_photo.id
response.should redirect_to(:action => :index, :person_id => alice.person.id.to_s) response.should redirect_to(:action => :index, :person_id => alice.person.guid.to_s)
end end
end end
@ -239,7 +239,7 @@ describe PhotosController do
it 'redirects if you do not have access to the post' do it 'redirects if you do not have access to the post' do
params = { :text => "now with lasers!" } params = { :text => "now with lasers!" }
put :update, :id => @bobs_photo.id, :photo => params put :update, :id => @bobs_photo.id, :photo => params
response.should redirect_to(:action => :index, :person_id => alice.person.id.to_s) response.should redirect_to(:action => :index, :person_id => alice.person.guid.to_s)
end end
end end

View file

@ -101,7 +101,7 @@ describe("app.helpers.textFormatter", function(){
var wrapper = $("<div>").html(formattedText); var wrapper = $("<div>").html(formattedText);
_.each([this.alice, this.bob], function(person) { _.each([this.alice, this.bob], function(person) {
expect(wrapper.find("a[href='/people/" + person.id + "']").text()).toContain(person.name) expect(wrapper.find("a[href='/people/" + person.guid + "']").text()).toContain(person.name)
}) })
}); });

View file

@ -53,24 +53,24 @@ describe Person do
end end
end end
describe '.find_person_from_id_or_username' do describe '.find_person_from_guid_or_username' do
it 'searchs for a person if id is passed' do it 'searchs for a person if id is passed' do
Person.find_from_id_or_username(:id => @person.id).id.should == @person.id Person.find_from_guid_or_username(:id => @person.guid).id.should == @person.id
end end
it 'searchs a person from a user if username is passed' do it 'searchs a person from a user if username is passed' do
Person.find_from_id_or_username(:username => @user.username).id.should == @user.person.id Person.find_from_guid_or_username(:username => @user.username).id.should == @user.person.id
end end
it 'throws active record not found exceptions if no person is found via id' do it 'throws active record not found exceptions if no person is found via id' do
expect{ expect{
Person.find_from_id_or_username(:id => 213123) Person.find_from_guid_or_username(:id => 213123)
}.to raise_error ActiveRecord::RecordNotFound }.to raise_error ActiveRecord::RecordNotFound
end end
it 'throws active record not found exceptions if no person is found via username' do it 'throws active record not found exceptions if no person is found via username' do
expect{ expect{
Person.find_from_id_or_username(:username => 'michael_jackson') Person.find_from_guid_or_username(:username => 'michael_jackson')
}.to raise_error ActiveRecord::RecordNotFound }.to raise_error ActiveRecord::RecordNotFound
end end
end end
@ -463,10 +463,11 @@ describe Person do
it 'returns a hash representation of a person' do it 'returns a hash representation of a person' do
@person.as_json.should == { @person.as_json.should == {
:id => @person.id, :id => @person.id,
:guid => @person.guid,
:name => @person.name, :name => @person.name,
:avatar => @person.profile.image_url(:thumb_medium), :avatar => @person.profile.image_url(:thumb_medium),
:handle => @person.diaspora_handle, :handle => @person.diaspora_handle,
:url => "/people/#{@person.id}", :url => Rails.application.routes.url_helpers.person_path(@person),
} }
end end
it 'return tags if asked' do it 'return tags if asked' do