[Ovirt-devel] [PATCH server 3/4] Remove handle_auth_error since we use rescue_with now

David Lutterkort lutter at redhat.com
Mon May 4 23:15:49 UTC 2009


---
 src/app/controllers/application.rb               |   27 +--------------------
 src/app/controllers/storage_volume_controller.rb |    5 +++-
 src/app/controllers/vm_controller.rb             |   12 ++-------
 3 files changed, 9 insertions(+), 35 deletions(-)

diff --git a/src/app/controllers/application.rb b/src/app/controllers/application.rb
index 3902e78..638f9c0 100644
--- a/src/app/controllers/application.rb
+++ b/src/app/controllers/application.rb
@@ -111,36 +111,13 @@ class ApplicationController < ActionController::Base
   def authorize_action(privilege, msg=nil)
     msg ||= 'You have insufficient privileges to perform action.'
     unless authorized?(privilege)
-      handle_auth_error(msg)
+      handle_error(:message => msg,
+                   :title => "Access Denied", :status => :forbidden)
       false
     else
       true
     end
   end
-  def handle_auth_error(msg)
-    respond_to do |format|
-      format.html do
-        @title = "Access denied"
-        @errmsg = msg
-        @ajax = params[:ajax]
-        @nolayout = params[:nolayout]
-        if @ajax
-          render :template => 'layouts/popup-error', :layout => 'tabs-and-content'
-        elsif @nolayout
-          render :template => 'layouts/popup-error', :layout => 'help-and-content'
-        else
-          render :template => 'layouts/popup-error', :layout => 'popup'
-        end
-      end
-      format.json do
-        @json_hash ||= {}
-        @json_hash[:success] = false
-        @json_hash[:alert] = msg
-        render :json => @json_hash
-      end
-      format.xml { head :forbidden }
-    end
-  end
 
   def handle_perm_error(error)
     handle_error(:error => error, :status => :forbidden,
diff --git a/src/app/controllers/storage_volume_controller.rb b/src/app/controllers/storage_volume_controller.rb
index b6b0593..c6ce58d 100644
--- a/src/app/controllers/storage_volume_controller.rb
+++ b/src/app/controllers/storage_volume_controller.rb
@@ -112,7 +112,10 @@ class StorageVolumeController < ApplicationController
     @storage_volume = StorageVolume.find(params[:id])
     set_perms(@storage_volume.storage_pool.hardware_pool)
     unless authorized?(Privilege::MODIFY) and @storage_volume.storage_pool.user_subdividable
-      handle_auth_error("You do not have permission to delete this storage volume.")
+      handle_error(:message =>
+                   "You do not have permission to delete this storage volume.",
+                   :status => :forbidden,
+                   :title => "Access Denied")
     else
       alert, success = delete_volume_internal(@storage_volume)
       respond_to do |format|
diff --git a/src/app/controllers/vm_controller.rb b/src/app/controllers/vm_controller.rb
index ee6d79e..c276f0b 100644
--- a/src/app/controllers/vm_controller.rb
+++ b/src/app/controllers/vm_controller.rb
@@ -41,13 +41,9 @@ class VmController < ApplicationController
   end
 
   def show
-    begin
-      svc_show(params[:id])
-      @actions = @vm.get_action_hash(@user)
-      render :layout => 'selection'
-    rescue PermissionError => perm_error
-      handle_auth_error(perm_error.message)
-    end
+    svc_show(params[:id])
+    @actions = @vm.get_action_hash(@user)
+    render :layout => 'selection'
   end
 
   def add_to_smart_pool
@@ -65,8 +61,6 @@ class VmController < ApplicationController
     begin
       alert = svc_create(params[:vm], params[:start_now])
       render :json => { :object => "vm", :success => true, :alert => alert  }
-    rescue PermissionError => perm_error
-      handle_auth_error(perm_error.message)
     rescue Exception => error
       json_error("vm", @vm, error)
     end
-- 
1.6.0.6




More information about the ovirt-devel mailing list