From 1e281a909e7dab928214b39a990625f32226c94d Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 3 Sep 2014 14:43:07 -0400 Subject: [PATCH] FIX: Prevent duplicate flags after undoing on the server side too. --- app/controllers/post_actions_controller.rb | 3 ++- spec/controllers/post_actions_controller_spec.rb | 8 +++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/controllers/post_actions_controller.rb b/app/controllers/post_actions_controller.rb index cbdb13129ec..24412c239ce 100644 --- a/app/controllers/post_actions_controller.rb +++ b/app/controllers/post_actions_controller.rb @@ -7,7 +7,8 @@ class PostActionsController < ApplicationController before_filter :fetch_post_action_type_id_from_params def create - guardian.ensure_post_can_act!(@post, PostActionType.types[@post_action_type_id]) + taken = PostAction.counts_for([@post], current_user)[@post.id] + guardian.ensure_post_can_act!(@post, PostActionType.types[@post_action_type_id], taken_actions: taken) args = {} args[:message] = params[:message] if params[:message].present? diff --git a/spec/controllers/post_actions_controller_spec.rb b/spec/controllers/post_actions_controller_spec.rb index 71ba8a6939f..4b719d6513a 100644 --- a/spec/controllers/post_actions_controller_spec.rb +++ b/spec/controllers/post_actions_controller_spec.rb @@ -28,7 +28,7 @@ describe PostActionsController do end it "fails when the user doesn't have permission to perform that action" do - Guardian.any_instance.expects(:post_can_act?).with(@post, :like).returns(false) + Guardian.any_instance.expects(:post_can_act?).with(@post, :like, taken_actions: nil).returns(false) xhr :post, :create, id: @post.id, post_action_type_id: PostActionType.types[:like] response.should be_forbidden end @@ -38,6 +38,12 @@ describe PostActionsController do xhr :post, :create, id: @post.id, post_action_type_id: PostActionType.types[:like] end + it "passes a list of taken actions through" do + PostAction.create(post_id: @post.id, user_id: @user.id, post_action_type_id: PostActionType.types[:inappropriate]) + Guardian.any_instance.expects(:post_can_act?).with(@post, :off_topic, has_entry({:taken_actions => has_key(PostActionType.types[:inappropriate])})) + xhr :post, :create, id: @post.id, post_action_type_id: PostActionType.types[:off_topic] + end + it 'passes the message through' do PostAction.expects(:act).once.with(@user, @post, PostActionType.types[:like], {message: 'action message goes here'}) xhr :post, :create, id: @post.id, post_action_type_id: PostActionType.types[:like], message: 'action message goes here'