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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions app/controllers/vm_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,20 @@ def snap
end
alias_method :vm_snapshot_add, :snap

def render_missing_field(session, missing_field_name)
add_flash(_("%{missing_field_name} is required") %
{:missing_field_name => missing_field_name}, :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
javascript_flash(:spinner_off => true)
else
render :action => "snap"
end
end

def snap_vm
@vm = @record = identify_record(params[:id], VmOrTemplate)
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

if params["cancel"] || params[:button] == "cancel"
Expand All @@ -573,15 +587,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)
@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
javascript_flash(:spinner_off => true)
else
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 😄

render_missing_field(session, "Description")
else
flash_error = false
# audit = {:event=>"vm_genealogy_change", :target_id=>@record.id, :target_class=>@record.class.base_class.name, :userid => session[:userid]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ def snapshot_name_optional?
true
end

def snapshot_description_required?
true
end

def validate_remove_all_snapshots
{:available => false, :message => _("Removing all snapshots is currently not supported")}
end
Expand Down