[Ovirt-devel] [PATCH server] use service layer for NIC controller. (revised)
Scott Seago
sseago at redhat.com
Thu May 14 18:55:03 UTC 2009
Signed-off-by: Scott Seago <sseago at redhat.com>
---
src/app/controllers/nic_controller.rb | 29 +++++++++---------------
src/app/services/nic_service.rb | 39 +++++++++++++++++++++++++++++++++
2 files changed, 50 insertions(+), 18 deletions(-)
create mode 100644 src/app/services/nic_service.rb
diff --git a/src/app/controllers/nic_controller.rb b/src/app/controllers/nic_controller.rb
index fdbda06..8387f1c 100644
--- a/src/app/controllers/nic_controller.rb
+++ b/src/app/controllers/nic_controller.rb
@@ -18,47 +18,40 @@
# also available at http://www.gnu.org/copyleft/gpl.html.
class NicController < ApplicationController
+ include NicService
# GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
verify :method => :post, :only => [ :destroy, :create, :update ],
:redirect_to => { :controller => 'dashboard' }
def show
- authorize_view
+ svc_show(params[:id])
end
def new
+ raise ActionError.new("Network Interfaces may not be edited via the web UI")
end
def create
+ raise ActionError.new("Network Interfaces may not be edited via the web UI")
end
def edit
+ raise ActionError.new("Network Interfaces may not be edited via the web UI")
end
def update
+ raise ActionError.new("Network Interfaces may not be edited via the web UI")
end
def destroy
+ raise ActionError.new("Network Interfaces may not be edited via the web UI")
end
- private
- #filter methods
- def pre_new
- flash[:notice] = 'Network Interfaces may not be edited via the web UI'
- redirect_to :controller => 'host', :action => 'show', :id => params[:host_id]
+ # FIXME: remove these when service transition is complete. these are here
+ # to keep from running permissions checks and other setup steps twice
+ def tmp_pre_update
end
- def pre_create
- flash[:notice] = 'Network Interfaces may not be edited via the web UI'
- redirect_to :controller => 'dashboard'
- end
- def pre_edit
- @nic = Nic.find(params[:id])
- flash[:notice] = 'Network Interfaces may not be edited via the web UI'
- redirect_to :action=> 'show', :id => @nic
- end
- def pre_show
- @nic = Nic.find(params[:id])
- set_perms(@nic.host.hardware_pool)
+ def tmp_authorize_admin
end
end
diff --git a/src/app/services/nic_service.rb b/src/app/services/nic_service.rb
new file mode 100644
index 0000000..12314a4
--- /dev/null
+++ b/src/app/services/nic_service.rb
@@ -0,0 +1,39 @@
+#
+# Copyright (C) 2009 Red Hat, Inc.
+# Written by Scott Seago <sseago at redhat.com>,
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+# MA 02110-1301, USA. A copy of the GNU General Public License is
+# also available at http://www.gnu.org/copyleft/gpl.html.
+# Mid-level API: Business logic around nics
+module NicService
+ include ApplicationService
+
+ # Load the Nic with +id+ for viewing
+ #
+ # === Instance variables
+ # [<tt>@nic</tt>] stores the Nic with +id+
+ # === Required permissions
+ # [<tt>Privilege::VIEW</tt>] on nic target's Pool
+ def svc_show(id)
+ lookup(id,Privilege::VIEW)
+ end
+
+ private
+ def lookup(id, priv)
+ @nic = Nic.find(id)
+ authorized!(priv, at nic.host.hardware_pool)
+ end
+
+end
--
1.6.0.6
More information about the ovirt-devel
mailing list