Skip to content

Commit

Permalink
Authorize comment #create api endpoint
Browse files Browse the repository at this point in the history
Currently there is not authorization going on, in some cases
the `CommentLockingValidator` still prevents comments from being
created if permission is unsufficient in certain cases.
But some things are not handled, for example when a user is
blocked for commenting.

This should be handled on the controller level using our pundit
policy.
  • Loading branch information
krauselukas committed Feb 21, 2024
1 parent f1ae0ec commit 26bcb38
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/api/app/controllers/comments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ def index
end

def create
@obj.comments.create!(body: request.raw_post, user: User.session!, parent_id: params[:parent_id])
comment = @obj.comments.new(body: request.raw_post, user: User.session!, parent_id: params[:parent_id])
authorize comment, :create?
comment.save!
render_ok
end

Expand Down

0 comments on commit 26bcb38

Please sign in to comment.