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

Return custom buttons for service having nil service template #17703

Merged
merged 1 commit into from
Jul 17, 2018

Conversation

d-m-u
Copy link
Contributor

@d-m-u d-m-u commented Jul 13, 2018

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

@d-m-u
Copy link
Contributor Author

d-m-u commented Jul 13, 2018

@miq-bot add_label bug, blocker

@JPrause
Copy link
Member

JPrause commented Jul 13, 2018

@d-m-u if this can be backported can you add the gaprindashvili/yes label.

@d-m-u d-m-u changed the title Return custom buttons for service having nil service template [WIP] Return custom buttons for service having nil service template Jul 13, 2018
@d-m-u
Copy link
Contributor Author

d-m-u commented Jul 13, 2018

@miq-bot add_label gaprindashvili/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.

One small change requested in the specs, but otherwise looks good.

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
Copy link
Member

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.

@d-m-u d-m-u changed the title [WIP] Return custom buttons for service having nil service template Return custom buttons for service having nil service template Jul 13, 2018
@d-m-u
Copy link
Contributor Author

d-m-u commented Jul 13, 2018

@miq-bot remove_label wip

@miq-bot miq-bot removed the wip label Jul 13, 2018
@gmcculloug gmcculloug self-assigned this Jul 13, 2018
CustomButton.where(:applies_to_class => "Service")
else
service_template.custom_action_buttons(self)
end
Copy link
Member

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.

Copy link
Member

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

👍

@d-m-u d-m-u force-pushed the bz1595051 branch 3 times, most recently from fd3520c to 9b94e7c Compare July 16, 2018 13:58
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}
Copy link
Member

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.

Copy link
Contributor Author

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 ?

@gmcculloug
Copy link
Member

Yes, that looks correct.

@d-m-u d-m-u force-pushed the bz1595051 branch 2 times, most recently from e2d3181 to db92445 Compare July 16, 2018 20:29
@d-m-u
Copy link
Contributor Author

d-m-u commented Jul 16, 2018

@gmcculloug @syncrou can you 👀 again for me please?

@d-m-u d-m-u force-pushed the bz1595051 branch 2 times, most recently from fc208c1 to 834e726 Compare July 17, 2018 15:50
@gmcculloug
Copy link
Member

@d-m-u Please see failing tests.

We initially looked at using prepend but found that the included block in the CustomActionsMixin was not run which lead to other issues so we went with the current solution.
https://github.com/ManageIQ/manageiq/blob/master/app/models/mixins/custom_actions_mixin.rb#L4-L9

Open to suggestions on this one.

@miq-bot
Copy link
Member

miq-bot commented Jul 17, 2018

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
2 files checked, 1 offense detected

app/models/service.rb

@bdunne
Copy link
Member

bdunne commented Jul 17, 2018

We initially looked at using prepend but found that the included block

Yeah, @d-m-u asked me about that, include and prepend are very different. I'm still not sure what the goal is...

Copy link
Contributor

@syncrou syncrou left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@gmcculloug
Copy link
Member

@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.

@gmcculloug
Copy link
Member

@eclarizio PTAL

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.

👍

@gmcculloug gmcculloug merged commit 2d8f3e8 into ManageIQ:master Jul 17, 2018
@gmcculloug gmcculloug added this to the Sprint 91 Ending Jul 30, 2018 milestone Jul 17, 2018
simaishi pushed a commit that referenced this pull request Jul 19, 2018
Return custom buttons for service having nil service template
(cherry picked from commit 2d8f3e8)

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

Gaprindashvili backport details:

$ git log -1
commit 0378482d9f90600e3614cf65573b87f372bf04c2
Author: Greg McCullough <gmccullo@redhat.com>
Date:   Tue Jul 17 19:01:41 2018 -0400

    Merge pull request #17703 from d-m-u/bz1595051
    
    Return custom buttons for service having nil service template
    (cherry picked from commit 2d8f3e83bcc4e9ea519596957e99d9e69baf5041)
    
    Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1603031

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