Make public timeline of a user publicly accessible
This commit is contained in:
parent
c0ce0d71b8
commit
f5a03fd6ed
3 changed files with 68 additions and 58 deletions
|
|
@ -1,5 +1,5 @@
|
|||
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
|
||||
|
||||
#posts
|
||||
|
|
@ -11,13 +11,15 @@ class ApisController < ApplicationController #We should start with this versione
|
|||
end
|
||||
end
|
||||
|
||||
def user_timeline #No public timeline for a user? - R
|
||||
def user_timeline
|
||||
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 => person_id).first
|
||||
if person = Person.where(:guid => params[:user_id]).first
|
||||
if user_signed_in?
|
||||
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|
|
||||
format.json{ render :json => timeline.to_json(:format => :twitter) }
|
||||
end
|
||||
|
|
@ -58,7 +60,7 @@ class ApisController < ApplicationController #We should start with this versione
|
|||
person = Person.where(:diaspora_handle => params[:screen_name]).first
|
||||
end
|
||||
|
||||
if person
|
||||
if person && !person.remote?
|
||||
respond_with person do |format|
|
||||
format.json{ render :json => person.to_json(:format => :twitter) }
|
||||
end
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ Diaspora::Application.routes.draw do
|
|||
match 'receive/users/:guid', :to => 'publics#receive'
|
||||
match 'hub', :to => 'publics#hub'
|
||||
|
||||
scope '/api' do
|
||||
scope '/api/v0' do
|
||||
match '/statuses/public_timeline', :to => 'apis#public_timeline'
|
||||
match '/statuses/home_timeline', :to => 'apis#home_timeline'
|
||||
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_people/:tag', :to => 'apis#tag_people'
|
||||
match '/person/:diaspora_handle', :to => 'apis#people'
|
||||
end
|
||||
|
||||
match'localize', :to => "localize#show"
|
||||
|
|
|
|||
|
|
@ -92,11 +92,20 @@ describe ApisController do
|
|||
end
|
||||
|
||||
describe '#user_timeline' do
|
||||
it 'authenticates' do
|
||||
get :home_timeline, :format => :json
|
||||
response.code.should == '401'
|
||||
context 'unauthenticated' do
|
||||
it 'shows public posts' do
|
||||
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
|
||||
|
||||
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
|
||||
before do
|
||||
@user = bob
|
||||
|
|
@ -120,7 +129,7 @@ describe ApisController do
|
|||
end
|
||||
|
||||
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.length.should == 0
|
||||
end
|
||||
|
|
@ -148,6 +157,7 @@ describe ApisController do
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#users_profile_image' do
|
||||
it 'redirects on success' do
|
||||
|
|
@ -176,12 +186,12 @@ describe ApisController do
|
|||
|
||||
describe '#users' 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['id'].should == @person.guid
|
||||
p['name'].should == @person.name
|
||||
p['screen_name'].should == @person.diaspora_handle
|
||||
p['profile_image_url'].should == @person.profile.image_url(:thumb_small)
|
||||
p['id'].should == alice.person.guid
|
||||
p['name'].should == alice.person.name
|
||||
p['screen_name'].should == alice.person.diaspora_handle
|
||||
p['profile_image_url'].should == alice.person.profile.image_url(:thumb_small)
|
||||
p['created_at'].should_not be_nil
|
||||
end
|
||||
end
|
||||
|
|
@ -210,5 +220,4 @@ describe ApisController do
|
|||
p['id'].should == @person.guid
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue