Skip to content

Commit 7a0290a

Browse files
authored
Merge pull request #1841 from basecamp/fix-access-control-issues
Allow only the owner of a reaction to delete it
2 parents cb7b106 + 77f1110 commit 7a0290a

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

app/controllers/cards/comments/reactions_controller.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ def create
1515

1616
def destroy
1717
@reaction = @comment.reactions.find(params[:id])
18-
@reaction.destroy
18+
19+
if Current.user != @reaction.reacter
20+
head :forbidden
21+
else
22+
@reaction.destroy
23+
end
1924
end
2025

2126
private

test/controllers/cards/comments/reactions_controller_test.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
class Cards::Comments::ReactionsControllerTest < ActionDispatch::IntegrationTest
44
setup do
5-
sign_in_as :jz
5+
sign_in_as :david
66
@comment = comments(:logo_agreement_jz)
77
@card = @comment.card
88
end
@@ -15,10 +15,19 @@ class Cards::Comments::ReactionsControllerTest < ActionDispatch::IntegrationTest
1515
end
1616

1717
test "destroy" do
18-
reaction = reactions(:kevin)
18+
reaction = reactions(:david)
1919
assert_difference -> { @comment.reactions.count }, -1 do
2020
delete card_comment_reaction_path(@comment.card, @comment, reaction, format: :turbo_stream)
2121
assert_turbo_stream action: :remove, target: dom_id(reaction)
2222
end
2323
end
24+
25+
test "non-owner cannot destroy reaction" do
26+
reaction = reactions(:kevin)
27+
28+
assert_no_difference -> { @comment.reactions.count } do
29+
delete card_comment_reaction_path(@comment.card, @comment, reaction, format: :turbo_stream)
30+
assert_response :forbidden
31+
end
32+
end
2433
end

0 commit comments

Comments
 (0)