-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return NotFound error if ChatChannelMembership is not found #5806
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @majakomel, thanks for the PR!
Left a note about style, I think we should lean towards using Rails than custom code
@membership = ChatChannelMembership.where(chat_channel_id: params[:chat_channel_id], user_id: current_user.id).first | ||
not_found unless @membership |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can I suggest replacing this with:
ChatChannelMembership.where(...).first!
?
Rails has many handy ActiveRecord methods to bail out in case items don't exist, see https://api.rubyonrails.org/classes/ActiveRecord/FinderMethods.html#method-i-first-21
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! not_found
was suggested in the issue description and I just went with it. It's replaced now :)
8abbb4d
to
62ee693
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @majakomel!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀
@@ -2,7 +2,7 @@ class ChatChannelMembershipsController < ApplicationController | |||
after_action :verify_authorized | |||
|
|||
def find_by_chat_channel_id | |||
@membership = ChatChannelMembership.where(chat_channel_id: params[:chat_channel_id], user_id: current_user.id).first | |||
@membership = ChatChannelMembership.where(chat_channel_id: params[:chat_channel_id], user_id: current_user.id).first! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL you can put a bang on first
!
What type of PR is this? (check all applicable)
Description
Returns
ActiveRecord::RecordNotFound
instead ofPundit::NotDefinedError
when chat channel membership is not found.Related Tickets & Documents
Fixes #5790
Added to documentation?