-
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
add dialog info when import/export custom buttons #20137
add dialog info when import/export custom buttons #20137
Conversation
@borisko123 Please address the rubocop warnings. |
|
@lfu seems all clean now |
@gmcculloug Any idea why dialog was excluded from import/export in #17699? What was the concern? |
As I recall, we were following scripts that already existed (side the MIQ repo) which processed custom buttons and dialogs separately. If you add this you'll just want to consider how you handle if the dialog already exists. Dialogs can be re-used by different buttons and/or services. |
@borisko123 Thanks for the update. Please take a look at this file for importing a dialog and this for exporting. Hope they can give you some ideas. |
Dialog was concerned in rhconsulting scripts. The code for Miq was ported
from there. It worked well. The dialog support was simply missed,IMHO
…On Mon, May 11, 2020, 16:49 Greg McCullough ***@***.***> wrote:
As I recall, we were following scripts that already existed (side the MIQ
repo) which processed custom buttons and dialogs separately.
If you add this you'll just want to consider how you handle if the dialog
already exists. Dialogs can be re-used by different buttons and/or services.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#20137 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AOOOCDSTP2U35LLOUSGIJJTRQ766JANCNFSM4M3PEIEQ>
.
|
Only dialog name is exported.
In import, we lookup the dialog by this name. In case it exists, its
ID is added to resource_action.
It is exactly the same as add dialog manually by UI.
…On Mon, May 11, 2020, 20:05 Lucy Fu ***@***.***> wrote:
@borisko123 <https://github.com/borisko123> Thanks for the update.
What kind of dialog info is supposed to be added in this PR? Is it the
dialog object with all its tabs and fields? Seems only dialog label is
added in the export yaml file.
Please take a look at this file
<https://github.com/ManageIQ/manageiq/blob/cddcb42c99cc981f9ab74ba527eee58acc38a9a1/lib/services/dialog_import_service.rb>
for importing a dialog and this
<https://github.com/ManageIQ/manageiq/blob/master/lib/task_helpers/dialog_exporter.rb>
for exporting. Hope they can give you some ideas.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#20137 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AOOOCDVE7VLEOE74FKXGOH3RRAV6VANCNFSM4M3PEIEQ>
.
|
Forgot to mention that dialog should already exist!. So we deal with
existed ID only. Exactly as in rhconsulting code
…On Mon, May 11, 2020, 20:15 Boris Kozel ***@***.***> wrote:
Only dialog name is exported.
In import, we lookup the dialog by this name. In case it exists, its
ID is added to resource_action.
It is exactly the same as add dialog manually by UI.
On Mon, May 11, 2020, 20:05 Lucy Fu ***@***.***> wrote:
> @borisko123 <https://github.com/borisko123> Thanks for the update.
> What kind of dialog info is supposed to be added in this PR? Is it the
> dialog object with all its tabs and fields? Seems only dialog label is
> added in the export yaml file.
>
> Please take a look at this file
> <https://github.com/ManageIQ/manageiq/blob/cddcb42c99cc981f9ab74ba527eee58acc38a9a1/lib/services/dialog_import_service.rb>
> for importing a dialog and this
> <https://github.com/ManageIQ/manageiq/blob/master/lib/task_helpers/dialog_exporter.rb>
> for exporting. Hope they can give you some ideas.
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#20137 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AOOOCDVE7VLEOE74FKXGOH3RRAV6VANCNFSM4M3PEIEQ>
> .
>
|
What if a dialog exists with the same name but different contents? Dialogs can be re-used by different buttons and/or services. It seems not right to use the existing dialog just because it has the same name. |
From Dialog model: the name/label is unique within region: So I suggest to add this functionality (filtering ) and then all should work. |
If the user really wants to use an existing dialog just because it has the same name, we can add one more command line option like @gmcculloug @gtanzillo What do you think of the new option? Any suggestion for the option name? |
It seems this option should be set to true by default. |
I would also agree that it would be more often that the user would want to use an existing dialog with the same name. However, i think would still be safer if that intention was explicitly specified on the command line. |
Ok, this option will be set to false.
If there are no other objections. I will implement region specific
filtering, add new option for import task and add new commit to PR, ok?
…On Wed, May 13, 2020, 18:28 Gregg Tanzillo ***@***.***> wrote:
It seems this option should be set to true by default.
More often we want to import 'as-is'
I would also agree that it would be more often that the user would want to
use an existing dialog with the same name. However, i think would still be
safer if that intention was explicitly specified on the command line.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#20137 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AOOOCDQ3UI624WN3T7VCUKTRRK4DBANCNFSM4M3PEIEQ>
.
|
Please modify the code where the new feature is added and keep other places untouched. |
@lfu do you mean that some test files have .yml extensions and not .yaml?
This is done intentionally, to not include them in glob. They are used
individually in tests , by using full name with certain extensions
explicitly. This exists in original code as well.
…On Wed, May 13, 2020, 20:58 Lucy Fu ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In lib/task_helpers/imports/custom_buttons.rb
<#20137 (comment)>:
> module TaskHelpers
class Imports
class CustomButtons
def import(options)
return unless options[:source]
- glob = File.file?(options[:source]) ? options[:source] : "#{options[:source]}/*.yaml"
+
+ glob = File.file?(options[:source]) ? options[:source] : "#{options[:source]}/*.yaml*"
We should keep the import file as .yaml.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#20137 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AOOOCDTRGQJXDUOIRXRTB73RRLNWFANCNFSM4M3PEIEQ>
.
|
> glob = File.file?(options[:source]) ? options[:source] : "#{options[:source]}/*.yaml”
What I said is this line should not be changed.
|
44aa954
to
50fbbde
Compare
|
d034b34
to
7069262
Compare
ActiveRecord::Base.transaction { obj_hash.each { |obj_def| create_object(*obj_def) } } | ||
end | ||
|
||
def find_or_create_object(class_name, obj) |
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.
In my opinion, this is to import custom buttons where they don't exist.
In case custom buttons exist, they may use Edit task in UI to modify them.
This new method is not necessary.
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.
@lfu, this method is my main enhancement.
Original code raises exception when button exists.
This is unacceptable.
The import may occurs many times on the already existing buttons(in development and even in production), with or without some button changing.
In both cases the code should replace the button, optionally updating the button attributes.
The 'rhconsulting' script, which was used for porting, had this behaviour.
Your idea of using UI, seems strange to me, as all the goal of import/export scripts is to make things without UI.
Please re-think your opinion
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.
The import may occurs many times on the already existing buttons(in development and even in production), with or without some button changing.
There are couple of things here.
- Why do you need import again if the buttons exist?
name
alone is not enough to identify a button.- Not sure if it is a good practice to update an existing button just because it happens to have the same name. What if the buttons are owned by other users?
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.
- It is needed, for example, during development, when import may be done multiple times from the same or different developers. Personally, had problems with this. Currently this will cause error,
and one need to delete manually ALL the button(s) in import directory, prior to import, or update yaml file. This is far from being convenient. - You are right. Button should be looked up by class and apply_id.
This may be added to code - For user's support some logic exists (see check_user method). This method is untouched in PR.
It set user from export data, or 'admin'. Maybe it may be improved.
Summary:
A. Importing existed buttons needs additional efforts.
In my opinion, it is nice to have.
In case ManageIQ team has another opinion. it is not worth to implement this at all
B. This PR includes 2 independent features: dialog support and import existing buttons.
In any way, since dialog support code is already mostly approved by you, I suggest retaining only corresponding code (for dialog support) in this PR and continue to review.
C. Optionally, open issue about importing existing buttons.
end | ||
end | ||
|
||
def populate_action(item, assoc) |
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.
These two methods added here are not necessary. Please move the code into add_associations
.
@borisko123 I like your idea to keep this PR just for dialog support. Let's open another issue for importing existing buttons. |
af0240a
to
2d8da36
Compare
@lfu done PR just for dialog, please check |
assert_imports_only_custom_button_set_one | ||
end | ||
end | ||
end | ||
end | ||
|
||
def assert_dialog_is_set(connect) | ||
btn1 = CustomButton.find_by(:name => custom_button_1_name) | ||
expect(btn1).to be |
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 line seems not right.
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.
button_1 = CustomButton.find_by(:name => "button 1")
expect(button_1).not_to be_nil
if connect
expect(button_1.resource_action.dialog.id).to eq(test_dialog_2.id)
else
expect(button_1.resource_action.dialog).to be_nil
end
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.
Prefer variable name button_1
over btn1
.
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.
@borisko123 Can you fix this line expect(btn1).to be
?
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 @lfu , what is wrong with this line?
It asserts that button exists...
from : https://relishapp.com/rspec/rspec-expectations/v/3-9/docs/built-in-matchers/be-matchers
expect(obj).to be # passes if obj is truthy (not nil or false)
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.
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.
@lfu Done
end | ||
end | ||
|
||
context "with existing identical buttons" do | ||
it 'should not import anything' do | ||
TaskHelpers::Imports::CustomButtons.new.import(options) | ||
assert_raises_import_error |
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.
What caused this change?
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.
Never mind.
assert_imports_only_custom_button_set_one | ||
end | ||
end | ||
end | ||
end | ||
|
||
def assert_dialog_is_set(connect) | ||
btn1 = CustomButton.find_by(:name => custom_button_1_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.
Minor. But can we have a better variable name here? Like button
or button_1
?
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.
@lfu done
2d8da36
to
257466c
Compare
let(:options) { {:source => source} } | ||
let(:connect_dialog_by_name) { true } | ||
let(:options) { {:source => source, :connect_dialog_by_name => connect_dialog_by_name} } | ||
let(:button_1) { 'button 1' } |
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 variable never changes. Can be removed.
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.
right. :button_1 is constant here, defined via let, and used at line 85:
btn1 = CustomButton.find_by(:name => button_1)
Do you want me to use literal instead? like
btn1 = CustomButton.find_by(:name => 'button 1')
Using 'let' to define constant is found as preffered way: see
https://stackoverflow.com/questions/5230070/scope-constants-to-an-rspec-context
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.
In my opinion, there is no need to define a variable here whose value doesn't change between the test cases.
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.
Agree that btn1 = CustomButton.find_by(:name => 'button 1')
is clearer since button_1
does not seem to be used anywhere else. Which code sets the name to button 1
? Perhaps both of those can use the same variable, such as button_1_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.
@lfu @chessbyte done
257466c
to
da43b07
Compare
-fix error in spec example -the test result depends on file order -code style review -modified according to miq-bot request -fix rubocop offence -add new flag (for dialog), modify specs - after review, simplify export dialog (@lfu, Tempfile creation (@gmcculloug) - refactor to include only dialog support stuff - rubocop issues - review literal button name without let - fix to be (be_an(CustomButton)
da43b07
to
a1fa28e
Compare
Checked commit borisko123@a1fa28e with ruby 2.5.7, rubocop 0.69.0, haml-lint 0.28.0, and yamllint |
@gtanzillo LGTM |
Fixes #20124
Current flow for import/export custom buttons ignores possible reference of the button to service dialog.
It is very inconvenient, since after import one need to add this reference manually in UI.
What's done:
(actually added dialog label)
How to run unit tests:
How to test manually on real data:
bundle exec rake evm:export:custom_buttons -- --directory contrib_export/buttons/
bundle exec rake evm:import:custom_buttons -- --source contrib_export/buttons/
(see screenshot)
The screen