people#show displays shows public posts for non-contacts as well

This commit is contained in:
danielvincent 2010-12-08 16:53:24 -08:00
parent e4e3a7493c
commit 46793179db
7 changed files with 94 additions and 37 deletions

View file

@ -53,8 +53,9 @@ class PeopleController < ApplicationController
@aspects_with_person = @contact.aspects
end
@posts = current_user.visible_posts(:person_id => @person.id, :_type => "StatusMessage").paginate :page => params[:page], :order => 'created_at DESC'
@posts = current_user.posts_from(@person).paginate :page => params[:page]
@post_hashes = hashes_for_posts @posts
respond_with @person, :locals => {:post_type => :all}
else
@ -132,6 +133,7 @@ class PeopleController < ApplicationController
}
end
end
def webfinger(account, opts = {})
Resque.enqueue(Jobs::SocketWebfinger, current_user.id, account, opts)
end

View file

@ -20,45 +20,49 @@
= render :partial => 'people/profile_sidebar', :locals => {:person => @person, :is_contact => @is_contact}
.span-15.last
- if @contact || current_user.person == @person
- if @posts.count > 0
-if @post_type == :photos
- unless @contact || current_user.person == @person
- if current_user.has_incoming_request_from(@person)
.floating
%h3
= t('.incoming_request')
%h4
= t('_photos')
= render 'photos/index', :photos => @posts
- else
%h4
= t('.recent_posts')
= render 'shared/stream', :posts => @post_hashes
= will_paginate @posts
= link_to t('.return_to_aspects'), aspects_manage_path
= t('.to_accept_or_ignore')
- else
%ul#stream
%li
%h3= t('.no_posts')
.floating
%h3
= t('.not_connected', :name => @person.name)
- unless pending_request_for(@person)
%h3
.description
= t('.request_people')
= render :partial =>'requests/new_request_to_person', :locals => {:aspects => @aspects, :destination_handle => @person.diaspora_handle}
- elsif current_user.has_incoming_request_from(@person)
.floating
%h3
= t('.incoming_request')
- else
%h3
.description
= t('.already_requested', :name => @person.name)
- if @posts.count > 0
-if @post_type == :photos
%h4
= link_to t('.return_to_aspects'), aspects_manage_path
= t('.to_accept_or_ignore')
= t('_photos')
= render 'photos/index', :photos => @posts
- else
%h4
- if @contact
= t('.recent_posts')
- else
= t('.recent_public_posts')
= render 'shared/stream', :posts => @post_hashes
= will_paginate @posts
- else
.floating
%h3
= t('.not_connected', :name => @person.name)
- unless pending_request_for(@person)
%h3
.description
= t('.request_people')
= render :partial =>'requests/new_request_to_person', :locals => {:aspects => @aspects, :destination_handle => @person.diaspora_handle}
- else
%h3
.description
= t('.already_requested', :name => @person.name)
%ul#stream
%li
%h3= t('.no_posts')

View file

@ -317,6 +317,7 @@ en:
does_not_exist: "Person does not exist!"
not_connected: "You are not connected with this person"
recent_posts: "Recent Posts"
recent_public_posts: "Recent Public Posts"
edit:
info_available_to: "This info will be available to whomever you connect with on Diaspora."
your_profile: "Your profile"

View file

@ -96,6 +96,21 @@ module Diaspora
def request_for(to_person)
Request.from(self.person).to(to_person).first
end
def posts_from(person)
post_ids = []
public_post_ids = Post.where(:person_id => person.id, :_type => "StatusMessage", :public => true).fields('id').all
public_post_ids.map!{ |p| p.id }
directed_post_ids = self.visible_posts(:person_id => person.id, :_type => "StatusMessage")
directed_post_ids.map!{ |p| p.id }
post_ids += public_post_ids
post_ids += directed_post_ids
Post.all(:id.in => post_ids, :order => 'created_at desc')
end
end
end
end

View file

@ -1414,6 +1414,8 @@ ul.aspects
.floating
:position relative
:padding 12px
:margin
:bottom 2em
:background
:color rgb(255,255,255)

View file

@ -137,6 +137,14 @@ describe PeopleController do
get :show, :id => user2.person.id
response.should be_success
end
it "renders with public posts of a non-contact" do
user2 = make_user
status_message = user2.post(:status_message, :message => "hey there", :to => 'all', :public => true)
get :show, :id => user2.person.id
response.body.should include status_message.message
end
end
describe '#webfinger' do

View file

@ -229,4 +229,29 @@ describe User do
end
end
describe '#posts_from' do
let!(:user3) {make_user}
let!(:aspect3) {user3.aspects.create(:name => "bros")}
let!(:public_message) {user3.post(:status_message, :message => "hey there", :to => 'all', :public => true)}
let!(:private_message) {user3.post(:status_message, :message => "hey there", :to => aspect3.id)}
it 'displays public posts for a non-contact' do
user.posts_from(user3.person).should include public_message
end
it 'does not display private posts for a non-contact' do
user.posts_from(user3.person).should_not include private_message
end
it 'displays private and public posts for a non-contact after connecting' do
connect_users(user, aspect, user3, aspect3)
new_message = user3.post(:status_message, :message => "hey there", :to => aspect3.id)
user.reload
user.posts_from(user3.person).should include public_message
user.posts_from(user3.person).should include new_message
end
end
end