diff --git a/app/controllers/post_visibilities_controller.rb b/app/controllers/post_visibilities_controller.rb index 49488f261..302a2b9d3 100644 --- a/app/controllers/post_visibilities_controller.rb +++ b/app/controllers/post_visibilities_controller.rb @@ -6,17 +6,16 @@ class PostVisibilitiesController < ApplicationController before_filter :authenticate_user! - def destroy + def update #note :id is garbage @post = Post.where(:id => params[:post_id]).select("id, author_id").first @contact = current_user.contact_for( @post.author) - @vis = PostVisibility.where(:contact_id => @contact.id, + if @vis = PostVisibility.unscoped.where(:contact_id => @contact.id, :post_id => params[:post_id]).first - if @vis - @vis.hidden = true + @vis.hidden = !@vis.hidden if @vis.save - render :nothing => true, :status => 200 + render 'update' return end end diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index 373aeec9d..3412d22d6 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -89,7 +89,7 @@ class StatusMessagesController < ApplicationController @status_message = current_user.posts.where(:id => params[:id]).first if @status_message current_user.retract(@status_message) - render :nothing => true, :status => 200 + render 'destroy' else Rails.logger.info "event=post_destroy status=failure user=#{current_user.diaspora_handle} reason='User does not own post'" render :nothing => true, :status => 404 diff --git a/app/views/post_visibilities/update.js.erb b/app/views/post_visibilities/update.js.erb new file mode 100644 index 000000000..010c13a6b --- /dev/null +++ b/app/views/post_visibilities/update.js.erb @@ -0,0 +1,3 @@ +var target = $(".stream_element[data-guid=<%= escape_javascript(@post.id.to_s) %>]") +target.find(".sm_body").toggleClass("hidden"); +target.find(".undo_text").toggleClass("hidden"); diff --git a/app/views/shared/_stream_element.html.haml b/app/views/shared/_stream_element.html.haml index 852f6ce72..614e66472 100644 --- a/app/views/shared/_stream_element.html.haml +++ b/app/views/shared/_stream_element.html.haml @@ -11,40 +11,43 @@ = link_to image_tag('deletelabel.png'), status_message_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), :confirm => t('are_you_sure'), :method => :delete, :remote => true, :class => "delete stream_element_delete", :title => t('hide') + = 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) + = link_to t('undo'), post_visibility_path(:id => "42", :post_id => post.id), :method => :put, :remote => true, :class => "delete stream_element_delete" + .sm_body + = person_image_link(post.author, :size => :thumb_small) - = person_image_link(post.author, :size => :thumb_small) + .content + .from + = person_link(post.author, :class => 'author') + %time.timeago{:datetime => post.created_at} + = render 'status_messages/status_message', :post => post, :photos => post.photos - .content - .from - = person_link(post.author, :class => 'author') - %time.timeago{:datetime => post.created_at} - = render 'status_messages/status_message', :post => post, :photos => post.photos + .info + - if post.public? + %span.aspect_badges + %span.aspect_badge.public + = t('the_world') + - elsif post.author.owner_id == current_user.id + %span.aspect_badges + = aspect_badges(aspects_with_post(all_aspects, post), :link => true) - .info - - if post.public? - %span.aspect_badges - %span.aspect_badge.public - = t('the_world') - - elsif post.author.owner_id == current_user.id - %span.aspect_badges - = aspect_badges(aspects_with_post(all_aspects, post), :link => true) + %span.timeago + = link_to(how_long_ago(post), status_message_path(post)) - %span.timeago - = link_to(how_long_ago(post), status_message_path(post)) + - unless (defined?(@commenting_disabled) && @commenting_disabled) + = link_to t('comments.new_comment.comment'), '#', :class => 'focus_comment_textarea' - - unless (defined?(@commenting_disabled) && @commenting_disabled) - = link_to t('comments.new_comment.comment'), '#', :class => 'focus_comment_textarea' + / TODO(likes) + /- if (defined?(current_user) && !current_user.liked?(post)) + / %span.like_links + / | + / = link_to t('.like'), likes_path(:positive => 'true', :post_id => post.id ), :method => :post, :class => "like_it", :remote => true + / | + / = link_to t('.dislike'), likes_path(:positive => 'false', :post_id => post.id), :method => :post, :class => "dislike_it", :remote => true - / TODO(likes) - /- if (defined?(current_user) && !current_user.liked?(post)) - / %span.like_links - / | - / = link_to t('.like'), likes_path(:positive => 'true', :post_id => post.id ), :method => :post, :class => "like_it", :remote => true - / | - / = link_to t('.dislike'), likes_path(:positive => 'false', :post_id => post.id), :method => :post, :class => "dislike_it", :remote => true + /.likes_container + / = render "likes/likes", :post_id => post.id, :likes => post.likes, :dislikes => post.dislikes, :current_user => current_user - /.likes_container - / = render "likes/likes", :post_id => post.id, :likes => post.likes, :dislikes => post.dislikes, :current_user => current_user - - = render "comments/comments", :post => post, :comments => post.comments, :current_user => current_user, :condensed => true, :commenting_disabled => (defined?(@commenting_disabled) && @commenting_disabled) + = render "comments/comments", :post => post, :comments => post.comments, :current_user => current_user, :condensed => true, :commenting_disabled => (defined?(@commenting_disabled) && @commenting_disabled) diff --git a/app/views/status_messages/destroy.js.erb b/app/views/status_messages/destroy.js.erb new file mode 100644 index 000000000..d34c42e25 --- /dev/null +++ b/app/views/status_messages/destroy.js.erb @@ -0,0 +1,2 @@ +var target = $(".stream_element[data-guid=<%= escape_javascript(@status_message.id.to_s) %>]") +target.hide('blind', { direction: 'vertical' }, 300, function(){ target.remove() }); diff --git a/app/views/status_messages/show.mobile.haml b/app/views/status_messages/show.mobile.haml index 6299f7a21..c770f8c72 100644 --- a/app/views/status_messages/show.mobile.haml +++ b/app/views/status_messages/show.mobile.haml @@ -19,7 +19,7 @@ - if current_user.owns? @status_message = link_to t('delete'), @status_message, :confirm => t('are_you_sure'), :method => :delete - else - = link_to t('hide'), post_visibility_path(:id => "42", :post_id => post.id), :confirm => t('are_you_sure'), :method => :delete, :remote => true + = link_to t('hide'), post_visibility_path(:id => "42", :post_id => post.id), :confirm => t('are_you_sure'), :method => :put, :remote => true .stream.show{:data=>{:guid=>@status_message.id}} = render "comments/comments", :post => @status_message, :comments => @status_message.comments, :always_expanded => true diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 08c719ed8..2d4159332 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -15,6 +15,7 @@ en: cancel: "Cancel" delete: "Delete" hide: "Hide" + undo: "Undo?" or: "or" ago: "%{time} ago" username: "Username" @@ -433,9 +434,9 @@ en: posts: doesnt_exist: "that post does not exist!" - post_visibility: - destroy: - success: "Post successfully hidden" + post_visibilites: + update: + post_hidden: "%{name}'s post has been hidden." profiles: edit: diff --git a/config/routes.rb b/config/routes.rb index ad50fafd8..9bc5a254e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -72,7 +72,7 @@ Diaspora::Application.routes.draw do resources :contacts, :except => [:index, :update] resources :aspect_memberships, :only => [:destroy, :create, :update] - resources :post_visibilities, :only => [:destroy] + resources :post_visibilities, :only => [:update] resources :people, :except => [:edit, :update] do resources :status_messages diff --git a/features/posts.feature b/features/posts.feature index 7edc6c13a..24f89bec0 100644 --- a/features/posts.feature +++ b/features/posts.feature @@ -35,7 +35,6 @@ Feature: posting And I am on "bob@bob.bob"'s page And I hover over the post - And I preemptively confirm the alert And I click to delete the first post And I wait for the ajax to finish And I go to "bob@bob.bob"'s page diff --git a/features/step_definitions/custom_web_steps.rb b/features/step_definitions/custom_web_steps.rb index 40640a85e..fa3d1f146 100644 --- a/features/step_definitions/custom_web_steps.rb +++ b/features/step_definitions/custom_web_steps.rb @@ -46,7 +46,7 @@ And /^I hover over the (\w*)$/ do |element| end When /^I click to delete the first post$/ do - page.execute_script('$(".stream_element").first().find(".stream_element_delete").click()') + page.execute_script('$(".stream_element").first().find(".stream_element_delete").first().click()') end When /^I click to delete the first comment$/ do diff --git a/public/javascripts/publisher.js b/public/javascripts/publisher.js index b13270d89..89e215baa 100644 --- a/public/javascripts/publisher.js +++ b/public/javascripts/publisher.js @@ -300,6 +300,7 @@ var Publisher = { }, toggleServiceField: function(service){ Publisher.createCounter(service); + var provider = service.attr('id'); var hidden_field = $('#publisher [name="services[]"][value="'+provider+'"]') if(hidden_field.length > 0){ @@ -320,7 +321,7 @@ var Publisher = { }, createCounter: function(service){ var counter = $("#publisher .counter"); - if (counter.length > 0) { counter.remove()}; + counter.remove(); var min = 40000; var a = $('.service_icon:not(.dim)'); diff --git a/public/javascripts/stream.js b/public/javascripts/stream.js index 7caa92b6a..efe7f2cf7 100644 --- a/public/javascripts/stream.js +++ b/public/javascripts/stream.js @@ -108,11 +108,6 @@ var Stream = { Diaspora.widgets.alert.alert('Failed to post message!'); }); - $(".stream").find(".stream_element_delete", ".stream_element").live('ajax:success', function(data, html, xhr) { - var target = $(this).parents(".stream_element"); - target.hide('blind', { direction: 'vertical' }, 300, function(){ $(this).remove() }); - }); - $(".stream").find(".comment_delete", ".comment").live('ajax:success', function(data, html, xhr) { var element = $(this), target = element.parents(".comment"), diff --git a/spec/controllers/post_visibilities_controller_spec.rb b/spec/controllers/post_visibilities_controller_spec.rb index 83987841a..4c5e5f0e0 100644 --- a/spec/controllers/post_visibilities_controller_spec.rb +++ b/spec/controllers/post_visibilities_controller_spec.rb @@ -22,18 +22,24 @@ describe PostVisibilitiesController do @vis.reload.hidden.should == false end - describe '#destroy' do + describe '#update' do context "on a post you can see" do it 'succeeds' do - delete :destroy, :id => 42, :post_id => @status.id + put :update, :format => :js, :id => 42, :post_id => @status.id response.should be_success end - it 'deletes the visibility' do - delete :destroy, :id => 42, :post_id => @status.id + it 'marks hidden if visible' do + put :update, :format => :js, :id => 42, :post_id => @status.id @vis.reload.hidden.should == true end + it 'marks visible if hidden' do + @vis.hidden = true + @vis.save! + put :update, :format => :js, :id => 42, :post_id => @status.id + @vis.reload.hidden.should == false + end end context "post you do not see" do @@ -43,11 +49,11 @@ describe PostVisibilitiesController do end it 'does not let a user destroy a visibility that is not theirs' do lambda { - delete :destroy, :id => 42, :post_id => @status.id + put :update, :format => :js, :id => 42, :post_id => @status.id }.should_not change(@vis.reload, :hidden).to(true) end it 'does not succceed' do - delete :destroy, :id => 42, :post_id => @status.id + put :update, :format => :js, :id => 42, :post_id => @status.id response.should_not be_success end end diff --git a/spec/controllers/status_messages_controller_spec.rb b/spec/controllers/status_messages_controller_spec.rb index 4ffc7e6a6..66642fb98 100644 --- a/spec/controllers/status_messages_controller_spec.rb +++ b/spec/controllers/status_messages_controller_spec.rb @@ -177,22 +177,22 @@ describe StatusMessagesController do end it 'let a user delete his message' do - delete :destroy, :id => @message.id + delete :destroy, :format => :js, :id => @message.id StatusMessage.find_by_id(@message.id).should be_nil end it 'sends a retraction on delete' do alice.should_receive(:retract).with(@message) - delete :destroy, :id => @message.id + delete :destroy, :format => :js, :id => @message.id end it 'will not let you destroy posts visible to you' do - delete :destroy, :id => @message2.id + delete :destroy, :format => :js, :id => @message2.id StatusMessage.find_by_id(@message2.id).should be_true end it 'will not let you destory posts you do not own' do - delete :destroy, :id => @message3.id + delete :destroy, :format => :js, :id => @message3.id StatusMessage.find_by_id(@message3.id).should be_true end end diff --git a/spec/javascripts/embedder-spec.js b/spec/javascripts/embedder-spec.js index 14c519607..f6567c9d2 100644 --- a/spec/javascripts/embedder-spec.js +++ b/spec/javascripts/embedder-spec.js @@ -50,10 +50,12 @@ describe("Diaspora", function() { it("has to have a certain DOM structure", function() { spec.loadFixture("aspects_index_with_posts"); - var $post = $("#main_stream").children(".stream_element:first"), - $contentParagraph = $post.children(".content").children("p"), - $infoDiv = $contentParagraph.prev(".from").siblings(".info"); + var $post = $("#main_stream").children(".stream_element:first"); + var $contentParagraph = $post.find(".sm_body .content").children("p"); + console.log($contentParagraph); + var $infoDiv = $contentParagraph.prev(".from").siblings(".info"); + console.log($infoDiv); expect($infoDiv.length).toEqual(1); }); }); diff --git a/spec/javascripts/publisher-spec.js b/spec/javascripts/publisher-spec.js index de71388b3..d03c98544 100644 --- a/spec/javascripts/publisher-spec.js +++ b/spec/javascripts/publisher-spec.js @@ -28,13 +28,13 @@ describe("Publisher", function() { it("gets called in when you toggle service icons", function(){ spyOn(Publisher, 'createCounter'); - Publisher.toggleServiceField(); + Publisher.toggleServiceField($(".service_icon").first()); expect(Publisher.createCounter).toHaveBeenCalled(); }); it("removes the .counter span", function(){ spyOn($.fn, "remove"); - Publisher.createCounter(); + Publisher.createCounter($(".service_icon").first()); expect($.fn.remove).toHaveBeenCalled(); }); }); @@ -169,7 +169,7 @@ describe("Publisher", function() { Publisher.bindServiceIcons(); $(".service_icon#facebook").click(); - expect(Publisher.toggleServiceField).toHaveBeenCalledWith($(".service_icon#facebook").first()); + expect(Publisher.toggleServiceField).toHaveBeenCalled(); }); });