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

API Enhancement to support filtering on id attributes by compressed id's #13645

Merged
merged 2 commits into from
Jan 27, 2017

Conversation

abellotti
Copy link
Member

@abellotti abellotti commented Jan 24, 2017

  • This enhancement allows filtering on id attributes or any of the *_id
    named attributes, i.e. storage_id, ems_id, etc. by compressed id,

    i.e.
    GET /api/vms?expand=resources&attributes=name,vendor&filter[]=id='2r77'
    GET /api/instances?expand=resources&attributes=name,storage_id&filter[]=storage_id=1r32

  • Added specs

Fixes: #11636

@abellotti abellotti changed the title API Enhancement to support filtering id attributes by compressed id's API Enhancement to support filtering on id attributes by compressed id's Jan 24, 2017
- This enhancement allows filtering on id attribute or any of the *_id
named attributes, i.e. storage_id, ems_id, etc. by compressed id,

  i.e.
    GET /api/vms?expand=resources&attributes=name,vendor&filter=id='2r77'
    GET /api/instances?expand=resources&attributes=name,storage_id&filter[]=storage_id=1r32

- Added specs

Fixes: ManageIQ#11636
@@ -1,6 +1,8 @@
module Api
class BaseController
module Parameters
include CompressedIds
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondering if moving CompressedIds to the top of the includes in the BaseController removes the need to include it (again) here? (Which I believe might also be the solution to the weird problems Jillian was running into)

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, let's do that in a separate PR, removing all other includes of CompressedIds too.

Copy link

Choose a reason for hiding this comment

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

@imtayadeway just tried adding it to the top BaseController in my issue to see if it made a difference, but it didn't 😞

Copy link
Contributor

Choose a reason for hiding this comment

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

@abellotti I think this can just be removed. Explanation here: #13671, tl;dr is these methods from this module are already available, you just can't reference any constants from the module unqualified from another module such as this.

ems2 = FactoryGirl.create(:ems_vmware, :zone => zone)
host = FactoryGirl.create(:host)

_vm = FactoryGirl.create(:vm_vmware, :host => host, :ems_id => ems1.id, :raw_power_state => "poweredOn")
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe setting association ids explicitly can cause some callbacks to fail..... does :ext_management_system => ems1 work?

Copy link
Member Author

Choose a reason for hiding this comment

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

we do the same in vms_spec.rb, never had an issue with them. Yes, ext_management_system => ems1 works too.

Copy link
Member Author

Choose a reason for hiding this comment

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

just updated and re-push (added more lines to keep rubocop happy).

@@ -100,6 +102,8 @@ def parse_filter(filter, operators)
end
end

filter_value = from_cid(filter_value) if filter_attr =~ /[_]?id$/ && cid?(filter_value)
Copy link
Contributor

Choose a reason for hiding this comment

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

Are the [ and ] needed in this regex?

Copy link
Member Author

Choose a reason for hiding this comment

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

they are optional, I tend to use them regardless, one or more character being matched for consistency.

Copy link
Contributor

Choose a reason for hiding this comment

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

WDYT about pulling this out into a named constant?

Copy link
Member Author

Choose a reason for hiding this comment

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

Meh, it's only used here for now, up to you. it will eventually be needed by https://www.pivotaltracker.com/story/show/121850107

@abellotti
Copy link
Member Author

@imtayadeway any other changes here ?

@miq-bot
Copy link
Member

miq-bot commented Jan 27, 2017

Checked commits abellotti/manageiq@b7124ff~...64b8f19 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.

👍

Copy link
Member

@gtanzillo gtanzillo left a comment

Choose a reason for hiding this comment

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

👍

@gtanzillo gtanzillo added this to the Sprint 53 Ending Jan 30, 2017 milestone Jan 27, 2017
@gtanzillo gtanzillo merged commit 2bec755 into ManageIQ:master Jan 27, 2017
@abellotti abellotti deleted the api_filters_compressed_ids branch January 27, 2017 22:05
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.

5 participants