Skip to content

Commit

Permalink
Merge pull request ManageIQ#3643 from martinpovolny/flash_no_session
Browse files Browse the repository at this point in the history
Do not pass flash messages in the URL.
  • Loading branch information
mzazrivec authored Mar 29, 2018
2 parents 796d2c5 + 48c073a commit 6d51300
Show file tree
Hide file tree
Showing 56 changed files with 215 additions and 249 deletions.
3 changes: 1 addition & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -823,8 +823,7 @@ def calculate_lastaction(lastaction)
end

def report_edit_aborted(lastaction)
add_flash(_("Edit aborted! %{product} does not support the browser's back button or access from multiple tabs or windows of the same browser. Please close any duplicate sessions before proceeding.") % {:product => Vmdb::Appliance.PRODUCT_NAME}, :error)
session[:flash_msgs] = @flash_array.dup
flash_to_session(_("Edit aborted! %{product} does not support the browser's back button or access from multiple tabs or windows of the same browser. Please close any duplicate sessions before proceeding.") % {:product => Vmdb::Appliance.PRODUCT_NAME}, :error)
if request.xml_http_request? # Is this an Ajax request?
if lastaction == "configuration"
edit
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/application_controller/ci_processing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ def identify_record(id, klass = self.class.model)
record = find_record_with_rbac(klass, id)
rescue => @bang
self.x_node = "root" if @explorer
add_flash(@bang.message, :error, true)
session[:flash_msgs] = @flash_array.dup
flash_to_session(@bang.message, :error, true)
end
record
end
Expand Down
32 changes: 16 additions & 16 deletions app/controllers/application_controller/dialog_runner.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
module ApplicationController::DialogRunner
extend ActiveSupport::Concern

def redirect_url(flash)
def redirect_url
model = self.class.model
if restful_routed?(model)
polymorphic_path(model.find(session[:edit][:target_id]), :flash_msg => flash)
polymorphic_path(model.find(session[:edit][:target_id]))
else
{:action => 'show', :id => session[:edit][:target_id], :flash_msg => flash}
{:action => 'show', :id => session[:edit][:target_id]}
end
end

def dialog_cancel_form(flash = nil)
@sb[:action] = @edit = nil
@in_a_form = false
add_flash(flash) if flash.present?
if session[:edit][:explorer]
add_flash(flash)
dialog_replace_right_cell
else
javascript_redirect redirect_url(flash)
flash_to_session
javascript_redirect(redirect_url)
end
end

Expand All @@ -41,40 +42,39 @@ def dialog_form_button_pressed
else
if result[:errors].present?
# show validation errors
result[:errors].each do |err|
add_flash(err, :error)
end
result[:errors].each { |err| add_flash(err, :error) }
javascript_flash(:spinner_off => true)
else
flash = _("Order Request was Submitted")
add_flash(_("Order Request was Submitted"))
if role_allows?(:feature => "miq_request_show_list", :any => true)
@sb[:action] = @edit = nil
@in_a_form = false
if session[:edit][:explorer]
add_flash(flash)
if result[:request].nil?
dialog_replace_right_cell
else
flash_to_session
javascript_redirect :controller => 'miq_request',
:action => 'show_list',
:flash_msg => flash
:action => 'show_list'
end
else
javascript_redirect redirect_url(flash)
flash_to_session
javascript_redirect(redirect_url)
end
else
dialog_cancel_form(flash)
dialog_cancel_form
end
end
end
when "reset" # Reset
dialog_reset_form
flash = _("All changes have been reset")
add_flash(flash, :warning)
if session[:edit][:explorer]
add_flash(flash, :warning)
replace_right_cell(:action => "dialog_provision")
else
javascript_redirect :action => 'dialog_load', :flash_msg => flash, :flash_warning => true, :escape => false # redirect to miq_request show_list screen
flash_to_session
javascript_redirect(:action => 'dialog_load', :escape => false) # redirect to miq_request show_list screen
end
else
return unless load_edit("dialog_edit__#{params[:id]}", "replace_cell__explorer")
Expand Down
20 changes: 10 additions & 10 deletions app/controllers/application_controller/miq_request_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ def pre_prov_continue
# Pre provisioning, select a template
def pre_prov
if params[:button] == "cancel"
add_flash(_("Add of new %{type} Request was cancelled by the user") % {:type => session[:edit][:prov_type]})
session[:flash_msgs] = @flash_array.dup unless session[:edit][:explorer] # Put msg in session for next transaction to display
flash_to_session(_("Add of new %{type} Request was cancelled by the user") % {:type => session[:edit][:prov_type]})
@explorer = session[:edit][:explorer] ? session[:edit][:explorer] : false
@edit = session[:edit] = nil # Clear out session[:edit]
prov_request_cancel_submit_response
Expand Down Expand Up @@ -182,13 +181,14 @@ def get_template_kls
def prov_edit
if params[:button] == "cancel"
req = MiqRequest.find_by_id(session[:edit][:req_id]) if session[:edit] && session[:edit][:req_id]
add_flash(if req && req.id
_("Edit of %{model} Request \"%{name}\" was cancelled by the user") %
{:model => session[:edit][:prov_type], :name => req.description}
else
_("Provision %{type} Request was cancelled by the user") % {:type => session[:edit][:prov_type]}
end)
session[:flash_msgs] = @flash_array.dup unless session[:edit][:explorer] # Put msg in session for next transaction to display
flash_to_session(
if req && req.id
_("Edit of %{model} Request \"%{name}\" was cancelled by the user") %
{:model => session[:edit][:prov_type], :name => req.description}
else
_("Provision %{type} Request was cancelled by the user") % {:type => session[:edit][:prov_type]}
end
)
@explorer = session[:edit][:explorer] ? session[:edit][:explorer] : false
@edit = session[:edit] = nil # Clear out session[:edit]
@breadcrumbs.pop if @breadcrumbs
Expand Down Expand Up @@ -624,7 +624,7 @@ def prov_req_submit
add_flash(flash_message)

if role_allows?(:feature => "miq_request_show_list", :any => true)
session[:flash_msgs] = @flash_array.dup
flash_to_session
javascript_redirect :controller => 'miq_request',
:action => 'show_list',
:typ => org_controller
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller/tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def tagging_edit_tags_save
replace_right_cell
else
@edit = nil
session[:flash_msgs] = @flash_array.dup # Put msg in session for next transaction to display
flash_to_session
javascript_redirect previous_breadcrumb_url
end
end
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/auth_key_pair_cloud_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ def create_finished

@breadcrumbs.pop if @breadcrumbs
session[:edit] = nil
session[:flash_msgs] = @flash_array.dup if @flash_array

flash_to_session
javascript_redirect :action => "show_list"
end

Expand Down
3 changes: 2 additions & 1 deletion app/controllers/chargeback_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ def cb_rate_form_field_changed
def cb_rate_show
@display = "main"
if @record.nil?
redirect_to :action => "cb_rates_list", :flash_msg => _("Error: Record no longer exists in the database"), :flash_error => true
flash_to_session(_('Error: Record no longer exists in the database'), :error)
redirect_to(:action => 'cb_rates_list')
return
end
end
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/cloud_network_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def create_finished

@breadcrumbs.pop if @breadcrumbs
session[:edit] = nil
session[:flash_msgs] = @flash_array.dup if @flash_array
flash_to_session
javascript_redirect :action => "show_list"
end

Expand Down Expand Up @@ -130,7 +130,7 @@ def delete_networks
if @flash_array.nil?
add_flash(_("The selected Cloud Network was deleted"))
end
session[:flash_msgs] = @flash_array.dup if @flash_array
flash_to_session
end
end

Expand Down Expand Up @@ -203,7 +203,7 @@ def update_finished
end

session[:edit] = nil
session[:flash_msgs] = @flash_array.dup if @flash_array
flash_to_session
javascript_redirect previous_breadcrumb_url
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/cloud_object_store_container_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def create_finished
}, :error)
end

session[:flash_msgs] = @flash_array.dup if @flash_array
flash_to_session
javascript_redirect previous_breadcrumb_url
end

Expand Down
9 changes: 5 additions & 4 deletions app/controllers/cloud_subnet_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def create_finished

@breadcrumbs.pop if @breadcrumbs
session[:edit] = nil
session[:flash_msgs] = @flash_array.dup if @flash_array
flash_to_session
javascript_redirect :action => "show_list"
end

Expand Down Expand Up @@ -134,10 +134,11 @@ def delete_subnets
if @flash_array.nil?
add_flash(_("The selected Cloud Subnet was deleted"))
end
javascript_redirect :action => 'show_list', :flash_msg => @flash_array[0][:message]
flash_to_session
javascript_redirect(:action => 'show_list')
else
drop_breadcrumb(:name => 'dummy', :url => " ") # missing a bc to get correctly back so here's a dummy
session[:flash_msgs] = @flash_array.dup if @flash_array
flash_to_session
redirect_to(previous_breadcrumb_url)
end
end
Expand Down Expand Up @@ -196,7 +197,7 @@ def update_finished
end

session[:edit] = nil
session[:flash_msgs] = @flash_array.dup if @flash_array
flash_to_session
javascript_redirect previous_breadcrumb_url
end

Expand Down
9 changes: 4 additions & 5 deletions app/controllers/cloud_tenant_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ def create_finished

@breadcrumbs.pop if @breadcrumbs
session[:edit] = nil
session[:flash_msgs] = @flash_array.dup if @flash_array

flash_to_session
javascript_redirect :action => "show_list"
end

Expand Down Expand Up @@ -171,8 +170,7 @@ def update_finished

@breadcrumbs.pop if @breadcrumbs
session[:edit] = nil
session[:flash_msgs] = @flash_array.dup if @flash_array

flash_to_session
javascript_redirect :action => "show", :id => tenant_id
end

Expand Down Expand Up @@ -218,7 +216,8 @@ def delete_cloud_tenants
if flash_errors? # either show the errors and stay on the 'show'
render_flash
else # or (if we deleted what we were showing) we redirect to the listing
javascript_redirect :action => 'show_list', :flash_msg => @flash_array[0][:message]
flash_to_session
javascript_redirect(:action => 'show_list')
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/cloud_volume_backup_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def backup_restore_finished

@breadcrumbs.pop if @breadcrumbs
session[:edit] = nil
session[:flash_msgs] = @flash_array.dup if @flash_array
flash_to_session
javascript_redirect(:action => "show", :id => @backup.id)
end

Expand Down
20 changes: 8 additions & 12 deletions app/controllers/cloud_volume_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ def attach_finished

@breadcrumbs.pop if @breadcrumbs
session[:edit] = nil
session[:flash_msgs] = @flash_array.dup if @flash_array

flash_to_session
javascript_redirect :action => "show", :id => volume_id
end

Expand Down Expand Up @@ -178,8 +177,7 @@ def detach_finished

@breadcrumbs.pop if @breadcrumbs
session[:edit] = nil
session[:flash_msgs] = @flash_array.dup if @flash_array

flash_to_session
javascript_redirect :action => "show", :id => volume_id
end

Expand Down Expand Up @@ -258,8 +256,7 @@ def create_finished
end

session[:edit] = nil
session[:flash_msgs] = @flash_array.dup if @flash_array

flash_to_session
javascript_redirect previous_breadcrumb_url
end

Expand Down Expand Up @@ -330,8 +327,7 @@ def update_finished

@breadcrumbs.pop if @breadcrumbs
session[:edit] = nil
session[:flash_msgs] = @flash_array.dup if @flash_array

flash_to_session
javascript_redirect :action => "show", :id => volume_id
end

Expand Down Expand Up @@ -368,7 +364,7 @@ def delete_volumes
@single_delete = true unless flash_errors?
else
drop_breadcrumb(:name => 'dummy', :url => " ") # missing a bc to get correctly back so here's a dummy
session[:flash_msgs] = @flash_array.dup if @flash_array
flash_to_session
redirect_to(previous_breadcrumb_url)
end
end
Expand Down Expand Up @@ -428,7 +424,7 @@ def backup_create_finished

@breadcrumbs.pop if @breadcrumbs
session[:edit] = nil
session[:flash_msgs] = @flash_array.dup if @flash_array
flash_to_session
javascript_redirect :action => "show", :id => @volume.id
end

Expand Down Expand Up @@ -485,7 +481,7 @@ def backup_restore_finished

@breadcrumbs.pop if @breadcrumbs
session[:edit] = nil
session[:flash_msgs] = @flash_array.dup if @flash_array
flash_to_session
javascript_redirect :action => "show", :id => @volume.id
end

Expand Down Expand Up @@ -540,7 +536,7 @@ def snapshot_create_finished
end
@breadcrumbs.pop if @breadcrumbs
session[:edit] = nil
session[:flash_msgs] = @flash_array.dup if @flash_array
flash_to_session
javascript_redirect :action => "show", :id => @volume.id
end

Expand Down
6 changes: 2 additions & 4 deletions app/controllers/configuration_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,8 @@ def timeprofile_update
@timeprofile = TimeProfile.new
end
if params[:button] == "cancel"
add_flash(_("Edit of Time Profile \"%{name}\" was cancelled by the user") % {:name => @timeprofile.description})
params[:id] = @timeprofile.id.to_s
session[:flash_msgs] = @flash_array.dup # Put msgs in session for next transaction
flash_to_session(_("Edit of Time Profile \"%{name}\" was cancelled by the user") % {:name => @timeprofile.description})
javascript_redirect :action => 'change_tab', :typ => "timeprofiles", :tab => 4, :id => @timeprofile.id.to_s
elsif params[:button] == "save"
if params[:all_days] == 'true'
Expand Down Expand Up @@ -389,8 +388,7 @@ def timeprofile_update
else
construct_edit_for_audit(@timeprofile)
AuditEvent.success(build_created_audit(@timeprofile, @edit))
add_flash(_("Time Profile \"%{name}\" was saved") % {:name => @timeprofile.description})
session[:flash_msgs] = @flash_array.dup # Put msgs in session for next transaction
flash_to_session(_("Time Profile \"%{name}\" was saved") % {:name => @timeprofile.description})
javascript_redirect :action => 'change_tab', :typ => "timeprofiles", :tab => 4, :id => @timeprofile.id.to_s
end
end
Expand Down
4 changes: 3 additions & 1 deletion app/controllers/ems_cloud_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ def sync_users
password_digest = nil
password_digest = BCrypt::Password.create(selected_password) unless selected_password.blank?
ems.sync_users_queue(session[:userid], selected_admin_role, selected_member_role, password_digest)
redirect_to(ems_cloud_path(params[:id], :flash_msg => _("Sync users queued.")))

flash_to_session(_("Sync users queued."))
redirect_to(ems_cloud_path(params[:id]))
end
else
render_sync_page(ems, selected_admin_role, selected_member_role, selected_password, selected_verify)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/ems_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def button

return if params[:pressed].include?("tag") && !%w(host_tag vm_tag miq_template_tag instance_tag image_tag).include?(params[:pressed])
if params[:pressed].include?("orchestration_stack_delete")
session[:flash_msgs] = @flash_array.dup
flash_to_session
javascript_redirect(polymorphic_path(EmsCloud.find(params[:id]), :display => 'orchestration_stacks'))
return
end
Expand Down
Loading

0 comments on commit 6d51300

Please sign in to comment.