-
Notifications
You must be signed in to change notification settings - Fork 898
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
Service retirement values from dialog #16799
Conversation
Tests in progress as well as code changes to protect against parsing invalid values. |
7ea3cba
to
620f44a
Compare
This pull request is not mergeable. Please rebase and repush. |
620f44a
to
abba0ff
Compare
abba0ff
to
2291f38
Compare
2291f38
to
e6f9ade
Compare
e6f9ade
to
962aa1f
Compare
962aa1f
to
c7ab760
Compare
c7ab760
to
915ebc4
Compare
e9b5aa7
to
4be0f14
Compare
b81d047
to
bf9aead
Compare
@mkanoor @tinaafitz @eclarizio Still |
@miq-bot add_label blocker |
@gmcculloug if this can be backported to fine and gaprindashvili can you add: fine/yes and gaprindashvili/yes |
bf9aead
to
38597f2
Compare
@gmcculloug is this still a WIP. We have a build today, and wondering if it's ready, so it can be backported. |
Yes, still |
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.
Overall I think this looks like a good step but I'm extremely concerned about how all of the various attributes are set via the meta-programming. I think we could break some of the more complicated attribute setting logic into another class so that it's easier to test, and also easier to see the explicit call instead of just a send
.
Ultimately your #parse_options
method I think would change to something like:
@attributes[:name] = @options["dialog_service_name"] if @options["dialog_service_name"]
@attributes[:description] = @options["dialog_service_description"] if @options["dialog_service_description"]
retirement_options = SomeRetirementOptionParser.do_the_retirement_parsing(@options)
@attributes.merge(retirement_options)
end | ||
|
||
def parse_value(field_name, dialog_field_name, dialog_field_value) | ||
send(field_name, dialog_field_value) if @options.key?(dialog_field_name) |
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.
Do we need this if
? We're already qualifying the same thing on line 26, and I don't see anywhere else this method is used.
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.
Also I'm concerned about this method since it's a pretty huge feat of meta-programming (hats off to you for accomplishing that one) and it's going to be extremely difficult to unravel later down the line if something needs changing here. Not sure how to solve it quite yet, but maybe some of my other suggestions will make this easier to digest.
end | ||
|
||
def retires_on(value) | ||
self.retire_on_date = time_parse(value) |
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.
At first I was like "wait a second, why aren't we just doing @attributes[:retire_on_date] = time_parse(value)
but then I realized you overrode retire_on_date=
. I feel like this whole "retirement" part of this code could be broken out into a whole separate class that purely deals with the parsing of the time. The warning part could even be it's own separate class too, I think.
spec/models/service_template_spec.rb
Outdated
@@ -1,6 +1,9 @@ | |||
describe ServiceTemplate do | |||
include_examples "OwnershipMixin" | |||
|
|||
# let(:service_user) { instance_double("user") } |
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.
Probably don't need this line, haha 😄
Though, I would prefer to use the instance double if we can, but I'm guessing since it's commented out it didn't work for some reason.
end | ||
end | ||
|
||
# warn_on warn_in_days warn_in_hours warn_offset_days warn_offset_hours |
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.
Looks like this was a reminder to make these specs but they appear to be made above, so I think we can safely remove this.
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.
Looks great except for the screenshotted weirdness.
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.
@gmcculloug Looks good. :-)
Changed to call create! Refactor create_service method to use create! with a block
8a41883
to
3f0d08b
Compare
require_nested :Retirement | ||
|
||
def initialize(options, user) | ||
@attributes = {} |
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.
@gmcculloug Is the @attributes needed since we are parsing and just returning a hash back after the parse?
3f0d08b
to
01761c8
Compare
|
||
def parse | ||
Service::DialogProperties::Retirement.parse(@options, @user).tap do |attributes| | ||
@attributes[:name] = @options['dialog_service_name'] if @options['dialog_service_name'].present? |
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.
@gmcculloug
The local attributes is not being used, should @attributes be attributes 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.
Definitely, it is fixed now.
Pass user so time parsing occurs in proper timezone.
01761c8
to
fd8709d
Compare
Checked commits gmcculloug/manageiq@9ed98e9~...fd8709d with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 app/models/service/dialog_properties/retirement.rb
|
Service retirement values from dialog (cherry picked from commit def0da5) Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1626475
Fine backport details:
|
Service retirement values from dialog (cherry picked from commit def0da5) Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1626474
Gaprindashvili backport details:
|
Building on the changes from PR #16338 (Name service during provisioning from dialog input) this PR adds the ability to set service retirement values from a dialog during service ordering.
The logic sets the
retires_on
value based on the dialog field name used:service_retires_on
- Date/DateTime valueservice_retires_in_days
- Duration value (Integer) from current time.service_retires_in_hours
- Duration value (Integer) from current time.The
retirement_warn
value for a service is set only if aretires_on
value has been specified. It can be set using one of the following dialog field names:service_retirement_warn_on
- Date/DataTime valueservice_retirement_warn_in_days
- Duration value (Integer) from current time.service_retirement_warn_in_hours
- Duration value (Integer) from current time.service_retirement_warn_offset_days
- Duration value (Integer) fromretries_on
valueservice_retirement_warn_offset_hours
- Duration value (Integer) fromretries_on
valueLinks
Steps for Testing/QA
Create a service dialog that specifics one of the fields that sets the
retires_on
value for a service. Optionally, set a dialog field to specify theretirement_warn
value. After ordering the Catalog Item the Service that is created should have the expected retirement properties.