-
Notifications
You must be signed in to change notification settings - Fork 141
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
add flavors create, delete to api #14
Conversation
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.
Hi @alexander-demichev, can you also add some specs to this? You will also need to update the config/api.yml. Thanks!
end | ||
|
||
def validate_flavor_attrs(data) | ||
data.dup |
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.
not sure this method is necessary if no validation is being done. If you aren't manipulating the data, you shouldn't need to dup it either
|
||
def delete_resource(type, id, _data = {}) | ||
flavor = resource_search(id, type, collection_class(:flavors)) | ||
raise "Delete not supported for #{flavor_ident(flavor)}" unless flavor.respond_to?(:delete_flavor_queue) |
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.
is this supposed to be delete_in_provider_queue
? it's checking a different method than is used below
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.
@alexander-demichev I may be incorrect, but is this method delete_flavor_queue
the correct method? I don't see any flavor descendants responding to it
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.
@jntullo I made comment with link to flavors actions PR.
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 don't all flavors respond to this? How does the user know which ones can be deleted? Is it possible that flavors could utilize the supports_feature? feature?
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.
All flavors support delete. I should delete this line of code.
cafe415
to
fdb9783
Compare
Thank you for review, @jntullo. I added some specs. |
6b98a40
to
f408fab
Compare
Flavors actions are implemented here ManageIQ/manageiq#15552 |
f408fab
to
f98e512
Compare
@jntullo Hi, can you review it again? |
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:
If you run into any issues, please ping me and I will try to help you out. Many thanks! |
452a2a1
to
25c5983
Compare
@imtayadeway Hi, one of the tests is failing, can you take a look at it? Thanks. :-) |
spec/requests/flavors_spec.rb
Outdated
|
||
api_basic_authorize | ||
|
||
run_delete api_flavors_url(nil, flavor) |
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 believe you want api_flavor_url(nil, flavor)
here
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.
@jntullo Silly mistake :) Thank you, now it`s ok!
2902981
to
febf9f1
Compare
Looks good to me, looking forward to see this merged :-) |
Maybe add 2 tests for delete single flavor (POST /api/flavors/:id - action edit) and do a bulk delete (POST /api/flavors - action edit). Otherwise looks good, @imtayadeway and @jntullo your 👀 when you get a chance. Thanks!! |
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.
LGTM! ✨ Minor comment about removing compressed_id
and just passing in the flavor object
spec/requests/flavors_spec.rb
Outdated
'count' => 1, | ||
'subcount' => 1, | ||
'name' => 'flavors', | ||
'resources' => [hash_including('href' => a_string_matching(api_flavors_url(nil, flavor.compressed_id)))] |
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 wouldn't use compressed_id
here, and instead just pass in flavor
7e54907
to
5f8895a
Compare
@jntullo @imtayadeway Hi, can you take a look, I edited tests and during CI it's throwing 'NoMethodError', but it works if I run test on my machine. |
hi @alexander-demichev, if you rebase and update to use |
5f8895a
to
db4a574
Compare
Added some tests :) @imtayadeway @jntullo |
@@ -1,4 +1,24 @@ | |||
module Api | |||
class FlavorsController < BaseController | |||
def create_resource(_type, _id, data) | |||
task_id = Flavor.create_flavor_queue(User.current_user.id, EmsCloud.find(data['ems']['id']), data) |
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.
Rather than EmsCloud.find
here, I think you may want to use resource_search(:id, :providers, collection_class(:providers)
. Also, what do you think about supporting both id
and href
? Something along the lines of
{ "provider": { "href" : "/api/providers/:id" }
or { "provider": { "id": ":id" } }
. This example may help
db4a574
to
2a6ff2f
Compare
action_result(false, err.to_s) | ||
end | ||
|
||
def delete_resource_snapshots(_parent, type, id, _data) |
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 believe this should be flavors_delete_resource
020b5a3
to
8425e11
Compare
@jntullo @imtayadeway Can I ask you for another round of review? 😄 |
config/api.yml
Outdated
@@ -861,20 +861,30 @@ | |||
:description: Flavors | |||
:identifier: flavor | |||
:options: | |||
- :collection | |||
:verbs: *gp | |||
- :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.
I didn't realize the collection already exists, I am assuming we'll still want to keep the collection actions? And just add in the subcollection actions?
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.
👍 Yeah I think if it already exists we can preserve the ability to retrieve flavors using only their id
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.
LGTM, but as @jntullo suggested I think it would be better to leave the existing routes for flavor retrieval intact.
8425e11
to
132082d
Compare
@imtayadeway @jntullo Is it ok now? |
config/api.yml
Outdated
:klass: Flavor | ||
:collection_actions: | ||
:subcollection_actions: |
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.
if you just add the collection actions back in, should be good to go 👍
spec/requests/collections_spec.rb
Outdated
@@ -114,11 +114,6 @@ def test_collection_bulk_query(collection, collection_url, klass, id = nil) | |||
test_collection_query(:features, api_features_url, MiqProductFeature) | |||
end | |||
|
|||
it "query Flavors" do |
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.
and we'll want these once you add the collections actions back into the api.yml
b8ada28
to
e3bdf15
Compare
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.
LGTM! Thanks @alexander-demichev! ✨
@alexander-demichev can you add the test for bulk deletes ? i.e. POST /api/providers/:id/flavors action "delete" with 2 flavors ? Thanks. |
e3bdf15
to
4d73097
Compare
4d73097
to
eb40c9e
Compare
Checked commit alexander-demicev@eb40c9e with ruby 2.3.3, rubocop 0.47.1, and haml-lint 0.20.0 |
@abellotti Added tests for bulk delete. |
Thanks @alexander-demichev for the added test and the API enhancement. 👍 |
Add flavors actions(create,delete) to api