merged publics/show and posts/show

This commit is contained in:
danielgrippi 2011-08-10 17:25:10 -07:00
parent 90a5cd2254
commit db645e8da8
20 changed files with 163 additions and 234 deletions

View file

@ -3,23 +3,37 @@
# the COPYRIGHT file.
class PostsController < ApplicationController
before_filter :authenticate_user!
respond_to :html
respond_to :mobile
respond_to :json
def show
@post = current_user.find_visible_post_by_id params[:id]
if @post
before_filter :authenticate_user!, :except => :show
respond_to :html,
:mobile,
:json,
:xml
def show
key = params[:id].to_s.length <= 8 ? :id : :guid
if user_signed_in?
@post = current_user.find_visible_post_by_id(params[:id], :key => key)
else
@post = Post.where(key => params[:id], :public => true).includes(:author, :comments => :author).first
end
if @post
# mark corresponding notification as read
if notification = Notification.where(:recipient_id => current_user.id, :target_id => @post.id).first
if user_signed_in? && notification = Notification.where(:recipient_id => current_user.id, :target_id => @post.id).first
notification.unread = false
notification.save
end
respond_with @post
respond_to do |format|
format.all{ }
format.xml{ render :xml => @post.to_diaspora_xml }
end
else
Rails.logger.info(:event => :link_to_nonexistent_post, :ref => request.env['HTTP_REFERER'], :user_id => current_user.id, :post_id => params[:id])
user_id = (user_signed_in? ? current_user : nil)
Rails.logger.info(:event => :link_to_nonexistent_post, :ref => request.env['HTTP_REFERER'], :user_id => user_id, :post_id => params[:id])
flash[:error] = I18n.t('posts.show.not_found')
redirect_to :back
end

View file

@ -66,37 +66,4 @@ class PublicsController < ApplicationController
render :nothing => true, :status => 202
end
def post
if params[:guid].to_s.length <= 8
@post = Post.where(:id => params[:guid], :public => true).includes(:author, :comments => :author).first
else
@post = Post.where(:guid => params[:guid], :public => true).includes(:author, :comments => :author).first
end
if @post
#hax to upgrade logged in users who can comment
if user_signed_in? && current_user.find_visible_post_by_id(@post.id)
redirect_to post_path(@post)
else
@landing_page = true
@person = @post.author
if @person.owner_id
I18n.locale = @person.owner.language
respond_to do |format|
format.xml{ render :xml => @post.to_diaspora_xml }
format.any{ render "publics/#{@post.class.to_s.underscore}", :layout => 'application'}
end
else
flash[:error] = I18n.t('posts.show.not_found')
redirect_to root_url
end
end
else
flash[:error] = I18n.t('posts.show.not_found')
redirect_to root_url
end
end
end

View file

@ -51,7 +51,7 @@ class StatusMessagesController < ApplicationController
aspects = current_user.aspects_from_ids(params[:aspect_ids])
current_user.add_to_streams(@status_message, aspects)
receiving_services = current_user.services.where( :type => params[:services].map{|s| "Services::"+s.titleize}) if params[:services]
current_user.dispatch_post(@status_message, :url => public_post_path(:guid => @status_message.guid), :services => receiving_services)
current_user.dispatch_post(@status_message, :url => short_post_url(@status_message.guid), :services => receiving_services)
if request.env['HTTP_REFERER'].include?("people") # if this is a post coming from a profile page

View file

@ -39,7 +39,6 @@ module PeopleHelper
end
end
def person_image_tag(person, size=nil)
size ||= :thumb_small
"<img alt=\"#{h(person.name)}\" class=\"avatar\" data-person_id=\"#{person.id}\" src=\"#{person.profile.image_url(size)}\" title=\"#{h(person.name)} (#{h(person.diaspora_handle)})\">".html_safe

View file

@ -23,7 +23,7 @@
.likes
= render "likes/likes_container", :target_id => comment.id, :likes_count => comment.likes_count, :target_type => "Comment"
- unless (defined?(@commenting_disabled) && @commenting_disabled)
- unless !user_signed_in? || @commenting_disabled
%span.like_action
= like_action(comment, current_user)

View file

@ -12,6 +12,6 @@
-else
= render :partial => 'comments/comment', :collection => post.comments, :locals => {:post => post}
- unless @commenting_disabled
- unless !user_signed_in? || @commenting_disabled
.new_comment_form_wrapper{:class => comment_form_wrapper_class(post)}
= new_comment_form(post.id, current_user)

View file

@ -0,0 +1,21 @@
-# Copyright (c) 2010, Diaspora Inc. This file is
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
- content_for :head do
= include_javascripts :photos
#author_info
= person_image_link(post.author)
.from
%h2
= post.author.name
#show_photo{:data=>{:guid=>post.id}}
= image_tag post.url(:scaled_full)
#caption
= post.text
%br
= link_to t('photos.show.show_original_post'), post_path(post.status_message)

View file

@ -3,7 +3,11 @@
-# the COPYRIGHT file.
.span-20.append-2.prepend-2.last
#main_stream.stream.status_message_show
- if @post.is_a?(Photo)
= render 'posts/photo', :post => @post
- else
= render 'shared/stream_element', :post => @post, :commenting_disabled => defined?(@commenting_disabled)
%br
%br

View file

@ -1,17 +0,0 @@
-# Copyright (c) 2010, Diaspora Inc. This file is
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
#author_info
= person_image_link(@person)
.from
%h2
= @person.name
.span-14.append-1.last
#show_text
= link_to image_tag(@post.image_url, 'data-small-photo' => @post.image_url, 'data-full-photo' => @post.image_url, :class => 'stream-photo'), @post.object_url, :class => "stream-photo-link"
.time
= how_long_ago(@post)
= link_to t('posts.show.permalink'), public_post_path(@post)

View file

@ -1,36 +0,0 @@
-# Copyright (c) 2010, Diaspora Inc. This file is
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
- content_for :head do
= include_javascripts :photos
#author_info
= person_image_link(@person)
.from
%h2
= @person.name
.span-14.append-1.last
#show_photo{:data=>{:guid=>@post.id}}
= image_tag @post.url(:scaled_full)
#caption
= @post.text
%br
.span-9.last
- if @post.status_message_guid
#original_post_info
%h4{:style=>"position:relative;"}
= t('photos.show.original_post')
= link_to t('photos.show.view'), public_post_path(@post.status_message)
%p
= @post.status_message.text
%p
- for photo in @post.status_message.photos
.thumb_small= link_to (image_tag photo.url(:thumb_small)), public_post_path(photo)
%p
= link_to t('posts.show.permalink'), public_post_path(@post)

View file

@ -1,21 +0,0 @@
-# Copyright (c) 2010, Diaspora Inc. This file is
-# licensed under the Affero General Public License version 3 or later. See
-# the COPYRIGHT file.
#author_info
= person_image_link(@person)
.from
%h2
= @person.name
.span-14.append-1.last
#show_text
%p
= markdownify(@post.text, :youtube_maps => @post[:youtube_titles])
- for photo in @post.photos
.thumb_small= link_to (image_tag photo.url(:thumb_small)), public_post_path(photo)
.time
= how_long_ago(@post)
= link_to t('posts.show.permalink'), public_post_path(@post)

View file

@ -3,7 +3,8 @@
-# the COPYRIGHT file.
.stream_element{:id => post.guid}
- if current_user && post.author.owner_id == current_user.id
- if user_signed_in?
- if post.author.owner_id == current_user.id
.right.controls
= link_to image_tag('deletelabel.png'), post_path(post), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete stream_element_delete", :title => t('delete')
@ -41,7 +42,7 @@
= t('public')
·
- else
- if post.author.owner_id == current_user.id
- if user_signed_in? && post.author.owner_id == current_user.id
- aspects = aspects_with_post(all_aspects, post)
%span.post_scope{:title => t('.shared_with', :aspect_names => aspects.map!{|a| a.name}.join(', '))}
- if aspects.size == 1
@ -59,6 +60,7 @@
= t('.via', :link => link_to("#{post.provider_display_name}", post.actor_url)).html_safe
·
- if user_signed_in?
- unless @commenting_disabled
%span.like_action
= like_action(post, current_user)

View file

@ -5,7 +5,8 @@
- if photos.size > 0
.photo_attachments
= link_to (image_tag photos.first.url(:scaled_full), :class => "stream-photo", 'data-small-photo' => photos.first.url(:thumb_medium), 'data-full-photo' => photos.first.url), photo_path(photos.first), :class => "stream-photo-link big_stream_photo"
.big_stream_photo
= link_to (image_tag photos.first.url(:scaled_full), :class => "stream-photo", 'data-small-photo' => photos.first.url(:thumb_medium), 'data-full-photo' => photos.first.url), photo_path(photos.first), :class => "stream-photo-link"
- if photos.size > 1
- if photos.size >= 8
- for photo in photos[1..8]

View file

@ -505,11 +505,10 @@ en:
delete_photo: "Delete Photo"
make_profile_photo: "make profile photo"
update_photo: "Update Photo"
view: "view"
edit: "edit"
edit_delete_photo: "Edit photo description / delete photo"
collection_permalink: "collection permalink"
original_post: "Original Post"
show_original_post: "Show original post"
edit:
editing: "Editing"
photo:

View file

@ -18,7 +18,7 @@ Diaspora::Application.routes.draw do
resources :likes, :only => [:create, :destroy, :index]
resources :comments, :only => [:create, :destroy, :index]
end
get 'p/:guid' => 'publics#post', :as => 'public_post'
get 'p/:id' => 'posts#show', :as => 'short_post'
# roll up likes into a nested resource above
resources :comments, :only => [:create, :destroy] do

View file

@ -7,9 +7,10 @@ module Diaspora
module Querying
def find_visible_post_by_id( id, opts={} )
post = Post.where(:id => id).joins(:contacts).where(:contacts => {:user_id => self.id}).where(opts).select("posts.*").first
post ||= Post.where(:id => id, :author_id => self.person.id).where(opts).first
post ||= Post.where(:id => id, :public => true).where(opts).first
key = opts.delete(:key) || :id
post = Post.where(key => id).joins(:contacts).where(:contacts => {:user_id => self.id}).where(opts).select("posts.*").first
post ||= Post.where(key => id, :author_id => self.person.id).where(opts).first
post ||= Post.where(key => id, :public => true).where(opts).first
end
def visible_posts(opts = {})

View file

@ -3065,9 +3065,6 @@ ul.left_nav
:position absolute
:left 0
.big_stream_photo
:display block
#view_all_notifications
:float right
:margin

View file

@ -6,7 +6,6 @@ require 'spec_helper'
describe PostsController do
before do
sign_in alice
aspect = alice.aspects.first
@message = alice.build_post :status_message, :text => "ohai", :to => aspect.id
@message.save!
@ -16,18 +15,23 @@ describe PostsController do
end
describe '#show' do
context 'user signed in' do
before do
sign_in alice
end
it 'succeeds' do
get :show, "id" => @message.id.to_s
get :show, "id" => @message.id
response.should be_success
end
it 'succeeds on mobile' do
get :show, "id" => @message.id.to_s, :format => :mobile
get :show, "id" => @message.id
response.should be_success
end
it 'succeeds on mobile with a reshare' do
get :show, "id" => Factory(:reshare, :author => alice.person), :format => :mobile
get :show, "id" => Factory(:reshare, :author => alice.person).id, :format => :mobile
response.should be_success
end
@ -41,18 +45,68 @@ describe PostsController do
}.should change(note, :unread).from(true).to(false)
end
it 'redirects to back if there is no status message' do
get :show, :id => 2345
response.status.should == 302
end
it 'succeeds with a AS/photo' do
photo = Factory(:activity_streams_photo, :author => bob.person)
get :show, :id => photo.id
response.should be_success
end
end
context 'user not signed in' do
it 'shows a public post' do
status = alice.post(:status_message, :text => "hello", :public => true, :to => 'all')
get :show, :id => status.id
response.status.should == 200
end
it 'shows a public photo' do
pending
status = Factory(:status_message_with_photo, :public => true, :author => alice.person)
photo = status.photos.first
get :show, :id => photo.id
response.status.should == 200
end
it 'does not show a private post' do
status = alice.post(:status_message, :text => "hello", :public => false, :to => 'all')
get :show, :id => status.id
response.status = 302
end
it 'responds with diaspora xml if format is xml' do
status = alice.post(:status_message, :text => "hello", :public => true, :to => 'all')
get :show, :id => status.guid, :format => :xml
response.body.should == status.to_diaspora_xml
end
# We want to be using guids from now on for this post route, but do not want to break
# pre-exisiting permalinks. We can assume a guid is 8 characters long as we have
# guids set to hex(8) since we started using them.
context 'id/guid switch' do
before do
@status = alice.post(:status_message, :text => "hello", :public => true, :to => 'all')
end
it 'assumes guids less than 8 chars are ids and not guids' do
Post.should_receive(:where).with(hash_including(:id => @status.id)).and_return(Post)
get :show, :id => @status.id
response.status= 200
end
it 'assumes guids more than (or equal to) 8 chars are actually guids' do
Post.should_receive(:where).with(hash_including(:guid => @status.guid)).and_return(Post)
get :show, :id => @status.guid
response.status= 200
end
end
end
end
describe '#destroy' do
before do
sign_in alice
end
it 'let a user delete his message' do
message = alice.post(:status_message, :text => "hey", :to => alice.aspects.first.id)

View file

@ -61,62 +61,6 @@ describe PublicsController do
end
end
describe '#post' do
it 'shows a public post' do
status = alice.post(:status_message, :text => "hello", :public => true, :to => 'all')
get :post, :guid => status.id
response.status.should == 200
end
it 'shows a public photo' do
status = Factory(:status_message_with_photo, :public => true, :author => alice.person)
photo = status.photos.first
get :post, :guid => photo.id
response.status.should == 200
end
it 'does not show a private post' do
status = alice.post(:status_message, :text => "hello", :public => false, :to => 'all')
get :post, :guid => status.id
response.status = 302
end
it 'redirects to the proper show page if the user has visibility of the post' do
status = alice.post(:status_message, :text => "hello", :public => true, :to => 'all')
sign_in bob
get :post, :guid => status.id
response.should be_redirect
end
it 'responds with diaspora xml if format is xml' do
status = alice.post(:status_message, :text => "hello", :public => true, :to => 'all')
get :post, :guid => status.guid, :format => :xml
response.body.should == status.to_diaspora_xml
end
# We want to be using guids from now on for this post route, but do not want to break
# preexisiting permalinks. We can assume a guid is 8 characters long as we have
# guids set to hex(8) since we started using them.
context 'id/guid switch' do
before do
@status = alice.post(:status_message, :text => "hello", :public => true, :to => 'all')
end
it 'assumes guids less than 8 chars are ids and not guids' do
Post.should_receive(:where).with(hash_including(:id => @status.id)).and_return(Post)
get :post, :guid => @status.id
response.status= 200
end
it 'assumes guids more than (or equal to) 8 chars are actually guids' do
Post.should_receive(:where).with(hash_including(:guid => @status.guid)).and_return(Post)
get :post, :guid => @status.guid
response.status= 200
end
end
end
describe '#hcard' do
it "succeeds", :fixture => true do
post :hcard, "guid" => @user.person.guid.to_s

View file

@ -100,7 +100,7 @@ describe Reshare do
response = mock
response.stub(:body).and_return(@root_object.to_diaspora_xml)
Faraday.default_connection.should_receive(:get).with(@original_author.url + public_post_path(:guid => @root_object.guid, :format => "xml")).and_return(response)
Faraday.default_connection.should_receive(:get).with(@original_author.url + short_post_path(@root_object.guid, :format => "xml")).and_return(response)
Reshare.from_xml(@xml)
end
@ -108,7 +108,7 @@ describe Reshare do
before do
response = mock
response.stub(:body).and_return(@root_object.to_diaspora_xml)
Faraday.default_connection.stub(:get).with(@reshare.root.author.url + public_post_path(:guid => @root_object.guid, :format => "xml")).and_return(response)
Faraday.default_connection.stub(:get).with(@reshare.root.author.url + short_post_path(@root_object.guid, :format => "xml")).and_return(response)
end
it 'fetches the root post from root_guid' do