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

View file

@ -108,7 +108,7 @@ class UsersController < ApplicationController
render :xml => director.build(ostatus_builder), :content_type => 'application/atom+xml'
end
format.any { redirect_to person_path(user.person.id) }
format.any { redirect_to person_path(user.person) }
end
else
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={})
opts[:class] ||= ""
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
end

View file

@ -14,6 +14,7 @@ class Person < ActiveRecord::Base
acts_as_api
api_accessible :backbone do |t|
t.add :id
t.add :guid
t.add :name
t.add lambda { |person|
person.diaspora_handle
@ -61,7 +62,7 @@ class Person < ActiveRecord::Base
scope :searchable, joins(:profile).where(:profiles => {:searchable => true})
scope :remote, where('people.owner_id IS 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
scope :all_from_aspects, lambda { |aspect_ids, user|
@ -95,9 +96,9 @@ class Person < ActiveRecord::Base
self.profile ||= Profile.new unless profile_set
end
def self.find_from_id_or_username(params)
def self.find_from_guid_or_username(params)
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])
u.person
else
@ -107,6 +108,10 @@ class Person < ActiveRecord::Base
p
end
def to_param
self.guid
end
def self.search_query_string(query)
query = query.downcase
like_operator = postgres? ? "ILIKE" : "LIKE"
@ -273,10 +278,11 @@ class Person < ActiveRecord::Base
opts ||= {}
json = {
:id => self.id,
:guid => self.guid,
:name => self.name,
:avatar => self.profile.image_url(:thumb_medium),
: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

View file

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

View file

@ -13,7 +13,7 @@
<% if(current_user) { %>
<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">
<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 %>"/>
</a>

View file

@ -84,7 +84,7 @@
<img alt="{{current_user.name}}" class="avatar" src="{{current_user.avatar.small}}" title="{{current_user.name}}" />
<a href="#">{{current_user.name}}</a>
</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="/user/edit">{{t "header.settings"}}</a></li>
{{#if current_user.admin}}

View file

@ -7,7 +7,7 @@
<% } else { %>
<span class="likes_list">
<% _.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 %>"/>
</a>
<% }) %>

View file

@ -2,14 +2,14 @@
<% 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 %>"/>
</a>
<div class="content">
<div class="post_initial_info">
<span class="from">
<a href="/people/<%= root.author.id %>">
<a href="/people/<%= root.author.guid %>">
<%= root.author.name %>
</a>
</span>

View file

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

View file

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

View file

@ -19,7 +19,7 @@
.span-24.last{:style => "text-align:right;"}
%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
%hr

View file

@ -95,7 +95,7 @@ ActiveRecord::Schema.define(:version => 20120114191018) do
t.datetime "updated_at"
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", ["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 "actor_url"
t.string "objectId"
t.string "root_guid", :limit => 30
t.string "status_message_guid"
t.integer "likes_count", :default => 0
t.string "root_guid", :limit => 30
t.integer "comments_count", :default => 0
t.integer "o_embed_cache_id"
t.integer "reshares_count", :default => 0
@ -457,9 +457,9 @@ ActiveRecord::Schema.define(:version => 20120114191018) do
t.integer "invited_by_id"
t.string "invited_by_type"
t.string "authentication_token", :limit => 30
t.datetime "locked_at"
t.string "unconfirmed_email"
t.string "confirm_email_token", :limit => 30
t.datetime "locked_at"
t.boolean "show_community_spotlight_in_stream", :default => true, :null => false
t.boolean "auto_follow_back", :default => false
t.integer "auto_follow_back_aspect_id"

View file

@ -29,7 +29,7 @@
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
Benchmark.realtime {
get :show, :id => @user.person.id
get :show, :id => @user.person.to_param
}.should < 1.0
end
end
@ -163,7 +163,7 @@ describe PeopleController do
it 'redirects home for closed account' do
@person = Factory(:person, :closed_account => true)
get :show, :id => @person.id
get :show, :id => @person.to_param
response.should be_redirect
flash[:notice].should_not be_blank
end
@ -173,7 +173,7 @@ describe PeopleController do
profile = user2.profile
profile.first_name = "<script> alert('xss attack');</script>"
profile.save
get :show, :id => user2.person.id
get :show, :id => user2.person.to_param
response.should be_success
response.body.match(profile.first_name).should be_false
end
@ -208,7 +208,7 @@ describe PeopleController do
it "renders the comments on the user's posts" do
message = @user.post :status_message, :text => 'test more', :to => @aspect.id
@user.comment 'I mean it', :post => message
get :show, :id => @user.person.id
get :show, :id => @user.person.to_param
response.should be_success
end
end
@ -220,12 +220,12 @@ describe PeopleController do
end
it "succeeds" do
get :show, :id => @person.id
get :show, :id => @person.to_param
response.status.should == 200
end
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
end
@ -242,17 +242,17 @@ describe PeopleController do
it "posts include reshares" do
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)
end
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)
end
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
end
end
@ -271,12 +271,12 @@ describe PeopleController do
end
it "succeeds" do
get :show, :id => @person.id
get :show, :id => @person.to_param
response.should be_success
end
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
end
@ -291,13 +291,13 @@ describe PeopleController do
posts_user_can_see << bob.post(:status_message, :text => "public", :to => 'all', :public => true)
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)
end
it "posts include reshares" do
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)
end
end
@ -308,12 +308,12 @@ describe PeopleController do
end
it "succeeds" do
get :show, :id => @person.id
get :show, :id => @person.to_param
response.should be_success
end
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
end
@ -324,13 +324,13 @@ describe PeopleController do
public_post = eve.post(:status_message, :text => "public", :to => 'all', :public => true)
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)
end
it "posts include reshares" do
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)
end
end
@ -340,7 +340,7 @@ describe PeopleController do
it 'assigns the contacts of a person' do
contact = alice.contact_for(bob.person)
contacts = contact.contacts
get :contacts, :person_id => bob.person.id
get :contacts, :person_id => bob.person.to_param
assigns(:contacts_of_contact).should =~ contacts
response.should be_success
end

View file

@ -189,7 +189,7 @@ describe PhotosController do
it "redirects when the user does not own the photo" do
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
@ -239,7 +239,7 @@ describe PhotosController do
it 'redirects if you do not have access to the post' do
params = { :text => "now with lasers!" }
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

View file

@ -101,7 +101,7 @@ describe("app.helpers.textFormatter", function(){
var wrapper = $("<div>").html(formattedText);
_.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
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
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
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
it 'throws active record not found exceptions if no person is found via id' do
expect{
Person.find_from_id_or_username(:id => 213123)
Person.find_from_guid_or_username(:id => 213123)
}.to raise_error ActiveRecord::RecordNotFound
end
it 'throws active record not found exceptions if no person is found via username' do
expect{
Person.find_from_id_or_username(:username => 'michael_jackson')
Person.find_from_guid_or_username(:username => 'michael_jackson')
}.to raise_error ActiveRecord::RecordNotFound
end
end
@ -463,10 +463,11 @@ describe Person do
it 'returns a hash representation of a person' do
@person.as_json.should == {
:id => @person.id,
:guid => @person.guid,
:name => @person.name,
:avatar => @person.profile.image_url(:thumb_medium),
:handle => @person.diaspora_handle,
:url => "/people/#{@person.id}",
:url => Rails.application.routes.url_helpers.person_path(@person),
}
end
it 'return tags if asked' do