From 7aaaf4f43bcb3d0bc4f03613fe2abfcf0c8aad23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonne=20Ha=C3=9F?= Date: Mon, 23 Jan 2012 23:35:31 +0100 Subject: [PATCH] use guid instead of id for /people/ urls --- app/controllers/people_controller.rb | 6 ++-- app/controllers/users_controller.rb | 2 +- app/helpers/people_helper.rb | 2 +- app/models/person.rb | 14 +++++--- app/views/templates/comment.handlebars | 4 +-- app/views/templates/comment_stream.jst | 2 +- app/views/templates/header.handlebars | 2 +- app/views/templates/likes_info.jst | 2 +- app/views/templates/reshare.jst | 4 +-- app/views/templates/stream_element.jst | 4 +-- app/views/templates/stream_faces.handlebars | 2 +- app/views/tokens/show.html.haml | 2 +- db/schema.rb | 6 ++-- .../javascripts/app/helpers/text_formatter.js | 2 +- spec/controllers/people_controller_spec.rb | 36 +++++++++---------- spec/controllers/photos_controller_spec.rb | 4 +-- .../app/helpers/text_formatter_spec.js | 2 +- spec/models/person_spec.rb | 13 +++---- 18 files changed, 58 insertions(+), 51 deletions(-) diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 0857378d1..0c88f0ef5 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 72c1ccbd7..75f3a9581 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 c47a8f2c0..5a9d5be46 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 " {: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 5e7b48877..48d832b01 100644 --- a/app/views/templates/comment.handlebars +++ b/app/views/templates/comment.handlebars @@ -7,13 +7,13 @@ {{/if}} - +
- + {{author.name}} diff --git a/app/views/templates/comment_stream.jst b/app/views/templates/comment_stream.jst index c47efedef..7a413e212 100644 --- a/app/views/templates/comment_stream.jst +++ b/app/views/templates/comment_stream.jst @@ -13,7 +13,7 @@ <% if(current_user) { %>
- + diff --git a/app/views/templates/header.handlebars b/app/views/templates/header.handlebars index d5edfaade..105a5e89b 100644 --- a/app/views/templates/header.handlebars +++ b/app/views/templates/header.handlebars @@ -84,7 +84,7 @@ {{current_user.name}} {{current_user.name}} -
  • {{t "header.profile"}}
  • +
  • {{t "header.profile"}}
  • {{t "header.contacts"}}
  • {{t "header.settings"}}
  • {{#if current_user.admin}} diff --git a/app/views/templates/likes_info.jst b/app/views/templates/likes_info.jst index 6758e5ffc..84cb5d4fe 100644 --- a/app/views/templates/likes_info.jst +++ b/app/views/templates/likes_info.jst @@ -7,7 +7,7 @@ <% } else { %>