Mailinglist Archive: yast-commit (883 mails)

< Previous Next >
[yast-commit] <rest-service> master : Factor-out role-based functionality from ApplicationController
  • From: Klaus Kämpf <kkaempf@xxxxxxx>
  • Date: Mon, 6 Jul 2009 15:04:22 +0200
  • Message-id: <E1MNnyP-0006EL-ER@xxxxxxxxxxxxxxxx>
ref: refs/heads/master
commit 70605582ef653b5d4390478601991f8f246c77df
Author: Klaus Kämpf <kkaempf@xxxxxxx>
Date: Mon Jul 6 15:04:22 2009 +0200

Factor-out role-based functionality from ApplicationController

Move the code to lib/yast_roles.rb and "include YastRoles" into
ApplicationController instead.
---
.../app/controllers/application_controller.rb | 52 +------------------
webservice/lib/yast_roles.rb | 54 ++++++++++++++++++++
2 files changed, 55 insertions(+), 51 deletions(-)

diff --git a/webservice/app/controllers/application_controller.rb
b/webservice/app/controllers/application_controller.rb
index e9203db..7c82c10 100644
--- a/webservice/app/controllers/application_controller.rb
+++ b/webservice/app/controllers/application_controller.rb
@@ -5,57 +5,7 @@ class ApplicationController < ActionController::Base

include AuthenticatedSystem

- # FIXME: move this to test/ if RAILS_ENV == 'test'
- USER_ROLES_CONFIG = "/etc/yast_user_roles"
-
- require 'polkit'
- include PolKit
-
-private
- def user_roles(user)
- return session['services'] unless session['user_roles'].nil?
-
- return [] unless File.exists?(USER_ROLES_CONFIG)
-
- IO.foreach( USER_ROLES_CONFIG ) do |line|
- line = line.chomp
- next if line[0] == "#"
- roles = line.split(/[\s,]+/)
- return roles if ( roles.size > 1 and roles[0] == user )
- end
- return []
- end
-
-public
-
- def permission_check(action)
- return true if ENV["RAILS_ENV"] == "test"
- return false if self.current_account==nil ||
self.current_account.login.size == 0
-
- begin
- if polkit_check( action, self.current_account.login) == :yes
- logger.debug "Action: #{action} User: #{self.current_account.login}
Result: ok"
- return true
- end
- rescue #caused by poolkit
- logger.error "ruby-polkit has returned an exception"
- end
- #checking roles
- roles = user_roles(self.current_account.login)
- roles.each do |role|
- begin
- if ( role != self.current_account.login and
- polkit_check( action, role) == :yes)
- logger.debug "Action: #{action} User:
#{self.current_account.login} WITH role #{role} Result: ok"
- return true
- end
- rescue #caused by poolkit
- logger.error "ruby-polkit has returned an exception"
- end
- end
- logger.debug "Action: #{action} User: #{self.current_account.login}
Result: NOT granted"
- return false
- end
+ include YastRoles

helper :all # include all helpers, all the time

diff --git a/webservice/lib/yast_roles.rb b/webservice/lib/yast_roles.rb
new file mode 100644
index 0000000..0cd00a2
--- /dev/null
+++ b/webservice/lib/yast_roles.rb
@@ -0,0 +1,54 @@
+module YastRoles
+
+ # FIXME: move this to test/ if RAILS_ENV == 'test'
+ USER_ROLES_CONFIG = "/etc/yast_user_roles"
+
+ require 'polkit'
+ include PolKit
+
+private
+ def user_roles(user)
+ return session['services'] unless session['user_roles'].nil?
+
+ return [] unless File.exists?(USER_ROLES_CONFIG)
+
+ IO.foreach( USER_ROLES_CONFIG ) do |line|
+ line = line.chomp
+ next if line[0] == "#"
+ roles = line.split(/[\s,]+/)
+ return roles if ( roles.size > 1 and roles[0] == user )
+ end
+ return []
+ end
+
+public
+
+ def permission_check(action)
+ return true if ENV["RAILS_ENV"] == "test"
+ return false if self.current_account==nil ||
self.current_account.login.size == 0
+
+ begin
+ if polkit_check( action, self.current_account.login) == :yes
+ logger.debug "Action: #{action} User: #{self.current_account.login}
Result: ok"
+ return true
+ end
+ rescue #caused by poolkit
+ logger.error "ruby-polkit has returned an exception"
+ end
+ #checking roles
+ roles = user_roles(self.current_account.login)
+ roles.each do |role|
+ begin
+ if ( role != self.current_account.login and
+ polkit_check( action, role) == :yes)
+ logger.debug "Action: #{action} User:
#{self.current_account.login} WITH role #{role} Result: ok"
+ return true
+ end
+ rescue #caused by poolkit
+ logger.error "ruby-polkit has returned an exception"
+ end
+ end
+ logger.debug "Action: #{action} User: #{self.current_account.login}
Result: NOT granted"
+ return false
+ end
+end
--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages