-
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
Return custom buttons for service having nil service template #17703
Conversation
@miq-bot add_label bug, blocker |
994844b
to
8857491
Compare
@d-m-u if this can be backported can you add the gaprindashvili/yes label. |
@miq-bot add_label gaprindashvili/yes |
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.
One small change requested in the specs, but otherwise looks good.
spec/models/service_spec.rb
Outdated
describe "#custom_action_buttons" do | ||
it "get list of custom action buttons on services" do | ||
expect(service).to receive(:custom_action_buttons).and_return(@custom_button) | ||
service.custom_action_buttons |
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 think you want to re-word this expect
so that it doesn't read like you've stubbed out service.custom_action_buttons
since that's what you're testing.
Should be something more like:
expect(service.custom_action_buttons).to equal(@custom_button)
You can also change the @custom_button
to be a let for consistency, it shouldn't have to be an instance variable. In this case, since lets are lazily loaded, you can use let!
if you need the button to be created before the spec gets ran.
@miq-bot remove_label wip |
app/models/service.rb
Outdated
CustomButton.where(:applies_to_class => "Service") | ||
else | ||
service_template.custom_action_buttons(self) | ||
end |
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.
This looks fine, although I might suggest if service_template
and swapping the if-else blocks. Doing a 1-line ternary operator comes out to 121 characters. So close.
Anyway, the real reason I'm here is to ask about the custom_actions
method just above this method which looks like it will suffer the same fate and should be addressed as well.
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.
Doing a 1-line ternary operator comes out to 121 characters. So close.
There's no line length limit, so 121 is fine
if service_template
👍
fd3520c
to
9b94e7c
Compare
app/models/service.rb
Outdated
if service_template.nil? | ||
buttons = CustomButton.where(:applies_to_class => "Service") | ||
button_groups = CustomButtonSet.all.select { |f| f.set_data[:applies_to_class] == "Service" } | ||
{:buttons => buttons, :button_groups => button_groups} |
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.
Looking at app/models/mixins/custom_actions_mixin.rb#L11-L20 there looks like there is more to this.
Could the Service
class include the mixin and then call it when service_template
is not available? I think it would avoid rewriting this logic.
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.
Then since I'm using the mixin logic should the custom_action_button query just be generic_custom_buttons from the mixin here: https://github.com/ManageIQ/manageiq/blob/master/app/models/mixins/custom_actions_mixin.rb#L52 ?
Yes, that looks correct. |
e2d3181
to
db92445
Compare
@gmcculloug @syncrou can you 👀 again for me please? |
fc208c1
to
834e726
Compare
@d-m-u Please see failing tests. We initially looked at using Open to suggestions on this one. |
Checked commit d-m-u@14c4be1 with ruby 2.3.3, rubocop 0.52.1, haml-lint 0.20.0, and yamllint 1.10.0 app/models/service.rb
|
Yeah, @d-m-u asked me about that, |
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 👍
@bdunne Services can be backed by a ServiceTemplate or created without one. Custom buttons can be attached directly to a ServiceTemplate and/or to the Service class (meaning all service instances get them). The existing code assumes that there is a ServiceTemplate and if so we get the buttons from there. If there is no ServiceTemplate then nothing is returned. This change handles a stand-along Service (no parent ServiceTemplate) and supports the custom buttons that are defined on the Service class. |
@eclarizio PTAL |
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.
👍
Return custom buttons for service having nil service template (cherry picked from commit 2d8f3e8) Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1603031
Gaprindashvili backport details:
|
For bz https://bugzilla.redhat.com/show_bug.cgi?id=1595051.
Services with nonexistent service templates should return all buttons applicable to services, I spose.
GM's ideas were to use a prepend or alias_method for this. The custom_action method exists in both Service and the CustomActionsMixin and in the event of a dearth of service template on the service, we want to run the mixin method. The mixin is used basically everywhere which complicates this somewhat. If anyone (ie @bdunne) has a better idea about how to handle this, I'm all 👂s.
@eclarizio can you 👀 for me please?
@tinaafitz