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

OPTIONS - Generic Object Definition #42

Merged
merged 4 commits into from
Sep 8, 2017

Conversation

AparnaKarve
Copy link
Contributor

We need support for OPTIONS /api/generic_object_definitions so that the Generic Object Definitions UI populates the dropdowns with the allowed association types and allowed data types

Requires ManageIQ/manageiq#15922 to be merged first for the new Dictionary entries added for the allowed data types.

@abellotti
Copy link
Member

This LGTM!! Thanks @AparnaKarve for the enhancement.

/cc @jntullo can I borrow your 👀 for a quick review ?

@miq-bot
Copy link
Member

miq-bot commented Sep 7, 2017

This pull request is not mergeable. Please rebase and repush.

@abellotti
Copy link
Member

@AparnaKarve will need a rebase/repush when you get a chance. Thanks.

@imtayadeway
Copy link
Contributor

Hi! It looks like your PR has been affected by the recently merged #40, and as a result will need to be rebased. First, I apologize for any inconvenience caused. After rebasing, you'll need to update some specs in order for them to pass. In particular you'll need to change any path helpers, applying the following pattern:

vms_url => api_vms_url
vms_url(vm.id) => api_vm_url(nil, vm) 
vms_url(vm.compressed_id) => api_vm_url(nil, vm.compressed_id)
"#{vms_url(vm.id)}/tags" => api_vm_tags_url(nil, vm)
"#{vms_url(vm.compressed_id}/tags" => api_vm_tags_url(nil, vm.compressed_id)
"#{vms_url(vm.id)}/tags/#{tag.id}" => api_vm_tag_url(nil, vm, tag)
"#{vms_url(vm.compressed_id)}/tags/#{tag.compressed_id}" => api_vm_tag_url(nil, vm.compressed_id, tag.compressed_id)

If you run into any issues, please ping me and I will try to help you out.

Many thanks!
Tim

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.

@AparnaKarve this LGTM. Just one suggestion - do you think that allowed_association_types and allowed_types could be centralized (possibly in the model) so that you don't have to reproduce the implementation in the tests? I'm fine with leaving that as a follow up if you'd rather get this merged first

@AparnaKarve
Copy link
Contributor Author

@imtayadeway I did think about adding allowed_association_types and allowed_types in the model, but wanted to keep the model free of all the Dictionary/i18n related stuff.

In normal course (pre-API days), we would have implemented allowed_association_types and allowed_types in the view controller (controllers/generic_object_definition_controller.rb)
So to keep that parity, I decided to add the methods in allowed_association_types and allowed_types in the API controller (api/generic_object_definitions_controller.rb ) instead.

That was mainly the rationale behind adding the methods in api/generic_object_definitions_controller.rb

@imtayadeway
Copy link
Contributor

I did think about adding allowed_association_types and allowed_types in the model, but wanted to keep the model free of all the Dictionary/i18n related stuff.

@AparnaKarve is that because you didn't want it to be executed at load time? Aren't there ways to delay it until call time?

Either way, if you didn't want to update the model, you could add a service object instead?

@AparnaKarve
Copy link
Contributor Author

is that because you didn't want it to be executed at load time? Aren't there ways to delay it until call time?

@imtayadeway If we add the methods to the model, we probably do not have to worry about delayed loading etc. It should just work.
Not adding it to the model was a conscious decision, but I think I can reconsider that.

@abellotti Can you please merge this and I can create a follow-up PR to move the methods allowed_association_types and allowed_types out of the API controller. Thanks.

you could add a service object instead?

Not sure how applicable the service object is to this case.

@abellotti
Copy link
Member

I'm ok with keeping those here, but still not crazy with the dup. As an option (no pun intended), why not just define those as class instance methods for now.

module Api
   class GenericObjectDefinitionsController
      def self.allowed_types
      end
      ...
      def self.allowed_association_types
      end
      ...

and used by both api controller and specs.

@AparnaKarve
Copy link
Contributor Author

@abellotti When I make those methods as class instance methods, they work in the api controller when I access them like this -

GenericObjectDefinitionsController::allowed_association_types

But GenericObjectDefinitionsController::allowed_association_types does not seem to work in the spec. I'm seeing this -

Unable to autoload constant GenericObjectDefinitionsController, expected ~/master/manageiq/plugins/manageiq-api/app/controllers/api/generic_object_definitions_controller.rb to define it

to remove method duplication in the spec
@miq-bot
Copy link
Member

miq-bot commented Sep 8, 2017

Checked commits AparnaKarve/manageiq-api@9b87724~...9cfe639 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0
2 files checked, 0 offenses detected
Everything looks fine. 🏆

@AparnaKarve
Copy link
Contributor Author

@abellotti Thanks for the tip on class instance method and Api::GenericObjectDefinitionsController.<method_name>

@AparnaKarve
Copy link
Contributor Author

I like that there are no dups now.

Thanks @imtayadeway and @abellotti

@abellotti
Copy link
Member

Thanks @AparnaKarve for the API enhancement !! will merge when 🍏

@abellotti abellotti added this to the Sprint 69 Ending Sep 18, 2017 milestone Sep 8, 2017
@abellotti abellotti merged commit b372c7e into ManageIQ:master Sep 8, 2017
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