-
Notifications
You must be signed in to change notification settings - Fork 6
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
Ensure the all_public_actions method works for Grape APIs #23
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,8 +155,14 @@ def this_is_an_abstract_controller_so_it_needs_no_access_tests | |
alias :access_tests_not_required :this_is_an_abstract_controller_so_it_needs_no_access_tests | ||
|
||
def all_public_actions | ||
actions = controller_class.public_instance_methods(false) | ||
actions += controller_class.superclass.public_instance_methods(false) | ||
actions = [] | ||
if defined?(Grape) && [Grape::API, Grape::API::Instance].any? { |base| controller_class < base } | ||
actions += controller_class.routes.map { |api| "#{api.request_method} #{api.origin}" } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really understand how this works but I guess it adds a string that is somehow parsed somewhere else? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In rails controllers, actions are uniquely identified by their method name (eg This means authorization rules for APIs look like this: role :tenant do
allowed to: ['GET /occupancies/:id'], when: [:read, :write_without_delete, :write]
end The string There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh right, that string. Yeah makes sense. |
||
else | ||
actions += controller_class.public_instance_methods(false) | ||
actions += controller_class.superclass.public_instance_methods(false) | ||
end | ||
|
||
actions.reject! do |method| | ||
method =~ /^_/ || | ||
method =~ /^rescue_action/ || | ||
|
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.
Could you update the README as well?
Currently it says:
Support for Rails 4 and 5
Instead, I think it should follow the Appraisals:
https://github.com/appfolio/ae_declarative_authorization/blob/master/Appraisals#L1-L2
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.
I agree it should be updated, but that seems unrelated to this change.
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.
Fair enough.