diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index a65f4eee921f5e51d9dee8498e5a0c2e9ad98e0a..c0bca6d061501e435b594bfb782fc421eb866e4c 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -3,23 +3,37 @@ # the COPYRIGHT file. class PostsController < ApplicationController - before_filter :authenticate_user! - respond_to :html - respond_to :mobile - respond_to :json + before_filter :authenticate_user!, :except => :show + + respond_to :html, + :mobile, + :json, + :xml + def show - @post = current_user.find_visible_post_by_id params[:id] - if @post + 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 diff --git a/app/controllers/publics_controller.rb b/app/controllers/publics_controller.rb index 4468fd34929eff1e33131808094e9a07cf8c7f11..3a9cc22906c3a65f3a7f47115f2265841fcc7fe4 100644 --- a/app/controllers/publics_controller.rb +++ b/app/controllers/publics_controller.rb @@ -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 diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index 6735a9abd3ef23ae642a3b30ac85f7a76ba58dc9..fbe07f57d804db940daf5fda4cacae9d2828eb25 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -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 diff --git a/app/helpers/people_helper.rb b/app/helpers/people_helper.rb index 41397badaf9bf1bd8f5346732e19945a7918fa55..906bf5d882df627167c86741aa92bf4829152d82 100644 --- a/app/helpers/people_helper.rb +++ b/app/helpers/people_helper.rb @@ -38,7 +38,6 @@ module PeopleHelper "<a href='#{remote_or_hovercard_link}' data-hovercard='#{remote_or_hovercard_link}' class='#{opts[:class]}' >#{h(person.name)}</a>".html_safe end end - def person_image_tag(person, size=nil) size ||= :thumb_small diff --git a/app/views/comments/_comment.html.haml b/app/views/comments/_comment.html.haml index 482c31b3cba1d407daafd4b2b2168e6cc4677f0f..30f49dae5d55ecd8bc26764ad56c3f2b56c500b8 100644 --- a/app/views/comments/_comment.html.haml +++ b/app/views/comments/_comment.html.haml @@ -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) diff --git a/app/views/comments/_comments.haml b/app/views/comments/_comments.haml index 136cebf340d5a0b4c8976d1dd20384cf6f0c19b0..48e88a985f7ebc2d855999e40f76a23e8d1c8dc3 100644 --- a/app/views/comments/_comments.haml +++ b/app/views/comments/_comments.haml @@ -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) diff --git a/app/views/posts/_photo.html.haml b/app/views/posts/_photo.html.haml new file mode 100644 index 0000000000000000000000000000000000000000..e356bb416137aa33658af8e576c2fc231308b310 --- /dev/null +++ b/app/views/posts/_photo.html.haml @@ -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) diff --git a/app/views/posts/show.html.haml b/app/views/posts/show.html.haml index 716a1fd649901167e0b3a9b21f52c4c0a3759d71..717b93f2efc54ccb85481e6cd9c60ecb81782a5c 100644 --- a/app/views/posts/show.html.haml +++ b/app/views/posts/show.html.haml @@ -3,8 +3,12 @@ -# the COPYRIGHT file. .span-20.append-2.prepend-2.last + #main_stream.stream.status_message_show - = render 'shared/stream_element', :post => @post, :commenting_disabled => defined?(@commenting_disabled) + - if @post.is_a?(Photo) + = render 'posts/photo', :post => @post + - else + = render 'shared/stream_element', :post => @post, :commenting_disabled => defined?(@commenting_disabled) %br %br %br diff --git a/app/views/publics/activity_streams/photo.haml b/app/views/publics/activity_streams/photo.haml deleted file mode 100644 index 50c7121f2f2681fc432aab0373250481c0723dda..0000000000000000000000000000000000000000 --- a/app/views/publics/activity_streams/photo.haml +++ /dev/null @@ -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) diff --git a/app/views/publics/photo.haml b/app/views/publics/photo.haml deleted file mode 100644 index b8e2f712335fa150f592cf4ccba5969f58c1a24a..0000000000000000000000000000000000000000 --- a/app/views/publics/photo.haml +++ /dev/null @@ -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) diff --git a/app/views/publics/status_message.haml b/app/views/publics/status_message.haml deleted file mode 100644 index a12003d78194ce04e23ab56cdf3480df4d634758..0000000000000000000000000000000000000000 --- a/app/views/publics/status_message.haml +++ /dev/null @@ -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) diff --git a/app/views/shared/_stream_element.html.haml b/app/views/shared/_stream_element.html.haml index e5751f2eef66be7a2e800bcd2e845fa6da4b8573..a33a26908de3986894ee17acf7a33ef1a1d69bcc 100644 --- a/app/views/shared/_stream_element.html.haml +++ b/app/views/shared/_stream_element.html.haml @@ -3,13 +3,14 @@ -# the COPYRIGHT file. .stream_element{:id => post.guid} - - if current_user && 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') + - 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') - - else - .right.controls - = link_to image_tag('deletelabel.png'), post_visibility_path(:id => "42", :post_id => post.id), :method => :put, :remote => true, :class => "delete stream_element_delete", :title => t('hide') + - else + .right.controls + = link_to image_tag('deletelabel.png'), post_visibility_path(:id => "42", :post_id => post.id), :method => :put, :remote => true, :class => "delete stream_element_delete", :title => t('hide') .undo_text.hidden = t('post_visibilites.update.post_hidden', :name => post.author.name) @@ -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,17 +60,18 @@ = t('.via', :link => link_to("#{post.provider_display_name}", post.actor_url)).html_safe 路 - - unless @commenting_disabled - %span.like_action - = like_action(post, current_user) + - if user_signed_in? + - unless @commenting_disabled + %span.like_action + = like_action(post, current_user) - - if (post.author_id != current_user.person.id) && (post.public?) + - if (post.author_id != current_user.person.id) && (post.public?) + 路 + %span.reshare_action + = reshare_link(post) 路 - %span.reshare_action - = reshare_link(post) - 路 - = link_to t('comments.new_comment.comment'), '#', :class => 'focus_comment_textarea' + = link_to t('comments.new_comment.comment'), '#', :class => 'focus_comment_textarea' .likes.on_post = render "likes/likes_container", :target_id => post.id, :likes_count => post.likes_count, :current_user => current_user, :target_type => "Post" diff --git a/app/views/status_messages/_status_message.haml b/app/views/status_messages/_status_message.haml index 5dcce8a8536bea91ab2a90e883b41742fe6f47e1..133cde0b5f0ce133a884d41dea4aa35c016f9ace 100644 --- a/app/views/status_messages/_status_message.haml +++ b/app/views/status_messages/_status_message.haml @@ -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] diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 976ce02ae5280b96a74a1c834aa04753b8e5febc..453c80f759cbf8ae26c72204a2f41b3d5a6d9800 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -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: diff --git a/config/routes.rb b/config/routes.rb index 70a1fc3ce8d6258f4cb8252843ad69dab72f77c9..49ef87a95a3745d75ccd5fca8b702c28eef349a1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/lib/diaspora/user/querying.rb b/lib/diaspora/user/querying.rb index 71210e0ce92c926cb1fa3a777fe60813641c24ce..7e0f6ef45b5509d3408b97d7eb0034a6050ae1e0 100644 --- a/lib/diaspora/user/querying.rb +++ b/lib/diaspora/user/querying.rb @@ -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 = {}) diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 26cd10827c81d1c03927ee105d4b39d763349f67..ffc8da7b1ad88cb9785a3cffe56dce2b60b5686b 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -3065,9 +3065,6 @@ ul.left_nav :position absolute :left 0 -.big_stream_photo - :display block - #view_all_notifications :float right :margin diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index 928d129a0837251616e5f530e435f89f9eeac460..2efaad4f96966c2c0d8c5c550989ed666ce3bdbc 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -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,43 +15,98 @@ describe PostsController do end describe '#show' do - it 'succeeds' do - get :show, "id" => @message.id.to_s - response.should be_success - end + context 'user signed in' do + before do + sign_in alice + end - it 'succeeds on mobile' do - get :show, "id" => @message.id.to_s, :format => :mobile - response.should be_success - end + it 'succeeds' do + 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 - response.should be_success - end + it 'succeeds on mobile' do + get :show, "id" => @message.id + response.should be_success + end - it 'marks a corresponding notification as read' do - alice.comment("comment after me", :post => @message) - bob.comment("here you go", :post => @message) - note = Notification.where(:recipient_id => alice.id, :target_id => @message.id).first - lambda{ - get :show, :id => @message.id - note.reload - }.should change(note, :unread).from(true).to(false) - end + it 'succeeds on mobile with a reshare' do + get :show, "id" => Factory(:reshare, :author => alice.person).id, :format => :mobile + response.should be_success + end - it 'redirects to back if there is no status message' do - get :show, :id => 2345 - response.status.should == 302 + it 'marks a corresponding notification as read' do + alice.comment("comment after me", :post => @message) + bob.comment("here you go", :post => @message) + note = Notification.where(:recipient_id => alice.id, :target_id => @message.id).first + lambda{ + get :show, :id => @message.id + note.reload + }.should change(note, :unread).from(true).to(false) + 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 - it 'succeeds with a AS/photo' do - photo = Factory(:activity_streams_photo, :author => bob.person) - get :show, :id => photo.id - response.should be_success + 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) diff --git a/spec/controllers/publics_controller_spec.rb b/spec/controllers/publics_controller_spec.rb index 483206ba666435bc09bd69003afd7c4705652573..8783c0fad7df0912a8685a22d4f983f6f80f50ca 100644 --- a/spec/controllers/publics_controller_spec.rb +++ b/spec/controllers/publics_controller_spec.rb @@ -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 diff --git a/spec/models/reshare_spec.rb b/spec/models/reshare_spec.rb index 1839cc363b1de466603e7cd9e7d71b0e7930c847..b9c075ddd6fe346977d144245aaf9e4314a010bb 100644 --- a/spec/models/reshare_spec.rb +++ b/spec/models/reshare_spec.rb @@ -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