fix issue #3671 reshare a post multiple times
This commit is contained in:
parent
4793ee5d5a
commit
aabbea6ee2
4 changed files with 28 additions and 6 deletions
|
|
@ -95,14 +95,20 @@ app.models.Post.Interactions = Backbone.Model.extend({
|
|||
reshare : function(){
|
||||
var interactions = this
|
||||
, reshare = this.post.reshare()
|
||||
, flash = new Diaspora.Widgets.FlashMessages;
|
||||
|
||||
reshare.save({}, {
|
||||
success : function(resp){
|
||||
var flash = new Diaspora.Widgets.FlashMessages;
|
||||
flash.render({
|
||||
success: true,
|
||||
notice: Diaspora.I18n.t("reshares.successful")
|
||||
});
|
||||
},
|
||||
error: function(resp){
|
||||
flash.render({
|
||||
success: false,
|
||||
notice: Diaspora.I18n.t("reshares.duplicate")
|
||||
});
|
||||
}
|
||||
}).done(function(){
|
||||
interactions.reshares.add(reshare)
|
||||
|
|
@ -119,7 +125,8 @@ app.models.Post.Interactions = Backbone.Model.extend({
|
|||
, publicPost = this.post.get("public")
|
||||
, userIsNotAuthor = this.post.get("author").diaspora_id != app.currentUser.get("diaspora_id")
|
||||
, userIsNotRootAuthor = rootExists && (isReshare ? this.post.get("root").author.diaspora_id != app.currentUser.get("diaspora_id") : true)
|
||||
, notReshared = this.reshares.length === 0;
|
||||
|
||||
return publicPost && app.currentUser.authenticated() && userIsNotAuthor && userIsNotRootAuthor;
|
||||
return publicPost && app.currentUser.authenticated() && userIsNotAuthor && userIsNotRootAuthor && notReshared;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -7,8 +7,9 @@ class ResharesController < ApplicationController
|
|||
if @reshare.save
|
||||
current_user.add_to_streams(@reshare, current_user.aspects)
|
||||
current_user.dispatch_post(@reshare, :url => post_url(@reshare), :additional_subscribers => @reshare.root_author)
|
||||
render :json => ExtremePostPresenter.new(@reshare, current_user), :status => 201
|
||||
else
|
||||
render :nothing => true, :status => 422
|
||||
end
|
||||
|
||||
render :json => ExtremePostPresenter.new(@reshare, current_user), :status => 201
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -22,3 +22,4 @@ Feature: public repost
|
|||
And I wait for the ajax to finish
|
||||
Then I should see a flash message indicating success
|
||||
And I should see a flash message containing "successfully"
|
||||
And I should not see a ".reshare" within ".feedback"
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ describe ResharesController do
|
|||
}
|
||||
|
||||
before do
|
||||
@post_guid = FactoryGirl.create(:status_message, :public => true).guid
|
||||
@post = FactoryGirl.create(:status_message, :public => true)
|
||||
@post_guid = @post.guid
|
||||
end
|
||||
|
||||
it 'requires authentication' do
|
||||
|
|
@ -41,6 +42,18 @@ describe ResharesController do
|
|||
bob.should_receive(:dispatch_post).with(anything, hash_including(:additional_subscribers))
|
||||
post_request!
|
||||
end
|
||||
|
||||
context 'resharing a reshared post' do
|
||||
before do
|
||||
FactoryGirl.create(:reshare, :root => @post, :author => bob.person)
|
||||
end
|
||||
|
||||
it 'doesn\'t allow the user to reshare the post again' do
|
||||
post_request!
|
||||
response.code.should == '422'
|
||||
response.body.strip.should be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue