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

Add flag to initialize field default values #485

Merged
merged 1 commit into from
Oct 15, 2018
Merged

Conversation

d-m-u
Copy link
Contributor

@d-m-u d-m-u commented Oct 4, 2018

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1635673

At this point if a service dialog gets ordered via the API, it will not honor defaults on static fields. To remedy this, this adds a flag to the call to also let us call load_values_into_fields(values, false), thus honoring the default values. This builds on the recent changes to ManageIQ/manageiq#17844

Related:

ManageIQ/manageiq#18061

@d-m-u
Copy link
Contributor Author

d-m-u commented Oct 4, 2018

@eclarizio can you 👀 please?

Copy link
Member

@eclarizio eclarizio left a comment

Choose a reason for hiding this comment

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

I feel like this would be much better as a parameter. For example, if the parameter of "init_defaults" is passed in as true, then we remove the :submit_workflow => true and use :init_defaults => true instead, cause otherwise as you have it now it's going to always call automate, no?

@d-m-u d-m-u force-pushed the bz1635673 branch 2 times, most recently from 8941245 to 6311303 Compare October 4, 2018 21:12
@d-m-u d-m-u changed the title Add flag to initialize field default values [WIP] Add flag to initialize field default values Oct 4, 2018
@d-m-u d-m-u force-pushed the bz1635673 branch 2 times, most recently from d4c8f5d to b41704a Compare October 4, 2018 22:04
@miq-bot miq-bot added the wip label Oct 5, 2018
Copy link
Member

@eclarizio eclarizio left a comment

Choose a reason for hiding this comment

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

One small comment but otherwise I think this should do what we want. 👍

app/controllers/api/mixins/service_templates.rb Outdated Show resolved Hide resolved
@d-m-u d-m-u force-pushed the bz1635673 branch 2 times, most recently from 58c3f88 to 01c7c09 Compare October 8, 2018 12:51
@d-m-u
Copy link
Contributor Author

d-m-u commented Oct 8, 2018

@miq-bot remove_label wip

@d-m-u d-m-u changed the title [WIP] Add flag to initialize field default values Add flag to initialize field default values Oct 8, 2018
@miq-bot miq-bot removed the wip label Oct 8, 2018
@d-m-u
Copy link
Contributor Author

d-m-u commented Oct 9, 2018

Hey @eclarizio can you please review again?

@@ -469,6 +476,8 @@ def init_st(service_template, resource_action)
let(:ra1) { FactoryGirl.create(:resource_action, :action => "Provision", :dialog => dialog1) }
let(:st1) { FactoryGirl.create(:service_template, :name => "service template 1") }
let(:sc) { FactoryGirl.create(:service_template_catalog, :name => "sc", :description => "sc description") }
let(:product_settings) { double(:run_automate_methods_on_service_catalog_api_submit => run_automate_methods_on_service_catalog_api_submit) }
Copy link
Member

Choose a reason for hiding this comment

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

I don't think product_settings is being used anywhere currently?

@d-m-u
Copy link
Contributor Author

d-m-u commented Oct 9, 2018

@miq-bot add_reviewer @tinaafitz

@miq-bot miq-bot requested a review from tinaafitz October 9, 2018 19:31
@JPrause
Copy link
Member

JPrause commented Oct 9, 2018

@d-m-u if this will be able to be backported, please add the gaprindashvili/yes and hammer/yes labels

@JPrause
Copy link
Member

JPrause commented Oct 9, 2018

@miq-bot add_label blocker

@d-m-u
Copy link
Contributor Author

d-m-u commented Oct 9, 2018

@miq-bot add_label bug

@d-m-u
Copy link
Contributor Author

d-m-u commented Oct 9, 2018

@miq-bot add_label gaprindashvili/yes, hammer/yes

Copy link
Member

@eclarizio eclarizio left a comment

Choose a reason for hiding this comment

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

Couple more spec comments, but the code itself should be fine

@@ -469,6 +476,7 @@ def init_st(service_template, resource_action)
let(:ra1) { FactoryGirl.create(:resource_action, :action => "Provision", :dialog => dialog1) }
let(:st1) { FactoryGirl.create(:service_template, :name => "service template 1") }
let(:sc) { FactoryGirl.create(:service_template_catalog, :name => "sc", :description => "sc description") }
let(:run_automate_methods_on_service_catalog_api_submit) { true }
Copy link
Member

Choose a reason for hiding this comment

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

Now that you fixed the product_settings not being used anywhere, this variable isn't being used either. I figured you meant to change line 372 (https://github.com/ManageIQ/manageiq-api/pull/485/files#diff-e129a646c1b31a559a2192293c958cf9R372) to use product_settings which then uses this variable.


context "with the product setting not allowing automate to run on submit" do
let(:template_no_display) { FactoryGirl.create(:service_template, :display => false) }
let(:run_automate_methods_on_service_catalog_api_submit) { false }
Copy link
Member

Choose a reason for hiding this comment

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

Is this variable being used anywhere?

@AllenBW
Copy link
Member

AllenBW commented Oct 11, 2018

Egad, 's a blocker here, we need eyes far sharper than mine, @abellotti if we turn this into a wrestling match, and I tag you in... 🤼‍♂️

@@ -14,6 +15,16 @@ def order_service_template(id, data, scheduled_time = nil)

private

def request_from_ui?
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Didn't we determine that it would be better to verify the token instead of solely going on if it's an http basic request versus token to know if the request is coming from the UI? At least that was my understanding from the conversation at #476 (comment).

Maybe that method could be extended or used in another way, but I don't think simply changing to use auth_mechanism is the correct solution.

@d-m-u
Copy link
Contributor Author

d-m-u commented Oct 11, 2018

@miq-bot assign @abellotti
sorry, AB, I dunno who else to give this to

@JPrause
Copy link
Member

JPrause commented Oct 12, 2018

@bdunne can you review,...Mr. Alberto is tied up at the moment. This is for a blocker issue.

@@ -14,6 +15,16 @@ def order_service_template(id, data, scheduled_time = nil)

private

def request_from_ui?
return false if request.headers["x-auth-token"].blank?
!token_info.empty?
Copy link
Member

Choose a reason for hiding this comment

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

Prefer .present? over !x.empty?

let(:product_settings) { double(:run_automate_methods_on_service_api_submit => run_automate_methods_on_service_api_submit) }

before do
stub_settings_merge(:product => product_settings)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be a hash rather than a double and let blocks?

let(:ra2) { FactoryGirl.create(:resource_action, :action => "Provision", :dialog => dialog1) }
let(:st2) { FactoryGirl.create(:service_template, :name => "service template 2", :display => true) }
let(:sc) { FactoryGirl.create(:service_template_catalog, :name => "sc", :description => "sc description") }
let(:run_automate_methods_on_service_api_submit) { true }
Copy link
Member

Choose a reason for hiding this comment

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

Why is this in a let block?

@miq-bot
Copy link
Member

miq-bot commented Oct 15, 2018

Checked commit d-m-u@f2f024a with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0
3 files checked, 0 offenses detected
Everything looks fine. 🏆

@simaishi simaishi closed this Oct 15, 2018
@simaishi simaishi reopened this Oct 15, 2018
@bdunne bdunne merged commit 73eee92 into ManageIQ:master Oct 15, 2018
@bdunne bdunne added this to the Sprint 97 Ending Oct 22, 2018 milestone Oct 15, 2018
@bdunne bdunne assigned bdunne and unassigned abellotti Oct 15, 2018
@d-m-u d-m-u deleted the bz1635673 branch October 15, 2018 16:40
@d-m-u
Copy link
Contributor Author

d-m-u commented Oct 15, 2018

Thanks @bdunne!

simaishi pushed a commit that referenced this pull request Oct 15, 2018
Add flag to initialize field default values

(cherry picked from commit 73eee92)

https://bugzilla.redhat.com/show_bug.cgi?id=1635673
@simaishi
Copy link
Contributor

Hammer backport details:

$ git log -1
commit d394c47a8c23092acfdd3812ce8cbde59c86f485
Author: Brandon Dunne <brandondunne@hotmail.com>
Date:   Mon Oct 15 12:40:20 2018 -0400

    Merge pull request #485 from d-m-u/bz1635673
    
    Add flag to initialize field default values
    
    (cherry picked from commit 73eee92f0137aa8546c95e1e25a44e51e901cf90)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1635673

simaishi pushed a commit that referenced this pull request Oct 15, 2018
Add flag to initialize field default values

(cherry picked from commit 73eee92)

https://bugzilla.redhat.com/show_bug.cgi?id=1639413
@simaishi
Copy link
Contributor

Gaprindashvili backport details:

$ git log -1
commit 28d00c9389c6e4c9a50a1f3882174ae2ec6e7fc0
Author: Brandon Dunne <brandondunne@hotmail.com>
Date:   Mon Oct 15 12:40:20 2018 -0400

    Merge pull request #485 from d-m-u/bz1635673
    
    Add flag to initialize field default values
    
    (cherry picked from commit 73eee92f0137aa8546c95e1e25a44e51e901cf90)
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1639413

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.

8 participants