ref: refs/heads/jr-yastmodel
commit b9e7eeda243613df839b90289c5f48061516f084
Author: Josef Reidinger
Date: Mon Dec 21 15:29:46 2009 +0100
fix permissions and move as example time plugin to YastModel
---
.../app/controllers/systemtime_controller.rb | 25 +++----------------
plugins/systemtime/app/models/stime.rb | 4 +++
webclient/lib/yast_model/base.rb | 16 +++++++-----
webclient/test/unit/yast_model_test.rb | 4 +-
4 files changed, 19 insertions(+), 30 deletions(-)
diff --git a/plugins/systemtime/app/controllers/systemtime_controller.rb b/plugins/systemtime/app/controllers/systemtime_controller.rb
index b4c2c9d..7fff4aa 100644
--- a/plugins/systemtime/app/controllers/systemtime_controller.rb
+++ b/plugins/systemtime/app/controllers/systemtime_controller.rb
@@ -65,19 +65,8 @@ class SystemtimeController < ApplicationController
# show flash with partial problem.
def index
@ntp = available_ntp
- systemtime = load_proxy 'org.opensuse.yast.modules.yapi.time'
-
- unless systemtime
- return false
- end
-
- unless @permissions[:read]
- logger.debug "No permissions for time module"
- flash[:warning] = _("No permissions for time module")
- redirect_to root_path
- return false
- end
-
+ systemtime = Stime.find :one
+ @permissions = Stime.permissions
@@timezones = systemtime.timezones
@timezone = systemtime.timezone
@utcstatus = systemtime.utcstatus
@@ -98,9 +87,7 @@ class SystemtimeController < ApplicationController
# still shows problems. Now it invalidate session for logged user.If
# everything goes fine it redirect to index
def update
- t = load_proxy 'org.opensuse.yast.modules.yapi.time'
-
- return false unless t
+ t = Stime.find :one
fill_proxy_with_timezone t, params, t.timezones
clear_time t #do nothing
@@ -146,11 +133,7 @@ class SystemtimeController < ApplicationController
# since while calling this function there is different instance of the class
# than when calling index, @@timezones were empty; reinitialize them
# possible FIXME: how does it increase the amount of data transferred?
- systemtime = load_proxy 'org.opensuse.yast.modules.yapi.time'
-
- unless systemtime
- return false #possible FIXME: is returnign false for AJAX correct?
- end
+ systemtime = Stime.find :one
@@timezones = systemtime.timezones
end
diff --git a/plugins/systemtime/app/models/stime.rb b/plugins/systemtime/app/models/stime.rb
new file mode 100644
index 0000000..540b6b5
--- /dev/null
+++ b/plugins/systemtime/app/models/stime.rb
@@ -0,0 +1,4 @@
+class Stime < ActiveResource::Base
+ extend YastModel::Base
+ model_interface :"org.opensuse.yast.modules.yapi.time"
+end
diff --git a/webclient/lib/yast_model/base.rb b/webclient/lib/yast_model/base.rb
index 5ccd297..c1f0adf 100644
--- a/webclient/lib/yast_model/base.rb
+++ b/webclient/lib/yast_model/base.rb
@@ -46,14 +46,16 @@ module YastModel
def permissions
return @permissions if @permissions
- YastModel::Permission.site = "#{self.site}/" #resource has constant prefix to allow introspect
+ YastModel::Permission.site = self.site #resource has constant prefix to allow introspect
+ YastModel::Permission.password = self.password #resource has constant prefix to allow introspect
permissions = YastModel::Permission.find :all, :params => { :user_id => YaST::ServiceResource::Session.login, :filter => @interface }
- granted = permissions.collect { |p| p.granted ? p.id : nil }
- granted.delete(nil)
- @permissions = granted.collect { |p|
- p.slice!("#{@interface}.")
- p.to_sym
- }
+ @permissions = {}
+ permissions.each do |p|
+ key = p.id
+ key.slice! "#{@interface}."
+ @permissions[key.to_sym] = p.granted
+ end
+ @permissions
end
end
end
diff --git a/webclient/test/unit/yast_model_test.rb b/webclient/test/unit/yast_model_test.rb
index c57ce66..c3205ae 100644
--- a/webclient/test/unit/yast_model_test.rb
+++ b/webclient/test/unit/yast_model_test.rb
@@ -47,7 +47,7 @@ TEST2_STRING = "test2"
def setup
ActiveResource::HttpMock.respond_to do |mock|
mock.get "/resources.xml", {}, RESOURCE_RESPONSE, 200
- mock.get "//permissions.xml?filter=org.opensuse.yast.modules.test&user_id=test", {}, PERMISSION_RESPONSE,200
+ mock.get "/permissions.xml?filter=org.opensuse.yast.modules.test&user_id=test", {"Authorization"=>"Basic OjEyMzQ="}, PERMISSION_RESPONSE,200
mock.get "/test.xml", {"Authorization"=>"Basic OjEyMzQ="}, TEST_RESPONSE, 200
mock.post "/test.xml", {"Authorization"=>"Basic OjEyMzQ="}, TEST_RESPONSE, 200
mock.get "/test2.xml", {"Authorization"=>"Basic OjEyMzQ="}, TEST2_RESPONSE, 200
@@ -95,7 +95,7 @@ end
def test_permissions
perm = TestModel.permissions
- assert perm.include?(:synchronize), "permission is not available #{perm.inspect}"
+ assert perm[:synchronize], "permission is not granted #{perm.inspect}"
end
end
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org