diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 0857378d12bf1a74e946a8e75a73e564c6d9d7ca..0c88f0ef576491a55bd16d2db3db7498cf5da4e8 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -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 diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 72c1ccbd722d76fc9f767e754ed3d623a6c8fdc2..75f3a9581d584fd81a0d205924b25f0e3afa2e64 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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]) diff --git a/app/helpers/people_helper.rb b/app/helpers/people_helper.rb index c47a8f2c09e590702c990301d3be620c771c198a..5a9d5be464c71fa959c69ba7387906559d271dc4 100644 --- a/app/helpers/people_helper.rb +++ b/app/helpers/people_helper.rb @@ -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 diff --git a/app/models/person.rb b/app/models/person.rb index 55fd3fa172b4bffccd3579eb6af936a71618ace1..0fce8ebe129cd6a7fb8e4670381d5193982d4247 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -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 diff --git a/app/views/templates/comment.handlebars b/app/views/templates/comment.handlebars index 5e7b48877705f7cb7e3621904650104147a277cc..48d832b0140a2a22a6c6b23acacb851efbb01062 100644 --- a/app/views/templates/comment.handlebars +++ b/app/views/templates/comment.handlebars @@ -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> diff --git a/app/views/templates/comment_stream.jst b/app/views/templates/comment_stream.jst index c47efedefec524f7eb6a959f8016f99b2d7d14c1..7a413e2125117d34a3fe7ed8207d8b62ad0a193a 100644 --- a/app/views/templates/comment_stream.jst +++ b/app/views/templates/comment_stream.jst @@ -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> diff --git a/app/views/templates/header.handlebars b/app/views/templates/header.handlebars index d5edfaadecdc6f32052c70656fb09c6445abc5ab..105a5e89bdf07e52fe424f4af12f619f267fe93b 100644 --- a/app/views/templates/header.handlebars +++ b/app/views/templates/header.handlebars @@ -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}} diff --git a/app/views/templates/likes_info.jst b/app/views/templates/likes_info.jst index 6758e5ffcf72459c81f3aca7721cf93fc5608148..84cb5d4fe77fdc3ab3b2f4034633c085149cbc67 100644 --- a/app/views/templates/likes_info.jst +++ b/app/views/templates/likes_info.jst @@ -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> <% }) %> diff --git a/app/views/templates/reshare.jst b/app/views/templates/reshare.jst index 06fa7b3a70d476454ea790c6402275e4f34c5349..fbf63432cc66a73008212c79917403d7769af666 100644 --- a/app/views/templates/reshare.jst +++ b/app/views/templates/reshare.jst @@ -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> diff --git a/app/views/templates/stream_element.jst b/app/views/templates/stream_element.jst index dd2963b49ecf33f6c0bf91d8d4c3acb8eaebc52c..bbea574ef89a83dc988fd9b175e441846412ea00 100644 --- a/app/views/templates/stream_element.jst +++ b/app/views/templates/stream_element.jst @@ -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> diff --git a/app/views/templates/stream_faces.handlebars b/app/views/templates/stream_faces.handlebars index 981fb390a69b855aa469fc0e40dffad3b7ba0423..779ac70962ddf5d629887690c9b7f43af2cacb1e 100644 --- a/app/views/templates/stream_faces.handlebars +++ b/app/views/templates/stream_faces.handlebars @@ -1,5 +1,5 @@ {{#people}} - <a href="/people/{{id}}"> + <a href="/people/{{guid}}"> <img class="avatar" src="{{avatar.small}}" title="{{name}}"/> </a> {{/people}} diff --git a/app/views/tokens/show.html.haml b/app/views/tokens/show.html.haml index 380004f480261e85b21bb2e4ddc47bac4a3bc9b0..bd87e27c537ab41f058685c971887611aae5bad0 100644 --- a/app/views/tokens/show.html.haml +++ b/app/views/tokens/show.html.haml @@ -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 diff --git a/public/javascripts/app/helpers/text_formatter.js b/public/javascripts/app/helpers/text_formatter.js index c8dc9fafbf5cd0b42a782daf62e5a8114068a547..d977414f31deb957aa4db34380cd1d6986e723b4 100644 --- a/public/javascripts/app/helpers/text_formatter.js +++ b/public/javascripts/app/helpers/text_formatter.js @@ -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; }) } diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb index 9feed1c14d46e6bbd4176d7e668b09a244290bf5..4e2502dc65734a1aaac906ccde253d5306a6855e 100644 --- a/spec/controllers/people_controller_spec.rb +++ b/spec/controllers/people_controller_spec.rb @@ -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 diff --git a/spec/controllers/photos_controller_spec.rb b/spec/controllers/photos_controller_spec.rb index a025702cf18054fcd80a3837e29b8909a8362e30..f2d90e5f6a875f2e32bc293e36839442dae16dc2 100644 --- a/spec/controllers/photos_controller_spec.rb +++ b/spec/controllers/photos_controller_spec.rb @@ -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 diff --git a/spec/javascripts/app/helpers/text_formatter_spec.js b/spec/javascripts/app/helpers/text_formatter_spec.js index 75882880c0bbd8cda139a7f95648fd9327e194c7..6d408c130b48301208127ff16c1d8a3914c94d91 100644 --- a/spec/javascripts/app/helpers/text_formatter_spec.js +++ b/spec/javascripts/app/helpers/text_formatter_spec.js @@ -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) }) }); diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index 1ebe394d4ef2ae3dd526b39f634695d045f6fbf7..00d905a8e24a935317b690f1a7cba92c2e27999d 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -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