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

Require a description when creating Snapshot #12637

Merged
merged 1 commit into from
Nov 17, 2016

Conversation

borod108
Copy link

@borod108 borod108 commented Nov 15, 2016

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

@borod108
Copy link
Author

@masayag please review.

@borod108 borod108 force-pushed the bugs/1384517snapshot_desc_req branch from aae2270 to 41dd7b8 Compare November 15, 2016 14:59
Copy link
Contributor

@masayag masayag left a 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]
Copy link
Contributor

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.

Copy link
Author

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

Copy link
Contributor

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

Copy link
Author

Choose a reason for hiding this comment

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

done, tnx!

@borod108 borod108 force-pushed the bugs/1384517snapshot_desc_req branch from 41dd7b8 to 0fd3268 Compare November 16, 2016 09:22
Copy link
Contributor

@masayag masayag left a comment

Choose a reason for hiding this comment

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

👍 LGTM

@borod108 borod108 force-pushed the bugs/1384517snapshot_desc_req branch 2 times, most recently from 30be3b0 to cffd14b Compare November 16, 2016 10:45
@borod108
Copy link
Author

@miq-bot assign @durandom

@oourfali
Copy link

@miq-bot add_label blocker

@oourfali
Copy link

@durandom please review ASAP to merge this blocker.

@oourfali
Copy link

@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")
Copy link
Member

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'

Copy link
Author

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!

Copy link
Member

@durandom durandom left a 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)
Copy link
Member

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

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

Copy link
Author

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 :)

Copy link
Member

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

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.

Copy link
Author

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.

Copy link
Member

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
@borod108 borod108 force-pushed the bugs/1384517snapshot_desc_req branch from cffd14b to 06c8bc3 Compare November 17, 2016 09:10
@miq-bot
Copy link
Member

miq-bot commented Nov 17, 2016

Checked commit borod108@06c8bc3 with ruby 2.2.5, rubocop 0.37.2, and haml-lint 0.16.1
2 files checked, 0 offenses detected
Everything looks good. 🍪

@borod108
Copy link
Author

@durandom there is a strange error from CI - https://travis-ci.org/ManageIQ/manageiq/jobs/176640356
I will close and reopen the PR.
If this error is nothing to worry about can it please be merged?

@borod108 borod108 closed this Nov 17, 2016
@borod108 borod108 reopened this Nov 17, 2016
Copy link
Member

@durandom durandom left a comment

Choose a reason for hiding this comment

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

:shipit: from me. Let's wait until CI works again

@borod108 borod108 closed this Nov 17, 2016
@borod108 borod108 reopened this Nov 17, 2016
@durandom
Copy link
Member

@miq-bot assign @agrare
@agrare please merge

@miq-bot miq-bot assigned agrare and unassigned durandom Nov 17, 2016
@agrare
Copy link
Member

agrare commented Nov 17, 2016

Nice solution @borod108 👍

@agrare agrare merged commit d643265 into ManageIQ:master Nov 17, 2016
@agrare agrare added this to the Sprint 50 Ending Dec 5, 2016 milestone Nov 17, 2016
@agrare agrare added the bug label Nov 17, 2016
@chessbyte
Copy link
Member

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]}

borod108 pushed a commit to borod108/manageiq that referenced this pull request Nov 18, 2016
…desc_req

Require a description when creating Snapshot
(cherry picked from commit d643265)
@borod108
Copy link
Author

Conflict resolution: #12742

@chessbyte
Copy link
Member

Backported to Euwe via #12742

@chessbyte
Copy link
Member

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