Merge pull request #3831 from marpo60/fix-reshare
Remove the 'Reshare' link on posts if the user has already reshared the post, and displays an error in case a user tries to reshare a post they have already reshared.
This commit is contained in:
commit
abce12f274
5 changed files with 29 additions and 6 deletions
|
|
@ -37,6 +37,7 @@
|
|||
* Allow translation of "suggest member" of Community Spotlight. [#3791](https://github.com/diaspora/diaspora/issues/3791)
|
||||
* Resize deletelabel and ignoreuser images to align them [#3779](https://github.com/diaspora/diaspora/issues/3779)
|
||||
* Patch in Armenian pluralization rule until CLDR provides it.
|
||||
* Fix reshare a post multiple times[#3831](https://github.com/diaspora/diaspora/issues/3671)
|
||||
|
||||
## Gem Updates
|
||||
|
||||
|
|
|
|||
|
|
@ -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