-
Notifications
You must be signed in to change notification settings - Fork 900
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
Require a description when creating Snapshot #12637
Require a description when creating Snapshot #12637
Conversation
@masayag please review. |
aae2270
to
41dd7b8
Compare
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.
Pls handle rubocop comment & remove the metrics_capture.rb from the PR. Besides. LGTM
add_flash(_("Description is required"), :error) | ||
@in_a_form = true | ||
drop_breadcrumb(:description => _("Snapshot VM '%{description}'") % {:description => @record.description}, :url => "/vm_common/snap") | ||
if session[:edit] && session[:edit][:explorer] |
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.
Could you use 'dig' instead ? assuming the ci is okay with it.
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.
Unfortunately this is not a hash its a Session object which does not support dig.
@@ -22,7 +22,6 @@ def perf_init_rhevm | |||
require 'ovirt_metrics' | |||
OvirtMetrics.establish_connection(conn_info) | |||
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.
please remove this file from the PR
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.
done, tnx!
41dd7b8
to
0fd3268
Compare
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
30be3b0
to
cffd14b
Compare
@miq-bot add_label blocker |
@durandom please review ASAP to merge this blocker. |
@miq-bot add_label euwe/yes |
def render_missing_field(session, missing_field_name) | ||
add_flash(_("#{missing_field_name} is required"), :error) | ||
@in_a_form = true | ||
drop_breadcrumb(:name => _("Snapshot VM '#{@record.name}'"), :url => "/vm_common/snap") |
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 won't work with i18n.
please use the format in the original code
See http://manageiq.org/docs/guides/i18n and search for 'string interpolation'
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.
Oh I had no idea. Tnx!
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.
besides i18n stuff good
@@ -558,6 +558,18 @@ def snap | |||
end | |||
alias_method :vm_snapshot_add, :snap | |||
|
|||
def render_missing_field(session, missing_field_name) | |||
add_flash(_("#{missing_field_name} is required"), :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.
same i18n thing here
@@ -573,15 +585,9 @@ def snap_vm | |||
@name = params[:name] | |||
@description = params[:description] | |||
if params[:name].blank? && [email protected](:snapshot_name_optional?) | |||
add_flash(_("Name is required"), :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.
+1 for refactoring into a method
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.
tnx. I just discovered I have a Vim plugin to extract methods ))
Although it did put the method inside a non related if block at first, but it was still nice :)
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.
yep, I use IntelliJ with vim bindings and like the refactoring tools there as well
render :action => "snap" | ||
end | ||
render_missing_field(session, "Name") | ||
elsif params[:description].blank? && @record.try(:snapshot_description_required?) |
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 I always prefer try!
over try
, cause the former one will raise an exception if you call it on nil.
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 seems to be the opposite of what i want here,
http://api.rubyonrails.org/classes/Object.html#method-i-try-21
"try! - Same as try, but raises a NoMethodError exception if the receiver is not nil and does not implement the tried method."
All other providers do not currently implement this method so I just want it to return nil rather then throw an exception.
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.
oh, you are absolutely right! so scratch that. It was just a reflex 😄
When creating a snapshot on RHV one has to write a description else the operation will fail. So one should not be able to start the "create snapshot" operation without writing the description. https://bugzilla.redhat.com/show_bug.cgi?id=1384517
cffd14b
to
06c8bc3
Compare
Checked commit borod108@06c8bc3 with ruby 2.2.5, rubocop 0.37.2, and haml-lint 0.16.1 |
@durandom there is a strange error from CI - https://travis-ci.org/ManageIQ/manageiq/jobs/176640356 |
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.
from me. Let's wait until CI works again
Nice solution @borod108 👍 |
Euwe Backport conflict: $ git cherry-pick -e -x -m 1 d643265
error: could not apply d643265... Merge pull request #12637 from borod108/bugs/1384517snapshot_desc_req
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'
$ git status
On branch euwe
Your branch is up-to-date with 'upstream/euwe'.
You are currently cherry-picking commit d643265.
(fix conflicts and run "git cherry-pick --continue")
(use "git cherry-pick --abort" to cancel the cherry-pick operation)
Changes to be committed:
modified: app/models/manageiq/providers/redhat/infra_manager/vm/operations/snapshot.rb
Unmerged paths:
(use "git add <file>..." to mark resolution)
both modified: app/controllers/vm_common.rb
$ git diff diff --cc app/controllers/vm_common.rb
index 8a684de,f05fe2a..0000000
--- a/app/controllers/vm_common.rb
+++ b/app/controllers/vm_common.rb
@@@ -585,15 -587,9 +599,21 @@@ module VmCommo
@name = params[:name]
@description = params[:description]
if params[:name].blank? && [email protected](:snapshot_name_optional?)
++<<<<<<< HEAD
+ add_flash(_("Name is required"), :error)
+ @in_a_form = true
+ drop_breadcrumb(:name => _("Snapshot VM '%{name}'") % {:name => @record.name}, :url => "/vm_common/snap")
+ if session[:edit] && session[:edit][:explorer]
+ @edit = session[:edit] # saving it to use in next transaction
+ render :partial => "shared/ajax/flash_msg_replace"
+ else
+ render :action => "snap"
+ end
++=======
+ render_missing_field(session, "Name")
+ elsif params[:description].blank? && @record.try(:snapshot_description_required?)
+ render_missing_field(session, "Description")
++>>>>>>> d643265... Merge pull request #12637 from borod108/bugs/1384517snapshot_desc_req
else
flash_error = false
# audit = {:event=>"vm_genealogy_change", :target_id=>@record.id, :target_class=>@record.class.base_class.name, :userid => session[:userid]} |
…desc_req Require a description when creating Snapshot (cherry picked from commit d643265)
Conflict resolution: #12742 |
Backported to Euwe via #12742 |
When creating a snapshot on RHV one has to write a description else
the operation will fail.
So one should not be able to start the "create snapshot" operation
without writing the description.
https://bugzilla.redhat.com/show_bug.cgi?id=1384517