Skip to content

Commit 06478f2

Browse files
authored
Merge pull request #1912 from basecamp/refactor-reaction-permission-check
Change reaction admin permission check to be in-line with other controllers
2 parents 6050f18 + 5cfe693 commit 06478f2

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

app/controllers/cards/comments/reactions_controller.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ class Cards::Comments::ReactionsController < ApplicationController
22
include CardScoped
33

44
before_action :set_comment
5+
before_action :set_reaction, only: %i[ destroy ]
6+
before_action :ensure_permision_to_administer_reaction, only: %i[ destroy ]
57

68
def index
79
end
@@ -14,17 +16,19 @@ def create
1416
end
1517

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

2622
private
2723
def set_comment
2824
@comment = @card.comments.find(params[:comment_id])
2925
end
26+
27+
def set_reaction
28+
@reaction = @comment.reactions.find(params[:id])
29+
end
30+
31+
def ensure_permision_to_administer_reaction
32+
head :forbidden if Current.user != @reaction.reacter
33+
end
3034
end

0 commit comments

Comments
 (0)