surrounded 0.7.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/surrounded/access_control.rb +24 -1
- data/lib/surrounded/version.rb +1 -1
- data/test/context_access_test.rb +18 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 349c77c09cbb18c43dff15df5fcb3ce444f6aee1
|
4
|
+
data.tar.gz: 61b1e9fb3ce7e7865a624425fbb4fc746644d674
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 166ecba24f2037b1a57c80a163f1a2a75506af524d88552af1caa3d6d72ea79cd0693a97df446acbfd7ac903e57b4d8a8c524b21d5f087dbf21fd0ad00c5c4ab
|
7
|
+
data.tar.gz: 04b781c0db8fc068de9af65f4fda3f58b3b8d1e4f859c6dfa67800e89be032cc696a5690b6c7adf7661663dea61dd2eea6dbabb74ad915517e04be0faa9d86a1
|
@@ -9,7 +9,7 @@ module Surrounded
|
|
9
9
|
|
10
10
|
def disallow(*names, &block)
|
11
11
|
names.map do |name|
|
12
|
-
|
12
|
+
define_access_method(name, &block)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
@@ -33,6 +33,20 @@ module Surrounded
|
|
33
33
|
}
|
34
34
|
end
|
35
35
|
|
36
|
+
def define_access_method(name, &block)
|
37
|
+
class_eval {
|
38
|
+
meth = AccessMethods.instance_method(:with_roles)
|
39
|
+
define_method "disallow_#{name}?" do
|
40
|
+
begin
|
41
|
+
apply_roles if __apply_role_policy == :trigger
|
42
|
+
instance_exec(&block)
|
43
|
+
ensure
|
44
|
+
remove_roles if __apply_role_policy == :trigger
|
45
|
+
end
|
46
|
+
end
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
36
50
|
module AccessMethods
|
37
51
|
def all_triggers
|
38
52
|
self.class.triggers
|
@@ -44,6 +58,15 @@ module Surrounded
|
|
44
58
|
!self.respond_to?(method_restrictor, true) || !self.send(method_restrictor)
|
45
59
|
}.to_set
|
46
60
|
end
|
61
|
+
|
62
|
+
def with_roles(policy = :trigger)
|
63
|
+
begin
|
64
|
+
apply_roles if __apply_role_policy == policy
|
65
|
+
yield
|
66
|
+
ensure
|
67
|
+
remove_roles if __apply_role_policy == policy
|
68
|
+
end
|
69
|
+
end
|
47
70
|
end
|
48
71
|
end
|
49
72
|
end
|
data/lib/surrounded/version.rb
CHANGED
data/test/context_access_test.rb
CHANGED
@@ -14,6 +14,20 @@ class FilteredContext
|
|
14
14
|
disallow :if_ready do
|
15
15
|
user.name != 'Amy'
|
16
16
|
end
|
17
|
+
|
18
|
+
trigger :check_disallow_behavior do
|
19
|
+
# used for disallow check
|
20
|
+
end
|
21
|
+
|
22
|
+
disallow :check_disallow_behavior do
|
23
|
+
user.special
|
24
|
+
end
|
25
|
+
|
26
|
+
role :user do
|
27
|
+
def special
|
28
|
+
'special user method'
|
29
|
+
end
|
30
|
+
end
|
17
31
|
end
|
18
32
|
|
19
33
|
describe Surrounded::Context, 'access control' do
|
@@ -37,4 +51,8 @@ describe Surrounded::Context, 'access control' do
|
|
37
51
|
}
|
38
52
|
assert_match(/access to FilteredContext#if_ready is not allowed/i, error.message)
|
39
53
|
end
|
54
|
+
|
55
|
+
it 'applies roles in disallow blocks' do
|
56
|
+
assert_equal 'special user method', context.disallow_check_disallow_behavior?
|
57
|
+
end
|
40
58
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: surrounded
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- '''Jim Gay'''
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: triad
|