From 8ab9f30bbdc35e8830a86df54286ef075c9703a5 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Fri, 19 May 2017 12:24:49 +0800 Subject: [PATCH] FIX: User can't remove bookmark from a deleted post. --- app/controllers/posts_controller.rb | 4 +++- spec/controllers/posts_controller_spec.rb | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 6ed83c91ebb..5f74ecd57b7 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -383,9 +383,11 @@ class PostsController < ApplicationController PostAction.act(current_user, post, PostActionType.types[:bookmark]) else post_action = PostAction.find_by(post_id: params[:post_id], user_id: current_user.id) - post = post_action&.post raise Discourse::NotFound unless post_action + post = Post.with_deleted.find_by(id: post_action&.post_id) + raise Discourse::NotFound unless post + PostAction.remove_act(current_user, post, PostActionType.types[:bookmark]) end diff --git a/spec/controllers/posts_controller_spec.rb b/spec/controllers/posts_controller_spec.rb index ccee8bf1e2d..6efb7380a3d 100644 --- a/spec/controllers/posts_controller_spec.rb +++ b/spec/controllers/posts_controller_spec.rb @@ -476,6 +476,17 @@ describe PostsController do expect(PostAction.find_by(id: post_action.id)).to eq(nil) end end + + describe "when post has been deleted" do + it "should still be able to remove a bookmark" do + post = post_action.post + post.trash! + + xhr :put, :bookmark, post_id: post.id + + expect(PostAction.find_by(id: post_action.id)).to eq(nil) + end + end end end