acl9 1.2.1 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +2 -2
- data/Gemfile.lock +40 -45
- data/README.md +4 -0
- data/lib/acl9/controller_extensions/dsl_base.rb +5 -11
- data/lib/acl9/model_extensions/for_subject.rb +13 -0
- data/lib/acl9/prepositions.rb +18 -0
- data/lib/acl9/version.rb +1 -1
- data/test/models/roles_test.rb +21 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c453f2d63455ec9792617d8436fdf11069dc843d
|
4
|
+
data.tar.gz: 20ae0c3d277ac3b8393b5a63e04a2b4c3e8c2576
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ea8427b7aac68a931a94c5cdefd3c5f82560130efd528bc46f260f55595044a4b425b3ee24bd22adf80a03b6fc57156142aee0d66b80b50703dcfae55245f0a
|
7
|
+
data.tar.gz: 07e1e06046612cad72fcbb37b8070b5c76d554b6f5168aeaa5eeec733696e639cde81cea13fecb19d2f5440245dcf83d69330038c32b01d68839358118424f07
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.2.
|
1
|
+
2.2.2
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,42 +1,42 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
acl9 (1.
|
4
|
+
acl9 (1.3.0)
|
5
5
|
rails (~> 4.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
|
-
actionmailer (4.2.
|
11
|
-
actionpack (= 4.2.
|
12
|
-
actionview (= 4.2.
|
13
|
-
activejob (= 4.2.
|
10
|
+
actionmailer (4.2.1)
|
11
|
+
actionpack (= 4.2.1)
|
12
|
+
actionview (= 4.2.1)
|
13
|
+
activejob (= 4.2.1)
|
14
14
|
mail (~> 2.5, >= 2.5.4)
|
15
15
|
rails-dom-testing (~> 1.0, >= 1.0.5)
|
16
|
-
actionpack (4.2.
|
17
|
-
actionview (= 4.2.
|
18
|
-
activesupport (= 4.2.
|
19
|
-
rack (~> 1.6
|
16
|
+
actionpack (4.2.1)
|
17
|
+
actionview (= 4.2.1)
|
18
|
+
activesupport (= 4.2.1)
|
19
|
+
rack (~> 1.6)
|
20
20
|
rack-test (~> 0.6.2)
|
21
21
|
rails-dom-testing (~> 1.0, >= 1.0.5)
|
22
22
|
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
23
|
-
actionview (4.2.
|
24
|
-
activesupport (= 4.2.
|
23
|
+
actionview (4.2.1)
|
24
|
+
activesupport (= 4.2.1)
|
25
25
|
builder (~> 3.1)
|
26
26
|
erubis (~> 2.7.0)
|
27
27
|
rails-dom-testing (~> 1.0, >= 1.0.5)
|
28
28
|
rails-html-sanitizer (~> 1.0, >= 1.0.1)
|
29
|
-
activejob (4.2.
|
30
|
-
activesupport (= 4.2.
|
29
|
+
activejob (4.2.1)
|
30
|
+
activesupport (= 4.2.1)
|
31
31
|
globalid (>= 0.3.0)
|
32
|
-
activemodel (4.2.
|
33
|
-
activesupport (= 4.2.
|
32
|
+
activemodel (4.2.1)
|
33
|
+
activesupport (= 4.2.1)
|
34
34
|
builder (~> 3.1)
|
35
|
-
activerecord (4.2.
|
36
|
-
activemodel (= 4.2.
|
37
|
-
activesupport (= 4.2.
|
35
|
+
activerecord (4.2.1)
|
36
|
+
activemodel (= 4.2.1)
|
37
|
+
activesupport (= 4.2.1)
|
38
38
|
arel (~> 6.0)
|
39
|
-
activesupport (4.2.
|
39
|
+
activesupport (4.2.1)
|
40
40
|
i18n (~> 0.7)
|
41
41
|
json (~> 1.7, >= 1.7.7)
|
42
42
|
minitest (~> 5.1)
|
@@ -53,16 +53,15 @@ GEM
|
|
53
53
|
simplecov (>= 0.7.1, < 1.0.0)
|
54
54
|
docile (1.1.5)
|
55
55
|
erubis (2.7.0)
|
56
|
-
globalid (0.3.
|
56
|
+
globalid (0.3.5)
|
57
57
|
activesupport (>= 4.1.0)
|
58
|
-
hike (1.2.3)
|
59
58
|
i18n (0.7.0)
|
60
59
|
json (1.8.1)
|
61
|
-
loofah (2.0.
|
60
|
+
loofah (2.0.2)
|
62
61
|
nokogiri (>= 1.5.9)
|
63
62
|
mail (2.6.3)
|
64
63
|
mime-types (>= 1.16, < 3)
|
65
|
-
mime-types (2.
|
64
|
+
mime-types (2.5)
|
66
65
|
mini_portile (0.6.2)
|
67
66
|
minitap (0.5.3)
|
68
67
|
minitest (~> 5.0)
|
@@ -74,31 +73,31 @@ GEM
|
|
74
73
|
multi_json (1.10.1)
|
75
74
|
nokogiri (1.6.6.2)
|
76
75
|
mini_portile (~> 0.6.0)
|
77
|
-
rack (1.6.
|
76
|
+
rack (1.6.1)
|
78
77
|
rack-test (0.6.3)
|
79
78
|
rack (>= 1.0)
|
80
|
-
rails (4.2.
|
81
|
-
actionmailer (= 4.2.
|
82
|
-
actionpack (= 4.2.
|
83
|
-
actionview (= 4.2.
|
84
|
-
activejob (= 4.2.
|
85
|
-
activemodel (= 4.2.
|
86
|
-
activerecord (= 4.2.
|
87
|
-
activesupport (= 4.2.
|
79
|
+
rails (4.2.1)
|
80
|
+
actionmailer (= 4.2.1)
|
81
|
+
actionpack (= 4.2.1)
|
82
|
+
actionview (= 4.2.1)
|
83
|
+
activejob (= 4.2.1)
|
84
|
+
activemodel (= 4.2.1)
|
85
|
+
activerecord (= 4.2.1)
|
86
|
+
activesupport (= 4.2.1)
|
88
87
|
bundler (>= 1.3.0, < 2.0)
|
89
|
-
railties (= 4.2.
|
88
|
+
railties (= 4.2.1)
|
90
89
|
sprockets-rails
|
91
90
|
rails-deprecated_sanitizer (1.0.3)
|
92
91
|
activesupport (>= 4.2.0.alpha)
|
93
|
-
rails-dom-testing (1.0.
|
92
|
+
rails-dom-testing (1.0.6)
|
94
93
|
activesupport (>= 4.2.0.beta, < 5.0)
|
95
94
|
nokogiri (~> 1.6.0)
|
96
95
|
rails-deprecated_sanitizer (>= 1.0.1)
|
97
|
-
rails-html-sanitizer (1.0.
|
96
|
+
rails-html-sanitizer (1.0.2)
|
98
97
|
loofah (~> 2.0)
|
99
|
-
railties (4.2.
|
100
|
-
actionpack (= 4.2.
|
101
|
-
activesupport (= 4.2.
|
98
|
+
railties (4.2.1)
|
99
|
+
actionpack (= 4.2.1)
|
100
|
+
activesupport (= 4.2.1)
|
102
101
|
rake (>= 0.8.7)
|
103
102
|
thor (>= 0.18.1, < 2.0)
|
104
103
|
rake (10.4.2)
|
@@ -107,12 +106,9 @@ GEM
|
|
107
106
|
multi_json (~> 1.0)
|
108
107
|
simplecov-html (~> 0.8.0)
|
109
108
|
simplecov-html (0.8.0)
|
110
|
-
sprockets (
|
111
|
-
hike (~> 1.2)
|
112
|
-
multi_json (~> 1.0)
|
109
|
+
sprockets (3.1.0)
|
113
110
|
rack (~> 1.0)
|
114
|
-
|
115
|
-
sprockets-rails (2.2.4)
|
111
|
+
sprockets-rails (2.3.1)
|
116
112
|
actionpack (>= 3.0)
|
117
113
|
activesupport (>= 3.0)
|
118
114
|
sprockets (>= 2.8, < 4.0)
|
@@ -121,8 +117,7 @@ GEM
|
|
121
117
|
ansi
|
122
118
|
json
|
123
119
|
thor (0.19.1)
|
124
|
-
thread_safe (0.3.
|
125
|
-
tilt (1.4.1)
|
120
|
+
thread_safe (0.3.5)
|
126
121
|
tzinfo (1.2.2)
|
127
122
|
thread_safe (~> 0.1)
|
128
123
|
yard (0.8.7.6)
|
data/README.md
CHANGED
@@ -75,6 +75,7 @@ the admin for a particular school:
|
|
75
75
|
|
76
76
|
```ruby
|
77
77
|
user.has_role! :admin, school
|
78
|
+
user.has_role! :admin, of: school
|
78
79
|
```
|
79
80
|
|
80
81
|
Then let's say we have some support people in our organization who are dedicated
|
@@ -84,6 +85,7 @@ assign roles to any object, including a class, and do this:
|
|
84
85
|
|
85
86
|
```ruby
|
86
87
|
user.has_role! :support, School
|
88
|
+
user.has_role! :support, for: School
|
87
89
|
```
|
88
90
|
|
89
91
|
You can see the `allow` line in our `access_control` block that this corresponds
|
@@ -94,6 +96,7 @@ Now, when a support person leaves that team, we need to remove that role:
|
|
94
96
|
|
95
97
|
```ruby
|
96
98
|
user.has_no_role! :support, School
|
99
|
+
user.has_no_role! :support, at: School
|
97
100
|
```
|
98
101
|
|
99
102
|
You can see more about all this stuff in the wiki under [Role
|
@@ -229,6 +232,7 @@ We all know that this means:
|
|
229
232
|
|
230
233
|
```ruby
|
231
234
|
user.has_role? :manager, department # => true
|
235
|
+
user.has_role? :manager, in: department # => true
|
232
236
|
```
|
233
237
|
|
234
238
|
With `:protect_global_roles` set to `false`, as it was in `0.x` then the above
|
@@ -1,6 +1,10 @@
|
|
1
|
+
require File.expand_path '../../prepositions', __FILE__
|
2
|
+
|
1
3
|
module Acl9
|
2
4
|
module Dsl
|
3
5
|
class Base
|
6
|
+
include Prepositions
|
7
|
+
|
4
8
|
attr_reader :allows, :denys
|
5
9
|
|
6
10
|
def initialize(*args)
|
@@ -164,18 +168,8 @@ module Acl9
|
|
164
168
|
end
|
165
169
|
end
|
166
170
|
|
167
|
-
VALID_PREPOSITIONS = %w(of for in on at by).freeze unless defined? VALID_PREPOSITIONS
|
168
|
-
|
169
171
|
def _role_object(options)
|
170
|
-
object =
|
171
|
-
|
172
|
-
VALID_PREPOSITIONS.each do |prep|
|
173
|
-
if options[prep.to_sym]
|
174
|
-
raise ArgumentError, "You may only use one preposition to specify object" if object
|
175
|
-
|
176
|
-
object = options[prep.to_sym]
|
177
|
-
end
|
178
|
-
end
|
172
|
+
object = _by_preposition options
|
179
173
|
|
180
174
|
case object
|
181
175
|
when Class then object.to_s
|
@@ -1,6 +1,10 @@
|
|
1
|
+
require File.expand_path '../../prepositions', __FILE__
|
2
|
+
|
1
3
|
module Acl9
|
2
4
|
module ModelExtensions
|
3
5
|
module ForSubject
|
6
|
+
include Prepositions
|
7
|
+
|
4
8
|
##
|
5
9
|
# Role check.
|
6
10
|
#
|
@@ -36,6 +40,8 @@ module Acl9
|
|
36
40
|
# @see Acl9::ModelExtensions::Object#accepts_role?
|
37
41
|
def has_role?(role_name, object = nil)
|
38
42
|
role_name = normalize role_name
|
43
|
+
object = _by_preposition object
|
44
|
+
|
39
45
|
!! if object.nil? && !::Acl9.config[:protect_global_roles]
|
40
46
|
self._role_objects.find_by_name(role_name.to_s) ||
|
41
47
|
self._role_objects.member?(get_role(role_name, nil))
|
@@ -53,6 +59,8 @@ module Acl9
|
|
53
59
|
# @see Acl9::ModelExtensions::Object#accepts_role!
|
54
60
|
def has_role!(role_name, object = nil)
|
55
61
|
role_name = normalize role_name
|
62
|
+
object = _by_preposition object
|
63
|
+
|
56
64
|
role = get_role(role_name, object)
|
57
65
|
|
58
66
|
if role.nil?
|
@@ -76,6 +84,7 @@ module Acl9
|
|
76
84
|
# @see Acl9::ModelExtensions::Object#accepts_no_role!
|
77
85
|
def has_no_role!(role_name, object = nil)
|
78
86
|
role_name = normalize role_name
|
87
|
+
object = _by_preposition object
|
79
88
|
delete_role(get_role(role_name, object))
|
80
89
|
end
|
81
90
|
|
@@ -182,6 +191,10 @@ module Acl9
|
|
182
191
|
|
183
192
|
protected
|
184
193
|
|
194
|
+
def _by_preposition object
|
195
|
+
object.is_a?(Hash) ? super : object
|
196
|
+
end
|
197
|
+
|
185
198
|
def _auth_role_class
|
186
199
|
self.class._auth_role_class_name.constantize
|
187
200
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Acl9
|
2
|
+
module Prepositions
|
3
|
+
VALID_PREPOSITIONS = %w(of for in on at by).freeze unless defined? VALID_PREPOSITIONS
|
4
|
+
|
5
|
+
def _by_preposition options
|
6
|
+
object = nil
|
7
|
+
|
8
|
+
VALID_PREPOSITIONS.each do |prep|
|
9
|
+
if options[prep.to_sym]
|
10
|
+
raise ArgumentError, "You may only use one preposition to specify object" if object
|
11
|
+
|
12
|
+
object = options[prep.to_sym]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
object
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/acl9/version.rb
CHANGED
data/test/models/roles_test.rb
CHANGED
@@ -62,6 +62,16 @@ class RolesTest < ActiveSupport::TestCase
|
|
62
62
|
assert @foo.accepts_roles_by? @user
|
63
63
|
end
|
64
64
|
|
65
|
+
test "#has_role! with preposition" do
|
66
|
+
assert @user.has_role! :manager, of: @foo
|
67
|
+
assert @user.has_role? :manager, @foo
|
68
|
+
end
|
69
|
+
|
70
|
+
test "#has_role? with preposition" do
|
71
|
+
assert @user.has_role! :manager, @foo
|
72
|
+
assert @user.has_role? :manager, of: @foo
|
73
|
+
end
|
74
|
+
|
65
75
|
test "should count object role also as global role when :protect_global_roles == false" do
|
66
76
|
Acl9.config[:protect_global_roles] = false
|
67
77
|
|
@@ -138,6 +148,17 @@ class RolesTest < ActiveSupport::TestCase
|
|
138
148
|
assert @user.has_role? :user, @foo # another role on the same object
|
139
149
|
end
|
140
150
|
|
151
|
+
test "#has_no_role! should unassign an object role from user with preposition" do
|
152
|
+
set_some_roles
|
153
|
+
|
154
|
+
assert_difference -> { @user.role_objects.count }, -1 do
|
155
|
+
assert @user.has_no_role! :manager, at: @foo
|
156
|
+
end
|
157
|
+
|
158
|
+
refute @user.has_role? :manager, @foo
|
159
|
+
assert @user.has_role? :user, @foo # another role on the same object
|
160
|
+
end
|
161
|
+
|
141
162
|
test "#has_no_role! should unassign a class role from user" do
|
142
163
|
set_some_roles
|
143
164
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acl9
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- oleg dashevskii
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2015-
|
12
|
+
date: 2015-05-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- lib/acl9/model_extensions.rb
|
118
118
|
- lib/acl9/model_extensions/for_object.rb
|
119
119
|
- lib/acl9/model_extensions/for_subject.rb
|
120
|
+
- lib/acl9/prepositions.rb
|
120
121
|
- lib/acl9/version.rb
|
121
122
|
- lib/generators/acl9/setup/USAGE
|
122
123
|
- lib/generators/acl9/setup/setup_generator.rb
|