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(){
|
reshare : function(){
|
||||||
var interactions = this
|
var interactions = this
|
||||||
, reshare = this.post.reshare()
|
, reshare = this.post.reshare()
|
||||||
|
, flash = new Diaspora.Widgets.FlashMessages;
|
||||||
|
|
||||||
reshare.save({}, {
|
reshare.save({}, {
|
||||||
success : function(resp){
|
success : function(resp){
|
||||||
var flash = new Diaspora.Widgets.FlashMessages;
|
|
||||||
flash.render({
|
flash.render({
|
||||||
success: true,
|
success: true,
|
||||||
notice: Diaspora.I18n.t("reshares.successful")
|
notice: Diaspora.I18n.t("reshares.successful")
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
error: function(resp){
|
||||||
|
flash.render({
|
||||||
|
success: false,
|
||||||
|
notice: Diaspora.I18n.t("reshares.duplicate")
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}).done(function(){
|
}).done(function(){
|
||||||
interactions.reshares.add(reshare)
|
interactions.reshares.add(reshare)
|
||||||
|
|
@ -119,7 +125,8 @@ app.models.Post.Interactions = Backbone.Model.extend({
|
||||||
, publicPost = this.post.get("public")
|
, publicPost = this.post.get("public")
|
||||||
, userIsNotAuthor = this.post.get("author").diaspora_id != app.currentUser.get("diaspora_id")
|
, 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)
|
, 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
|
if @reshare.save
|
||||||
current_user.add_to_streams(@reshare, current_user.aspects)
|
current_user.add_to_streams(@reshare, current_user.aspects)
|
||||||
current_user.dispatch_post(@reshare, :url => post_url(@reshare), :additional_subscribers => @reshare.root_author)
|
current_user.dispatch_post(@reshare, :url => post_url(@reshare), :additional_subscribers => @reshare.root_author)
|
||||||
end
|
|
||||||
|
|
||||||
render :json => ExtremePostPresenter.new(@reshare, current_user), :status => 201
|
render :json => ExtremePostPresenter.new(@reshare, current_user), :status => 201
|
||||||
|
else
|
||||||
|
render :nothing => true, :status => 422
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -22,3 +22,4 @@ Feature: public repost
|
||||||
And I wait for the ajax to finish
|
And I wait for the ajax to finish
|
||||||
Then I should see a flash message indicating success
|
Then I should see a flash message indicating success
|
||||||
And I should see a flash message containing "successfully"
|
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
|
before do
|
||||||
@post_guid = FactoryGirl.create(:status_message, :public => true).guid
|
@post = FactoryGirl.create(:status_message, :public => true)
|
||||||
|
@post_guid = @post.guid
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'requires authentication' do
|
it 'requires authentication' do
|
||||||
|
|
@ -41,6 +42,18 @@ describe ResharesController do
|
||||||
bob.should_receive(:dispatch_post).with(anything, hash_including(:additional_subscribers))
|
bob.should_receive(:dispatch_post).with(anything, hash_including(:additional_subscribers))
|
||||||
post_request!
|
post_request!
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue