Skip to content
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

Merged
merged 1 commit into from
Mar 24, 2017
Merged

Ensure actions are returned correctly in the API #14033

merged 1 commit into from
Mar 24, 2017

Conversation

jntullo
Copy link

@jntullo jntullo commented Feb 22, 2017

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:

  :snapshots:
    :description: Snapshots
    :options:
    - :subcollection
    :verbs: *gpd
    :klass: Snapshot

which does not describe any actions. However, on the vms collection, the subcollection is defined as:

    :snapshots_subcollection_actions:
      :get:
      - :name: read
        :identifier: vm_snapshot_view
      :post:
      - :name: create
        :identifier: vm_snapshot_add
      - :name: delete
        :identifier: vm_snapshot_delete
    :snapshots_subresource_actions:
      :get:
      - :name: read
        :identifier: vm_snapshot_view
      :post:
      - :name: delete
        :identifier: vm_snapshot_delete
      :delete:
      - :name: delete
        :identifier: vm_snapshot_delete

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

@abellotti
Copy link
Member

hmm, seems to have lost collection level actions with this PR.

@abellotti
Copy link
Member

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:

       def gen_action_spec_for_collections(collection, cspec, is_subcollection, href)
-        target = is_subcollection ? :subcollection_actions : :collection_actions
-        return [] unless cspec[target]
-        cspec[target].each.collect do |method, action_definitions|
+        if is_subcollection
+          target = :subcollection_actions
+          cspec_target = cspec[target] || collection_config.typed_subcollection_actions(@req.collection, collection)
+        else
+          target = :collection_actions
+          cspec_target = cspec[target]
+        end
+        return [] unless cspec_target
+        cspec_target.each.collect do |method, action_definitions|

and some variant for the second method.

Copy link
Member

@abellotti abellotti left a 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) }
Copy link
Member

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

Copy link
Member

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
Copy link
Member

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)
Copy link
Member

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 ?

Copy link
Author

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.

@abellotti abellotti requested a review from imtayadeway March 23, 2017 19:58
add additional tests

simplifying
@miq-bot
Copy link
Member

miq-bot commented Mar 23, 2017

Checked commit jntullo@70e89b6 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
2 files checked, 0 offenses detected
Everything looks good. 🍰

Copy link
Contributor

@imtayadeway imtayadeway left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@abellotti
Copy link
Member

Thanks @jntullo for fixing this. 😍

@abellotti abellotti merged commit c8f898e into ManageIQ:master Mar 24, 2017
@abellotti abellotti added this to the Sprint 57 Ending Mar 27, 2017 milestone Mar 24, 2017
@chrisarcand chrisarcand deleted the fix_actions branch November 28, 2017 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants