Do not leak photos in the profile sidebar

This commit is contained in:
Jonne Haß 2013-08-20 20:56:37 +02:00
parent a9e9961761
commit 554d0a93d0
3 changed files with 23 additions and 2 deletions

View file

@ -81,7 +81,8 @@ class PeopleController < ApplicationController
@aspect = :profile @aspect = :profile
@stream = Stream::Person.new(current_user, @person, :max_time => max_time) @stream = Stream::Person.new(current_user, @person, :max_time => max_time)
@profile = @person.profile @profile = @person.profile
@photos = Photo.where(author_id: @profile.id).order('created_at desc') @photos = photos_from(@person)
unless params[:format] == "json" # hovercard unless params[:format] == "json" # hovercard
if current_user if current_user
@block = current_user.blocks.where(:person_id => @person.id).first @block = current_user.blocks.where(:person_id => @person.id).first
@ -189,4 +190,14 @@ class PeopleController < ApplicationController
def remote_profile_with_no_user_session? def remote_profile_with_no_user_session?
@person.try(:remote?) && !user_signed_in? @person.try(:remote?) && !user_signed_in?
end end
def photos_from(person)
photos = if user_signed_in?
current_user.photos_from(person)
else
Photo.where(author_id: person.id, public: true)
end
photos.order('created_at desc')
end
end end

View file

@ -14,7 +14,7 @@ class PhotosController < ApplicationController
def index def index
@post_type = :photos @post_type = :photos
@person = Person.find_by_guid(params[:person_id]) @person = Person.find_by_guid(params[:person_id])
@photos = Photo.where(author_id: @person.id).order('created_at desc')
if @person if @person
@contact = current_user.contact_for(@person) @contact = current_user.contact_for(@person)

View file

@ -190,6 +190,16 @@ describe PeopleController do
response.body.should_not include(profile.first_name) response.body.should_not include(profile.first_name)
end end
it "doesn't leak photos in the sidebar" do
private_photo = @user.post(:photo, user_file: uploaded_photo, to: @aspect.id, public: false)
public_photo = @user.post(:photo, user_file: uploaded_photo, to: @aspect.id, public: true)
sign_out :user
get :show, id: @user.person.to_param
assigns(:photos).should_not include private_photo
assigns(:photos).should include public_photo
end
context "when the person is the current user" do context "when the person is the current user" do
it "succeeds" do it "succeeds" do