access_schema 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/access_schema/builders/namespace_builder.rb +1 -1
- data/lib/access_schema/element.rb +3 -3
- data/lib/access_schema/expectation.rb +2 -2
- data/lib/access_schema/proxy.rb +22 -12
- data/lib/access_schema/schema.rb +20 -7
- data/lib/access_schema/version.rb +1 -1
- data/spec/{assess_schema → access_schema}/config_builder_spec.rb +0 -0
- data/spec/{assess_schema → access_schema}/proxy_spec.rb +6 -1
- data/spec/{assess_schema → access_schema}/schema_builder_spec.rb +0 -0
- data/spec/{assess_schema → access_schema}/schema_spec.rb +0 -0
- metadata +10 -10
@@ -13,9 +13,9 @@ module AccessSchema
|
|
13
13
|
@expectations << expectation
|
14
14
|
end
|
15
15
|
|
16
|
-
def allow?(
|
17
|
-
@roles.
|
18
|
-
checklist = @expectations.select { |exp| exp.for?(
|
16
|
+
def allow?(roles)
|
17
|
+
(@roles & roles).size > 0 || begin
|
18
|
+
checklist = @expectations.select { |exp| exp.for?(roles) }
|
19
19
|
checklist.length > 0 && checklist.all? { |exp| yield(exp) }
|
20
20
|
end
|
21
21
|
end
|
data/lib/access_schema/proxy.rb
CHANGED
@@ -15,25 +15,35 @@ module AccessSchema
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def allow?(*args)
|
18
|
+
@schema.allow?(*normalize_args(args))
|
19
|
+
end
|
20
|
+
|
21
|
+
def require!(*args)
|
22
|
+
@schema.require!(*normalize_args(args))
|
23
|
+
end
|
24
|
+
|
25
|
+
def with_options(options)
|
26
|
+
Proxy.new(self, options)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def normalize_args(args)
|
18
32
|
namespace = args[0]
|
19
33
|
feature = args[1]
|
20
34
|
|
21
|
-
|
22
|
-
when
|
23
|
-
[
|
35
|
+
roles, options = case args[2]
|
36
|
+
when Hash, nil
|
37
|
+
[@options[:role] || @options[:plan], args[2] || {}]
|
24
38
|
else
|
25
|
-
[
|
39
|
+
[args[2], args[3] || {}]
|
26
40
|
end
|
27
41
|
|
28
|
-
|
29
|
-
|
42
|
+
options_to_pass = @options.dup
|
43
|
+
options_to_pass.delete :plan
|
44
|
+
options_to_pass.delete :role
|
30
45
|
|
31
|
-
|
32
|
-
@schema.require!(*args)
|
33
|
-
end
|
34
|
-
|
35
|
-
def with_options(options)
|
36
|
-
Proxy.new(@schema, options)
|
46
|
+
[namespace, feature, roles, options_to_pass.merge(options)]
|
37
47
|
end
|
38
48
|
|
39
49
|
end
|
data/lib/access_schema/schema.rb
CHANGED
@@ -31,21 +31,34 @@ module AccessSchema
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def require!(*args)
|
34
|
+
check!(*normalize_args(args))
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def normalize_args(args)
|
40
|
+
#Rails.logger.debug("schema normalize args: #{args.inspect}")
|
41
|
+
|
34
42
|
options = args.last.is_a?(Hash) ? args.pop : {}
|
43
|
+
roles = args[2]
|
44
|
+
roles = roles.respond_to?(:map) ? roles.map(&:to_sym) : [roles.to_sym]
|
45
|
+
privilege = args[1].to_sym
|
46
|
+
|
35
47
|
case args[0]
|
36
48
|
when String, Symbol
|
37
|
-
|
49
|
+
namespace = args[0].to_sym
|
50
|
+
[namespace, privilege, roles, options]
|
38
51
|
else
|
39
|
-
|
52
|
+
namespace = args[0].class.name.to_sym
|
53
|
+
[namespace, privilege, roles, options.merge(:subject => args[0])]
|
40
54
|
end
|
41
|
-
end
|
42
55
|
|
43
|
-
|
44
|
-
|
45
|
-
def check!(namespace_name, element_name, role, options)
|
56
|
+
end
|
46
57
|
|
58
|
+
def check!(namespace_name, element_name, roles, options)
|
59
|
+
#Rails.logger.debug [namespace_name, element_name, roles, options].inspect
|
47
60
|
allowed = for_element(namespace_name, element_name) do |element|
|
48
|
-
element.allow?(
|
61
|
+
element.allow?(roles) do |expectation|
|
49
62
|
check_assert(expectation, options)
|
50
63
|
end
|
51
64
|
end
|
File without changes
|
@@ -13,7 +13,7 @@ describe AccessSchema::Proxy do
|
|
13
13
|
describe "#with_options" do
|
14
14
|
|
15
15
|
before do
|
16
|
-
@schema = @proxy.with_options(:plan => :flower)
|
16
|
+
@schema = @proxy.with_options(:plan => [:flower], :user_id => 1)
|
17
17
|
end
|
18
18
|
|
19
19
|
it "allows to not specify plan for schema calls" do
|
@@ -25,6 +25,11 @@ describe AccessSchema::Proxy do
|
|
25
25
|
@schema.allow?("Review", :mark_featured, :none).should be_false
|
26
26
|
end
|
27
27
|
|
28
|
+
it "passes options to schema" do
|
29
|
+
@proxy.should_receive(:allow?).with("Review", :mark_featured, [:flower], {:user_id => 1})
|
30
|
+
@schema.allow?("Review", :mark_featured)
|
31
|
+
end
|
32
|
+
|
28
33
|
end
|
29
34
|
|
30
35
|
end
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: access_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-03-04 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: AccessSchema is a tool for ACL or tariff plans schema definition and
|
15
15
|
checks
|
@@ -44,11 +44,11 @@ files:
|
|
44
44
|
- lib/access_schema/proxy.rb
|
45
45
|
- lib/access_schema/schema.rb
|
46
46
|
- lib/access_schema/version.rb
|
47
|
+
- spec/access_schema/config_builder_spec.rb
|
48
|
+
- spec/access_schema/proxy_spec.rb
|
49
|
+
- spec/access_schema/schema_builder_spec.rb
|
50
|
+
- spec/access_schema/schema_spec.rb
|
47
51
|
- spec/access_schema_spec.rb
|
48
|
-
- spec/assess_schema/config_builder_spec.rb
|
49
|
-
- spec/assess_schema/proxy_spec.rb
|
50
|
-
- spec/assess_schema/schema_builder_spec.rb
|
51
|
-
- spec/assess_schema/schema_spec.rb
|
52
52
|
- spec/schema_example.rb
|
53
53
|
- spec/spec_helper.rb
|
54
54
|
homepage: ''
|
@@ -76,10 +76,10 @@ signing_key:
|
|
76
76
|
specification_version: 3
|
77
77
|
summary: AccessSchema is an ACL tool
|
78
78
|
test_files:
|
79
|
+
- spec/access_schema/config_builder_spec.rb
|
80
|
+
- spec/access_schema/proxy_spec.rb
|
81
|
+
- spec/access_schema/schema_builder_spec.rb
|
82
|
+
- spec/access_schema/schema_spec.rb
|
79
83
|
- spec/access_schema_spec.rb
|
80
|
-
- spec/assess_schema/config_builder_spec.rb
|
81
|
-
- spec/assess_schema/proxy_spec.rb
|
82
|
-
- spec/assess_schema/schema_builder_spec.rb
|
83
|
-
- spec/assess_schema/schema_spec.rb
|
84
84
|
- spec/schema_example.rb
|
85
85
|
- spec/spec_helper.rb
|