From aabbea6ee2675cce7e0fa20b68acea7d3d89a9fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabi=C3=A1n=20Rodr=C3=ADguez?= Date: Thu, 10 Jan 2013 18:49:32 -0200 Subject: [PATCH 1/2] fix issue #3671 reshare a post multiple times --- .../javascripts/app/models/post/interactions.js | 13 ++++++++++--- app/controllers/reshares_controller.rb | 5 +++-- features/reshare.feature | 1 + spec/controllers/reshares_controller_spec.rb | 15 ++++++++++++++- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/app/models/post/interactions.js b/app/assets/javascripts/app/models/post/interactions.js index 40fd28444..d510ca8b5 100644 --- a/app/assets/javascripts/app/models/post/interactions.js +++ b/app/assets/javascripts/app/models/post/interactions.js @@ -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; } -}); \ No newline at end of file +}); diff --git a/app/controllers/reshares_controller.rb b/app/controllers/reshares_controller.rb index 25ea951f3..5748386e1 100644 --- a/app/controllers/reshares_controller.rb +++ b/app/controllers/reshares_controller.rb @@ -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 diff --git a/features/reshare.feature b/features/reshare.feature index c77cff349..422bc8053 100644 --- a/features/reshare.feature +++ b/features/reshare.feature @@ -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" diff --git a/spec/controllers/reshares_controller_spec.rb b/spec/controllers/reshares_controller_spec.rb index a3414d881..180f9f6e8 100644 --- a/spec/controllers/reshares_controller_spec.rb +++ b/spec/controllers/reshares_controller_spec.rb @@ -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 From af6db5c0433f4c295d0fa1b99210a6d50541273a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabi=C3=A1n=20Rodr=C3=ADguez?= Date: Fri, 11 Jan 2013 20:46:54 -0200 Subject: [PATCH 2/2] update changelog --- Changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.md b/Changelog.md index 80c250a7b..9ef272a70 100644 --- a/Changelog.md +++ b/Changelog.md @@ -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