declarative_authorization 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG
CHANGED
@@ -60,6 +60,14 @@ module Authorization
|
|
60
60
|
def self.default_role= (role)
|
61
61
|
@@default_role = role.to_sym
|
62
62
|
end
|
63
|
+
|
64
|
+
def self.is_a_association_proxy? (object)
|
65
|
+
if Rails.version < "3.2"
|
66
|
+
object.respond_to?(:proxy_reflection)
|
67
|
+
else
|
68
|
+
object.respond_to?(:proxy_association)
|
69
|
+
end
|
70
|
+
end
|
63
71
|
|
64
72
|
# Authorization::Engine implements the reference monitor. It may be used
|
65
73
|
# for querying the permission and retrieving obligations under which
|
@@ -155,7 +163,7 @@ module Authorization
|
|
155
163
|
#
|
156
164
|
# Example: permit!( :edit, :object => user.posts )
|
157
165
|
#
|
158
|
-
if options[:object]
|
166
|
+
if Authorization.is_a_association_proxy?(options[:object]) && options[:object].respond_to?(:new)
|
159
167
|
options[:object] = options[:object].new
|
160
168
|
end
|
161
169
|
|
@@ -170,7 +170,7 @@ module Authorization
|
|
170
170
|
context = object = nil
|
171
171
|
if object_or_sym.nil?
|
172
172
|
context = self.class.decl_auth_context
|
173
|
-
elsif !
|
173
|
+
elsif !Authorization.is_a_association_proxy?(object_or_sym) and object_or_sym.is_a?(Symbol)
|
174
174
|
context = object_or_sym
|
175
175
|
else
|
176
176
|
object = object_or_sym
|
@@ -140,9 +140,13 @@ module Authorization
|
|
140
140
|
# Returns the model associated with the given path.
|
141
141
|
def model_for (path)
|
142
142
|
reflection = reflection_for(path)
|
143
|
-
|
144
|
-
if
|
145
|
-
|
143
|
+
|
144
|
+
if Authorization.is_a_association_proxy?(reflection)
|
145
|
+
if Rails.version < "3.2"
|
146
|
+
reflection.proxy_reflection.klass
|
147
|
+
else
|
148
|
+
reflection.proxy_association.reflection.klass
|
149
|
+
end
|
146
150
|
elsif reflection.respond_to?(:klass)
|
147
151
|
reflection.klass
|
148
152
|
else
|
@@ -167,7 +171,7 @@ module Authorization
|
|
167
171
|
|
168
172
|
reflection = path.empty? ? top_level_model : begin
|
169
173
|
parent = reflection_for( path[0..-2] )
|
170
|
-
if !
|
174
|
+
if !Authorization.is_a_association_proxy?(parent) and parent.respond_to?(:klass)
|
171
175
|
parent.klass.reflect_on_association( path.last )
|
172
176
|
else
|
173
177
|
parent.reflect_on_association( path.last )
|
@@ -182,7 +186,7 @@ module Authorization
|
|
182
186
|
|
183
187
|
# Claim alias for join table
|
184
188
|
# TODO change how this is checked
|
185
|
-
if !
|
189
|
+
if !Authorization.is_a_association_proxy?(reflection) and !reflection.respond_to?(:proxy_scope) and reflection.is_a?(ActiveRecord::Reflection::ThroughReflection)
|
186
190
|
join_table_path = path[0..-2] + [reflection.options[:through]]
|
187
191
|
reflection_for(join_table_path, true)
|
188
192
|
end
|
data/test/model_test.rb
CHANGED
@@ -88,7 +88,11 @@ class TestModelSecurityModel < ActiveRecord::Base
|
|
88
88
|
using_access_control
|
89
89
|
end
|
90
90
|
class TestModelSecurityModelWithFind < ActiveRecord::Base
|
91
|
-
|
91
|
+
if Rails.version < "3.2"
|
92
|
+
set_table_name "test_model_security_models"
|
93
|
+
else
|
94
|
+
self.table_name = "test_model_security_models"
|
95
|
+
end
|
92
96
|
has_many :test_attrs
|
93
97
|
belongs_to :test_attr
|
94
98
|
using_access_control :include_read => true,
|
@@ -209,6 +213,9 @@ class NamedScopeModelTest < Test::Unit::TestCase
|
|
209
213
|
end
|
210
214
|
}
|
211
215
|
Authorization::Engine.instance(reader)
|
216
|
+
TestModel.delete_all
|
217
|
+
TestAttrThrough.delete_all
|
218
|
+
TestAttr.delete_all
|
212
219
|
|
213
220
|
allowed_model = TestModel.create!
|
214
221
|
allowed_model.test_attrs.create!(:attr => 1).test_attr_throughs.create!
|
@@ -383,6 +390,7 @@ class NamedScopeModelTest < Test::Unit::TestCase
|
|
383
390
|
end
|
384
391
|
}
|
385
392
|
Authorization::Engine.instance(reader)
|
393
|
+
TestModel.delete_all
|
386
394
|
|
387
395
|
test_model_1 = TestModel.create!
|
388
396
|
TestModel.create!
|
@@ -911,6 +919,9 @@ class NamedScopeModelTest < Test::Unit::TestCase
|
|
911
919
|
end
|
912
920
|
}
|
913
921
|
Authorization::Engine.instance(reader)
|
922
|
+
TestModel.delete_all
|
923
|
+
TestAttrThrough.delete_all
|
924
|
+
TestAttr.delete_all
|
914
925
|
|
915
926
|
test_attr_through_1 = TestAttrThrough.create!
|
916
927
|
test_item = NWayJoinItem.create!
|
@@ -1061,6 +1072,8 @@ class NamedScopeModelTest < Test::Unit::TestCase
|
|
1061
1072
|
end
|
1062
1073
|
}
|
1063
1074
|
Authorization::Engine.instance(reader)
|
1075
|
+
TestModel.delete_all
|
1076
|
+
TestAttr.delete_all
|
1064
1077
|
|
1065
1078
|
test_model_1 = TestModel.create!
|
1066
1079
|
test_model_2 = TestModel.create!
|
@@ -1803,6 +1816,9 @@ class ModelTest < Test::Unit::TestCase
|
|
1803
1816
|
end
|
1804
1817
|
}
|
1805
1818
|
Authorization::Engine.instance(reader)
|
1819
|
+
TestModel.delete_all
|
1820
|
+
TestAttr.delete_all
|
1821
|
+
TestAttrThrough.delete_all
|
1806
1822
|
|
1807
1823
|
test_model_1 = TestModel.create! :content => 'test_1'
|
1808
1824
|
test_model_2 = TestModel.create! :content => 'test_2'
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 5
|
8
|
-
-
|
9
|
-
version: 0.5.
|
8
|
+
- 5
|
9
|
+
version: 0.5.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Steffen Bartsch
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2012-01-10 00:00:00 +01:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|