Make public timeline of a user publicly accessible

This commit is contained in:
danielgrippi 2011-03-25 14:52:30 -07:00
parent c0ce0d71b8
commit f5a03fd6ed
3 changed files with 68 additions and 58 deletions

View file

@ -1,5 +1,5 @@
class ApisController < ApplicationController #We should start with this versioned, V0ApisController BEES class ApisController < ApplicationController #We should start with this versioned, V0ApisController BEES
before_filter :authenticate_user!, :only => [:home_timeline, :user_timeline] before_filter :authenticate_user!, :only => [:home_timeline]
respond_to :json respond_to :json
#posts #posts
@ -11,13 +11,15 @@ class ApisController < ApplicationController #We should start with this versione
end end
end end
def user_timeline #No public timeline for a user? - R def user_timeline
set_defaults set_defaults
person_id = params[:user_id] || current_user.person.guid # I wouldn't put implicit params in anything meant to be programatically accessed - R if person = Person.where(:guid => params[:user_id]).first
if user_signed_in?
if person = Person.where(:guid => person_id).first
timeline = current_user.posts_from(person) timeline = current_user.posts_from(person)
else
timeline = StatusMessage.where(:public => true, :author_id => person.id).includes(:photos).paginate(:page => params[:page], :per_page => params[:per_page], :order => "#{params[:order]} DESC")
end
respond_with timeline do |format| respond_with timeline do |format|
format.json{ render :json => timeline.to_json(:format => :twitter) } format.json{ render :json => timeline.to_json(:format => :twitter) }
end end
@ -58,7 +60,7 @@ class ApisController < ApplicationController #We should start with this versione
person = Person.where(:diaspora_handle => params[:screen_name]).first person = Person.where(:diaspora_handle => params[:screen_name]).first
end end
if person if person && !person.remote?
respond_with person do |format| respond_with person do |format|
format.json{ render :json => person.to_json(:format => :twitter) } format.json{ render :json => person.to_json(:format => :twitter) }
end end

View file

@ -82,7 +82,7 @@ Diaspora::Application.routes.draw do
match 'receive/users/:guid', :to => 'publics#receive' match 'receive/users/:guid', :to => 'publics#receive'
match 'hub', :to => 'publics#hub' match 'hub', :to => 'publics#hub'
scope '/api' do scope '/api/v0' do
match '/statuses/public_timeline', :to => 'apis#public_timeline' match '/statuses/public_timeline', :to => 'apis#public_timeline'
match '/statuses/home_timeline', :to => 'apis#home_timeline' match '/statuses/home_timeline', :to => 'apis#home_timeline'
match '/statuses/show/:guid', :to => 'apis#statuses' match '/statuses/show/:guid', :to => 'apis#statuses'
@ -94,7 +94,6 @@ Diaspora::Application.routes.draw do
match '/tags_posts/:tag', :to => 'apis#tag_posts' match '/tags_posts/:tag', :to => 'apis#tag_posts'
match '/tags_people/:tag', :to => 'apis#tag_people' match '/tags_people/:tag', :to => 'apis#tag_people'
match '/person/:diaspora_handle', :to => 'apis#people'
end end
match'localize', :to => "localize#show" match'localize', :to => "localize#show"

View file

@ -92,11 +92,20 @@ describe ApisController do
end end
describe '#user_timeline' do describe '#user_timeline' do
it 'authenticates' do context 'unauthenticated' do
get :home_timeline, :format => :json it 'shows public posts' do
response.code.should == '401' get :user_timeline, :format => :json, :user_id => @status_message1.author.guid
posts = JSON.parse(response.body)
posts.first['id'].should == @status_message1.guid
posts.length.should == 1
end end
it 'does not show non-public posts' do
get :user_timeline, :format => :json, :user_id => alice.person.guid
posts = JSON.parse(response.body)
posts.should be_empty
end
end
context 'authenticated' do
context 'with bob logged in' do context 'with bob logged in' do
before do before do
@user = bob @user = bob
@ -120,7 +129,7 @@ describe ApisController do
end end
it 'shows bob' do it 'shows bob' do
get :user_timeline, :format => :json get :user_timeline, :format => :json, :user_id => bob.person.guid
p = JSON.parse(response.body) p = JSON.parse(response.body)
p.length.should == 0 p.length.should == 0
end end
@ -148,6 +157,7 @@ describe ApisController do
end end
end end
end end
end
describe '#users_profile_image' do describe '#users_profile_image' do
it 'redirects on success' do it 'redirects on success' do
@ -176,12 +186,12 @@ describe ApisController do
describe '#users' do describe '#users' do
it 'succeeds' do it 'succeeds' do
get :users, :user_id => @person.guid, :format => :json get :users, :user_id => alice.person.guid, :format => :json
p = JSON.parse(response.body) p = JSON.parse(response.body)
p['id'].should == @person.guid p['id'].should == alice.person.guid
p['name'].should == @person.name p['name'].should == alice.person.name
p['screen_name'].should == @person.diaspora_handle p['screen_name'].should == alice.person.diaspora_handle
p['profile_image_url'].should == @person.profile.image_url(:thumb_small) p['profile_image_url'].should == alice.person.profile.image_url(:thumb_small)
p['created_at'].should_not be_nil p['created_at'].should_not be_nil
end end
end end
@ -210,5 +220,4 @@ describe ApisController do
p['id'].should == @person.guid p['id'].should == @person.guid
end end
end end
end end