Mailinglist Archive: yast-commit (2114 mails)

< Previous Next >
[yast-commit] <rest-service> jr_ntp : Using yapi_perm_check, in before_filter.
  • From: Martin Vidner <mvidner@xxxxxxx>
  • Date: Mon, 7 Sep 2009 09:33:55 +0200
  • Message-id: <E1MpkqE-0004r7-MB@xxxxxxxxxxxxxxxx>
ref: refs/heads/jr_ntp
commit b1668984faf91691ed5457b7dd4aade613f4060a
Author: Martin Vidner <mvidner@xxxxxxx>
Date: Mon Sep 7 09:33:55 2009 +0200

Using yapi_perm_check, in before_filter.

yapi_perm_check is from caa6a1a1ebca6f47cb7272e4965cbf3392fe3993

before_filter can use an inline method, nice. The |c| parameter is
the controller

http://api.rubyonrails.org/classes/ActionController/Filters/ClassMethods.html
---
.../app/controllers/network/dns_controller.rb | 11 ++---------
.../app/controllers/network/hostname_controller.rb | 11 ++---------
.../controllers/network/interfaces_controller.rb | 14 ++------------
.../app/controllers/network/routes_controller.rb | 16 ++--------------
4 files changed, 8 insertions(+), 44 deletions(-)

diff --git a/plugins/network/app/controllers/network/dns_controller.rb
b/plugins/network/app/controllers/network/dns_controller.rb
index fa13f91..5740878 100644
--- a/plugins/network/app/controllers/network/dns_controller.rb
+++ b/plugins/network/app/controllers/network/dns_controller.rb
@@ -4,13 +4,11 @@
class Network::DnsController < ApplicationController

before_filter :login_required
+ before_filter(:only => [:show]) { |c| c.yapi_perm_check "network.read" }
+ before_filter(:only => [:create, :update]) { |c| c.yapi_perm_check
"network.write"}

# Sets hostname settings. Requires write permissions for network YaPI.
def update
- unless permission_check( "org.opensuse.yast.modules.yapi.network.write")
- render ErrorResult.error(403, 1, "no permission") and return
- end
-
root = params[:hostname]
if root == nil
render ErrorResult.error(404, 2, "format or internal error") and return
@@ -28,11 +26,6 @@ class Network::DnsController < ApplicationController

# Shows hostname settings. Requires read permission for network YaPI.
def show
-
- unless permission_check( "org.opensuse.yast.modules.yapi.network.read")
- render ErrorResult.error( 403, 1, "no permission" ) and return
- end
-
@dns = DNS.find

respond_to do |format|
diff --git a/plugins/network/app/controllers/network/hostname_controller.rb
b/plugins/network/app/controllers/network/hostname_controller.rb
index d25ec82..d85c006 100644
--- a/plugins/network/app/controllers/network/hostname_controller.rb
+++ b/plugins/network/app/controllers/network/hostname_controller.rb
@@ -5,13 +5,11 @@
class Network::HostnameController < ApplicationController

before_filter :login_required
+ before_filter(:only => [:show]) { |c| c.yapi_perm_check "network.read" }
+ before_filter(:only => [:create, :update]) { |c| c.yapi_perm_check
"network.write"}

# Sets hostname settings. Requires write permissions for network YaPI.
def update
- unless permission_check( "org.opensuse.yast.modules.yapi.network.write")
- render ErrorResult.error(403, 1, "no permission") and return
- end
-
root = params[:hostname]
if root == nil
render ErrorResult.error(404, 2, "format or internal error") and return
@@ -29,11 +27,6 @@ class Network::HostnameController < ApplicationController

# Shows hostname settings. Requires read permission for network YaPI.
def show
-
- unless permission_check( "org.opensuse.yast.modules.yapi.network.read")
- render ErrorResult.error( 403, 1, "no permission" ) and return
- end
-
@hostname = Hostname.find

respond_to do |format|
diff --git a/plugins/network/app/controllers/network/interfaces_controller.rb
b/plugins/network/app/controllers/network/interfaces_controller.rb
index 1e10b0e..4dea4a7 100644
--- a/plugins/network/app/controllers/network/interfaces_controller.rb
+++ b/plugins/network/app/controllers/network/interfaces_controller.rb
@@ -4,13 +4,11 @@
class Network::InterfacesController < ApplicationController

before_filter :login_required
+ before_filter(:only => [:index, :show]) { |c| c.yapi_perm_check
"network.read" }
+ before_filter(:only => [:create, :update]) { |c| c.yapi_perm_check
"network.write"}

# Sets hostname settings. Requires write permissions for network YaPI.
def update
- unless permission_check( "org.opensuse.yast.modules.yapi.network.write")
- render ErrorResult.error(403, 1, "no permission") and return
- end
-
root = params[:interfaces]
if root == nil
render ErrorResult.error(404, 2, "format or internal error") and return
@@ -28,11 +26,6 @@ class Network::InterfacesController < ApplicationController

# Shows hostname settings. Requires read permission for network YaPI.
def show
-
- unless permission_check( "org.opensuse.yast.modules.yapi.network.read")
- render ErrorResult.error( 403, 1, "no permission" ) and return
- end
-
@ifce = Interface.find(params[:id])

respond_to do |format|
@@ -43,9 +36,6 @@ class Network::InterfacesController < ApplicationController
end

def index
- unless permission_check( "org.opensuse.yast.modules.yapi.network.read")
- render ErrorResult.error( 403, 1, "no permission" ) and return
- end
@interfaces = Interface.find_all
end

diff --git a/plugins/network/app/controllers/network/routes_controller.rb
b/plugins/network/app/controllers/network/routes_controller.rb
index 327c6be..d66f0f8 100644
--- a/plugins/network/app/controllers/network/routes_controller.rb
+++ b/plugins/network/app/controllers/network/routes_controller.rb
@@ -4,20 +4,8 @@
class Network::RoutesController < ApplicationController

before_filter :login_required
- before_filter :read_check, :only => [:index, :show]
- before_filter :write_check, :only => [:create, :update]
-
- def read_check
- unless permission_check( "org.opensuse.yast.modules.yapi.network.read")
- render ErrorResult.error( 403, 1, "no permission" )
- end
- end
-
- def write_check
- unless permission_check( "org.opensuse.yast.modules.yapi.network.write")
- render ErrorResult.error(403, 1, "no permission")
- end
- end
+ before_filter(:only => [:index, :show]) { |c| c.yapi_perm_check
"network.read" }
+ before_filter(:only => [:create, :update]) { |c| c.yapi_perm_check
"network.write"}

# Sets route settings. Requires write permissions for network YaPI.
def update
--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages