Skip to content

Commit

Permalink
Use notification_link from decorators to redirect notification links
Browse files Browse the repository at this point in the history
  • Loading branch information
skateman committed Aug 27, 2018
1 parent 9cb7dd5 commit cb00a4a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 13 deletions.
20 changes: 7 additions & 13 deletions app/controllers/restful_redirect_controller.rb
@@ -1,19 +1,13 @@
class RestfulRedirectController < ApplicationController
before_action :check_privileges

def index
case params[:model]
when 'MiqRequest'
redirect_to :controller => 'miq_request', :action => 'show', :id => params[:id]
when 'VmOrTemplate'
klass = VmOrTemplate.select(:id, :type).find(params[:id]).try(:class)
controller = if klass && (VmCloud > klass || TemplateCloud > klass)
'vm_cloud'
else
'vm_infra'
end
redirect_to :controller => controller, :action => 'show', :id => params[:id]
redirect_params = params[:model].safe_constantize.try(:find, params[:id]).try(:decorate).try(:notification_link)
if redirect_params
redirect_to(redirect_params)
else
flash_to_session(_("Could not find %{model}[id=%{id}]") % {:model => params[:model], :id => params[:id]})
redirect_to(:controller => 'dashboard')
flash_to_session(_("Could not find the given \"%{model}\" record.") % {:model => ui_lookup(:model => params[:model])}, :error)
redirect_to(:controller => 'dashboard', :action => 'show')
end
end
end
4 changes: 4 additions & 0 deletions app/decorators/miq_request_decorator.rb
Expand Up @@ -7,4 +7,8 @@ def fonticon
"pficon pficon-error-circle-o"
end
end

def notification_link
{ :controller => 'miq_request', :action => 'show', :id => id }
end
end
@@ -0,0 +1,5 @@
class ServiceTemplateTransformationPlanRequestDecorator < MiqDecorator
def notification_link
nil
end
end
10 changes: 10 additions & 0 deletions app/decorators/vm_decorator.rb
Expand Up @@ -37,4 +37,14 @@ def single_quad
:fileicon => fileicon
}
end

def notification_link
klass = __getobj__.class
controller = if klass && (VmCloud > klass || TemplateCloud > klass)
'vm_cloud'
else
'vm_infra'
end
{ :controller => controller, :action => 'show', :id => id }
end
end

0 comments on commit cb00a4a

Please sign in to comment.