ms iz, can now undo hiding a post, fixed a bunch of jamine specs
This commit is contained in:
parent
3e008a54d4
commit
f99b724e0b
16 changed files with 76 additions and 65 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
3
app/views/post_visibilities/update.js.erb
Normal file
3
app/views/post_visibilities/update.js.erb
Normal file
|
|
@ -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");
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
2
app/views/status_messages/destroy.js.erb
Normal file
2
app/views/status_messages/destroy.js.erb
Normal file
|
|
@ -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() });
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)');
|
||||
|
|
|
|||
|
|
@ -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"),
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue