-
Notifications
You must be signed in to change notification settings - Fork 897
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 actions are returned correctly in the API #14033
Conversation
hmm, seems to have lost collection level actions with this PR. |
ping @jntullo @imtayadeway we really need this fixed. looked at this a bit, we should be able to extend gen_action_spec_for_collections and gen_action_spec_for_resources without adding new methods to fix this. for the first, something like:
and some variant for the second method. |
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.
thanks @jntullo for updating this, a couple of question and need a new test.
next unless render_actions_for_method(cspec[:verbs], method) | ||
typed_action_definitions = fetch_typed_subcollection_actions(method, is_subcollection) || action_definitions | ||
typed_action_definitions.each.collect do |action| | ||
if !action[:disabled] && api_user_role_allows?(action[:identifier]) | ||
{"name" => action[:name], "method" => method, "href" => (href ? href : collection)} | ||
{ "name" => action[:name], "method" => method, "href" => (href ? href : collection) } |
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.
why this change here ? was this for Rubocop ?
@@ -643,6 +643,53 @@ def create_vms_by_name(names) | |||
expect(actions.first["name"]).to eq("suspend") | |||
end | |||
|
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 you add a test on actions returned for the collection itself /api/vms, maybe authorize with vm_start and vm_stop. We seem to be missing that test.
@@ -413,7 +425,7 @@ def render_options(resource, data = {}) | |||
collection.virtual_attribute_names), | |||
:virtual_attributes => options_attribute_list(collection.virtual_attribute_names), | |||
:relationships => (collection.reflections.keys | | |||
collection.virtual_reflections.keys.collect(&:to_s)).sort | |||
collection.virtual_reflections.keys.collect(&:to_s)).sort |
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.
was this for Rubocop too ? looks odd, can collection on 428 align with collection on 427 while keeping Rubocop happy ?
next unless render_actions_for_method(cspec[:verbs], method) | ||
typed_action_definitions = fetch_typed_subcollection_actions(method, is_subcollection) || action_definitions | ||
typed_action_definitions = action_definitions || fetch_typed_subcollection_actions(method, is_subcollection) |
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.
what did this switch resolve ?
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.
@abellotti the correct subresource actions were not being resolved - it was sending back subcollection actions.
add additional tests simplifying
Checked commit jntullo@70e89b6 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
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.
👍
Thanks @jntullo for fixing this. 😍 |
This fixes an issue where subcollection actions were not being returned unless they were defined in the
api.yml
on the collection itself. As an example, the snapshots collection is defined as:which does not describe any actions. However, on the vms collection, the subcollection is defined as:
This update ensures that subresource and subcollection actions are correctly returned and adds in tests to ensure this case is accounted for.
@miq-bot add_label bug, api
@miq-bot assign @abellotti
cc: @imtayadeway, @AllenBW