DG MS; 404 show pages for objects that don't exist for given user

This commit is contained in:
danielvincent 2010-10-11 11:32:20 -07:00
parent c630d3db6f
commit 9162a4a168
7 changed files with 41 additions and 29 deletions

View file

@ -37,8 +37,12 @@ class AlbumsController < ApplicationController
def show def show
@photo = Photo.new @photo = Photo.new
@album = current_user.find_visible_post_by_id( params[:id] ) @album = current_user.find_visible_post_by_id( params[:id] )
@album_photos = @album.photos unless @album
respond_with @album render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
else
@album_photos = @album.photos
respond_with @album
end
end end
def edit def edit

View file

@ -41,10 +41,14 @@ class AspectsController < ApplicationController
end end
def show def show
@aspect = current_user.aspect_by_id params[:id] @aspect = current_user.aspect_by_id params[:id]
@friends = @aspect.people unless @aspect
@posts = current_user.visible_posts( :by_members_of => @aspect ).paginate :per_page => 15, :order => 'created_at DESC' render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
respond_with @aspect 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 end
def public def public

View file

@ -17,26 +17,18 @@ class PeopleController < ApplicationController
end end
def show def show
begin @person = current_user.visible_person_by_id(params[:id])
@person = current_user.visible_person_by_id(params[:id])
rescue BSON::InvalidObjectId
flash[:error] = "Person not found."
redirect_to people_path
return
end
unless @person unless @person
flash[:error] = "Person not found." render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
redirect_to people_path else
return @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 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 end
def destroy def destroy

View file

@ -76,8 +76,12 @@ class PhotosController < ApplicationController
def show def show
@photo = current_user.find_visible_post_by_id params[:id] @photo = current_user.find_visible_post_by_id params[:id]
@album = @photo.album unless @photo
respond_with @photo, @album render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
else
@album = @photo.album
respond_with @photo, @album
end
end end
def edit def edit

View file

@ -33,7 +33,11 @@ class StatusMessagesController < ApplicationController
def show def show
@status_message = current_user.find_visible_post_by_id params[:id] @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 end
private private

View file

@ -7,7 +7,7 @@ module Diaspora
module Querying module Querying
def find_visible_post_by_id( id ) def find_visible_post_by_id( id )
self.raw_visible_posts.find id self.raw_visible_posts.find id.to_id
end end
def visible_posts( opts = {} ) def visible_posts( opts = {} )

View file

@ -4,7 +4,11 @@
class String class String
def to_id def to_id
BSON::ObjectId self begin
BSON::ObjectId self
rescue
nil
end
end end
end end
class BSON::ObjectId class BSON::ObjectId