ref: refs/heads/jr-yastmodel
commit acbc131c52bb83c8a7ea652ec5d54e804b6472c6
Author: Josef Reidinger
Date: Mon Dec 21 14:58:28 2009 +0100
implement permissions for model
---
webclient/lib/yast_model/base.rb | 15 ++++++++++++++-
webclient/lib/yast_model/permission.rb | 4 ++++
webclient/test/unit/yast_model_test.rb | 9 +++++++--
3 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/webclient/lib/yast_model/base.rb b/webclient/lib/yast_model/base.rb
index c4db5c7..5ccd297 100644
--- a/webclient/lib/yast_model/base.rb
+++ b/webclient/lib/yast_model/base.rb
@@ -15,9 +15,10 @@ module YastModel
end
def set_site
+ @permissions = nil #reset permission as it can be for each site and for each user different
self.site = YaST::ServiceResource::Session.site
self.password = YaST::ServiceResource::Session.auth_token
- YastModel::Resource.site = "#{site}/" #resource has constant prefix to allow introspect
+ YastModel::Resource.site = "#{self.site}/" #resource has constant prefix to allow introspect
#FIXME not thread save
Rails.logger.debug "read interface to #{@interface.to_s}"
resource = YastModel::Resource.find(:all).find { |r| r.interface.to_sym == @interface.to_sym }
@@ -42,5 +43,17 @@ module YastModel
instantiate_record( (connection.get(path, headers)), prefix_options )
end
end
+
+ def permissions
+ return @permissions if @permissions
+ YastModel::Permission.site = "#{self.site}/" #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
+ }
+ end
end
end
diff --git a/webclient/lib/yast_model/permission.rb b/webclient/lib/yast_model/permission.rb
new file mode 100644
index 0000000..c8a1877
--- /dev/null
+++ b/webclient/lib/yast_model/permission.rb
@@ -0,0 +1,4 @@
+module YastModel
+ class Permission < ActiveResource::Base
+ end
+end
diff --git a/webclient/test/unit/yast_model_test.rb b/webclient/test/unit/yast_model_test.rb
index d1976e8..c57ce66 100644
--- a/webclient/test/unit/yast_model_test.rb
+++ b/webclient/test/unit/yast_model_test.rb
@@ -7,7 +7,7 @@ PERMISSION_RESPONSE= <"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
@@ -93,4 +93,9 @@ def test_mix_of_two_models
assert_equal "test2",Test2Model.collection_name
end
+def test_permissions
+ perm = TestModel.permissions
+ assert perm.include?(:synchronize), "permission is not available #{perm.inspect}"
+end
+
end
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org