diff --git a/app/controllers/albums_controller.rb b/app/controllers/albums_controller.rb index a7ce4b5e3..f5a43360c 100644 --- a/app/controllers/albums_controller.rb +++ b/app/controllers/albums_controller.rb @@ -37,8 +37,12 @@ class AlbumsController < ApplicationController def show @photo = Photo.new @album = current_user.find_visible_post_by_id( params[:id] ) - @album_photos = @album.photos - respond_with @album + unless @album + render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404 + else + @album_photos = @album.photos + respond_with @album + end end def edit diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index cc6aeaa6c..484cab55e 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -41,10 +41,14 @@ class AspectsController < ApplicationController end def show - @aspect = current_user.aspect_by_id params[:id] - @friends = @aspect.people - @posts = current_user.visible_posts( :by_members_of => @aspect ).paginate :per_page => 15, :order => 'created_at DESC' - respond_with @aspect + @aspect = current_user.aspect_by_id params[:id] + unless @aspect + render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404 + else + @friends = @aspect.people + @posts = current_user.visible_posts( :by_members_of => @aspect ).paginate :per_page => 15, :order => 'created_at DESC' + respond_with @aspect + end end def public diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 1e5ef5c23..746877498 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -17,26 +17,18 @@ class PeopleController < ApplicationController end def show - begin - @person = current_user.visible_person_by_id(params[:id]) - rescue BSON::InvalidObjectId - flash[:error] = "Person not found." - redirect_to people_path - return - end + @person = current_user.visible_person_by_id(params[:id]) unless @person - flash[:error] = "Person not found." - redirect_to people_path - return + render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404 + else + @profile = @person.profile + @aspects_with_person = current_user.aspects_with_person(@person) + @aspects_dropdown_array = current_user.aspects.collect{|x| [x.to_s, x.id]} + @posts = current_user.visible_posts(:person_id => @person.id).paginate :page => params[:page], :order => 'created_at DESC' + @latest_status_message = current_user.raw_visible_posts.find_all_by__type_and_person_id("StatusMessage", params[:id]).last + @post_count = @posts.count + respond_with @person end - - @profile = @person.profile - @aspects_with_person = current_user.aspects_with_person(@person) - @aspects_dropdown_array = current_user.aspects.collect{|x| [x.to_s, x.id]} - @posts = current_user.visible_posts(:person_id => @person.id).paginate :page => params[:page], :order => 'created_at DESC' - @latest_status_message = current_user.raw_visible_posts.find_all_by__type_and_person_id("StatusMessage", params[:id]).last - @post_count = @posts.count - respond_with @person end def destroy diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index a1ef260b1..a3a815f69 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -76,8 +76,12 @@ class PhotosController < ApplicationController def show @photo = current_user.find_visible_post_by_id params[:id] - @album = @photo.album - respond_with @photo, @album + unless @photo + render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404 + else + @album = @photo.album + respond_with @photo, @album + end end def edit diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index 58b86c051..205156a89 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -33,7 +33,11 @@ class StatusMessagesController < ApplicationController def show @status_message = current_user.find_visible_post_by_id params[:id] - respond_with @status_message + unless @status_message + render :status => 404 + else + respond_with @status_message + end end private diff --git a/lib/diaspora/user/querying.rb b/lib/diaspora/user/querying.rb index 9b08bd9b8..c0f192fed 100644 --- a/lib/diaspora/user/querying.rb +++ b/lib/diaspora/user/querying.rb @@ -7,7 +7,7 @@ module Diaspora module Querying def find_visible_post_by_id( id ) - self.raw_visible_posts.find id + self.raw_visible_posts.find id.to_id end def visible_posts( opts = {} ) diff --git a/lib/mongo_mapper/bson_id.rb b/lib/mongo_mapper/bson_id.rb index f1e0e9985..e3425715f 100644 --- a/lib/mongo_mapper/bson_id.rb +++ b/lib/mongo_mapper/bson_id.rb @@ -4,7 +4,11 @@ class String def to_id - BSON::ObjectId self + begin + BSON::ObjectId self + rescue + nil + end end end class BSON::ObjectId