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
|
class PostVisibilitiesController < ApplicationController
|
||||||
before_filter :authenticate_user!
|
before_filter :authenticate_user!
|
||||||
|
|
||||||
def destroy
|
def update
|
||||||
#note :id is garbage
|
#note :id is garbage
|
||||||
|
|
||||||
@post = Post.where(:id => params[:post_id]).select("id, author_id").first
|
@post = Post.where(:id => params[:post_id]).select("id, author_id").first
|
||||||
@contact = current_user.contact_for( @post.author)
|
@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
|
:post_id => params[:post_id]).first
|
||||||
if @vis
|
@vis.hidden = !@vis.hidden
|
||||||
@vis.hidden = true
|
|
||||||
if @vis.save
|
if @vis.save
|
||||||
render :nothing => true, :status => 200
|
render 'update'
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ class StatusMessagesController < ApplicationController
|
||||||
@status_message = current_user.posts.where(:id => params[:id]).first
|
@status_message = current_user.posts.where(:id => params[:id]).first
|
||||||
if @status_message
|
if @status_message
|
||||||
current_user.retract(@status_message)
|
current_user.retract(@status_message)
|
||||||
render :nothing => true, :status => 200
|
render 'destroy'
|
||||||
else
|
else
|
||||||
Rails.logger.info "event=post_destroy status=failure user=#{current_user.diaspora_handle} reason='User does not own post'"
|
Rails.logger.info "event=post_destroy status=failure user=#{current_user.diaspora_handle} reason='User does not own post'"
|
||||||
render :nothing => true, :status => 404
|
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,8 +11,11 @@
|
||||||
= 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')
|
= 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
|
- else
|
||||||
.right.controls
|
.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
|
.content
|
||||||
|
|
|
||||||
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
|
- if current_user.owns? @status_message
|
||||||
= link_to t('delete'), @status_message, :confirm => t('are_you_sure'), :method => :delete
|
= link_to t('delete'), @status_message, :confirm => t('are_you_sure'), :method => :delete
|
||||||
- else
|
- 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}}
|
.stream.show{:data=>{:guid=>@status_message.id}}
|
||||||
= render "comments/comments", :post => @status_message, :comments => @status_message.comments, :always_expanded => true
|
= render "comments/comments", :post => @status_message, :comments => @status_message.comments, :always_expanded => true
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ en:
|
||||||
cancel: "Cancel"
|
cancel: "Cancel"
|
||||||
delete: "Delete"
|
delete: "Delete"
|
||||||
hide: "Hide"
|
hide: "Hide"
|
||||||
|
undo: "Undo?"
|
||||||
or: "or"
|
or: "or"
|
||||||
ago: "%{time} ago"
|
ago: "%{time} ago"
|
||||||
username: "Username"
|
username: "Username"
|
||||||
|
|
@ -433,9 +434,9 @@ en:
|
||||||
posts:
|
posts:
|
||||||
doesnt_exist: "that post does not exist!"
|
doesnt_exist: "that post does not exist!"
|
||||||
|
|
||||||
post_visibility:
|
post_visibilites:
|
||||||
destroy:
|
update:
|
||||||
success: "Post successfully hidden"
|
post_hidden: "%{name}'s post has been hidden."
|
||||||
|
|
||||||
profiles:
|
profiles:
|
||||||
edit:
|
edit:
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ Diaspora::Application.routes.draw do
|
||||||
|
|
||||||
resources :contacts, :except => [:index, :update]
|
resources :contacts, :except => [:index, :update]
|
||||||
resources :aspect_memberships, :only => [:destroy, :create, :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 :people, :except => [:edit, :update] do
|
||||||
resources :status_messages
|
resources :status_messages
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,6 @@ Feature: posting
|
||||||
And I am on "bob@bob.bob"'s page
|
And I am on "bob@bob.bob"'s page
|
||||||
|
|
||||||
And I hover over the post
|
And I hover over the post
|
||||||
And I preemptively confirm the alert
|
|
||||||
And I click to delete the first post
|
And I click to delete the first post
|
||||||
And I wait for the ajax to finish
|
And I wait for the ajax to finish
|
||||||
And I go to "bob@bob.bob"'s page
|
And I go to "bob@bob.bob"'s page
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ And /^I hover over the (\w*)$/ do |element|
|
||||||
end
|
end
|
||||||
|
|
||||||
When /^I click to delete the first post$/ do
|
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
|
end
|
||||||
|
|
||||||
When /^I click to delete the first comment$/ do
|
When /^I click to delete the first comment$/ do
|
||||||
|
|
|
||||||
|
|
@ -300,6 +300,7 @@ var Publisher = {
|
||||||
},
|
},
|
||||||
toggleServiceField: function(service){
|
toggleServiceField: function(service){
|
||||||
Publisher.createCounter(service);
|
Publisher.createCounter(service);
|
||||||
|
|
||||||
var provider = service.attr('id');
|
var provider = service.attr('id');
|
||||||
var hidden_field = $('#publisher [name="services[]"][value="'+provider+'"]')
|
var hidden_field = $('#publisher [name="services[]"][value="'+provider+'"]')
|
||||||
if(hidden_field.length > 0){
|
if(hidden_field.length > 0){
|
||||||
|
|
@ -320,7 +321,7 @@ var Publisher = {
|
||||||
},
|
},
|
||||||
createCounter: function(service){
|
createCounter: function(service){
|
||||||
var counter = $("#publisher .counter");
|
var counter = $("#publisher .counter");
|
||||||
if (counter.length > 0) { counter.remove()};
|
counter.remove();
|
||||||
|
|
||||||
var min = 40000;
|
var min = 40000;
|
||||||
var a = $('.service_icon:not(.dim)');
|
var a = $('.service_icon:not(.dim)');
|
||||||
|
|
|
||||||
|
|
@ -108,11 +108,6 @@ var Stream = {
|
||||||
Diaspora.widgets.alert.alert('Failed to post message!');
|
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) {
|
$(".stream").find(".comment_delete", ".comment").live('ajax:success', function(data, html, xhr) {
|
||||||
var element = $(this),
|
var element = $(this),
|
||||||
target = element.parents(".comment"),
|
target = element.parents(".comment"),
|
||||||
|
|
|
||||||
|
|
@ -22,18 +22,24 @@ describe PostVisibilitiesController do
|
||||||
@vis.reload.hidden.should == false
|
@vis.reload.hidden.should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#destroy' do
|
describe '#update' do
|
||||||
context "on a post you can see" do
|
context "on a post you can see" do
|
||||||
it 'succeeds' 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
|
response.should be_success
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'deletes the visibility' do
|
it 'marks hidden if visible' do
|
||||||
delete :destroy, :id => 42, :post_id => @status.id
|
put :update, :format => :js, :id => 42, :post_id => @status.id
|
||||||
@vis.reload.hidden.should == true
|
@vis.reload.hidden.should == true
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context "post you do not see" do
|
context "post you do not see" do
|
||||||
|
|
@ -43,11 +49,11 @@ describe PostVisibilitiesController do
|
||||||
end
|
end
|
||||||
it 'does not let a user destroy a visibility that is not theirs' do
|
it 'does not let a user destroy a visibility that is not theirs' do
|
||||||
lambda {
|
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)
|
}.should_not change(@vis.reload, :hidden).to(true)
|
||||||
end
|
end
|
||||||
it 'does not succceed' do
|
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
|
response.should_not be_success
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -177,22 +177,22 @@ describe StatusMessagesController do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'let a user delete his message' do
|
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
|
StatusMessage.find_by_id(@message.id).should be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sends a retraction on delete' do
|
it 'sends a retraction on delete' do
|
||||||
alice.should_receive(:retract).with(@message)
|
alice.should_receive(:retract).with(@message)
|
||||||
delete :destroy, :id => @message.id
|
delete :destroy, :format => :js, :id => @message.id
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'will not let you destroy posts visible to you' do
|
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
|
StatusMessage.find_by_id(@message2.id).should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'will not let you destory posts you do not own' do
|
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
|
StatusMessage.find_by_id(@message3.id).should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -50,10 +50,12 @@ describe("Diaspora", function() {
|
||||||
it("has to have a certain DOM structure", function() {
|
it("has to have a certain DOM structure", function() {
|
||||||
spec.loadFixture("aspects_index_with_posts");
|
spec.loadFixture("aspects_index_with_posts");
|
||||||
|
|
||||||
var $post = $("#main_stream").children(".stream_element:first"),
|
var $post = $("#main_stream").children(".stream_element:first");
|
||||||
$contentParagraph = $post.children(".content").children("p"),
|
var $contentParagraph = $post.find(".sm_body .content").children("p");
|
||||||
$infoDiv = $contentParagraph.prev(".from").siblings(".info");
|
console.log($contentParagraph);
|
||||||
|
var $infoDiv = $contentParagraph.prev(".from").siblings(".info");
|
||||||
|
|
||||||
|
console.log($infoDiv);
|
||||||
expect($infoDiv.length).toEqual(1);
|
expect($infoDiv.length).toEqual(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -28,13 +28,13 @@ describe("Publisher", function() {
|
||||||
|
|
||||||
it("gets called in when you toggle service icons", function(){
|
it("gets called in when you toggle service icons", function(){
|
||||||
spyOn(Publisher, 'createCounter');
|
spyOn(Publisher, 'createCounter');
|
||||||
Publisher.toggleServiceField();
|
Publisher.toggleServiceField($(".service_icon").first());
|
||||||
expect(Publisher.createCounter).toHaveBeenCalled();
|
expect(Publisher.createCounter).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("removes the .counter span", function(){
|
it("removes the .counter span", function(){
|
||||||
spyOn($.fn, "remove");
|
spyOn($.fn, "remove");
|
||||||
Publisher.createCounter();
|
Publisher.createCounter($(".service_icon").first());
|
||||||
expect($.fn.remove).toHaveBeenCalled();
|
expect($.fn.remove).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -169,7 +169,7 @@ describe("Publisher", function() {
|
||||||
Publisher.bindServiceIcons();
|
Publisher.bindServiceIcons();
|
||||||
$(".service_icon#facebook").click();
|
$(".service_icon#facebook").click();
|
||||||
|
|
||||||
expect(Publisher.toggleServiceField).toHaveBeenCalledWith($(".service_icon#facebook").first());
|
expect(Publisher.toggleServiceField).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue