monarchy 2.0.6 → 2.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github_changelog_generator +1 -1
- data/CHANGELOG.md +11 -2
- data/Gemfile +8 -8
- data/Gemfile.lock +62 -61
- data/README.md +3 -4
- data/docs/acts_as_hierarchy.md +4 -0
- data/docs/acts_as_resource.md +4 -0
- data/lib/monarchy/acts_as_hierarchy.rb +20 -13
- data/lib/monarchy/acts_as_resource.rb +6 -3
- data/lib/monarchy/acts_as_user.rb +3 -4
- data/lib/monarchy/version.rb +1 -1
- data/monarchy.gemspec +2 -2
- metadata +6 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 387d2b45a06426e506849cb93e65233de8eb28f2
|
|
4
|
+
data.tar.gz: 7d5bc881940cb9b75831e01fee258a30409bd277
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d3254e9c61cce95221d874bbce2b4f62857f504ba0442f079a24e59d1f37b75f97121482cc2806ee89e9563a6ad8d064b3597a16399312d393c8d3ca34549975
|
|
7
|
+
data.tar.gz: 791954cbe20ab2d4bbb7ac3c9ebd0a26d1ca7252a8a5e5b265cbfd65303b94adfbe86ee18950c9862a6e43883d98be1b2253819cc46d8b021eb8d2d94ddb14aa
|
data/.github_changelog_generator
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
future-release=2.0.
|
|
1
|
+
future-release=2.0.7
|
data/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
## [2.0.
|
|
4
|
-
[Full Changelog](https://github.com/Exelord/Monarchy/compare/v2.0.
|
|
3
|
+
## [2.0.7](https://github.com/Exelord/Monarchy/tree/2.0.7) (2017-01-09)
|
|
4
|
+
[Full Changelog](https://github.com/Exelord/Monarchy/compare/v2.0.6...2.0.7)
|
|
5
|
+
|
|
6
|
+
**Merged pull requests:**
|
|
7
|
+
|
|
8
|
+
- Improve coverage [\#66](https://github.com/Exelord/Monarchy/pull/66) ([Exelord](https://github.com/Exelord))
|
|
9
|
+
- Update gems [\#65](https://github.com/Exelord/Monarchy/pull/65) ([Exelord](https://github.com/Exelord))
|
|
10
|
+
- Feature custom inherited roles [\#64](https://github.com/Exelord/Monarchy/pull/64) ([Exelord](https://github.com/Exelord))
|
|
11
|
+
|
|
12
|
+
## [v2.0.6](https://github.com/Exelord/Monarchy/tree/v2.0.6) (2016-11-29)
|
|
13
|
+
[Full Changelog](https://github.com/Exelord/Monarchy/compare/v2.0.5...v2.0.6)
|
|
5
14
|
|
|
6
15
|
**Fixed bugs:**
|
|
7
16
|
|
data/Gemfile
CHANGED
|
@@ -16,17 +16,17 @@ gemspec
|
|
|
16
16
|
# gem 'byebug', group: [:development, :test]
|
|
17
17
|
|
|
18
18
|
group :development, :test do
|
|
19
|
-
gem '
|
|
20
|
-
gem '
|
|
19
|
+
gem 'database_cleaner', '1.5.3'
|
|
20
|
+
gem 'factory_girl_rails', '4.8.0'
|
|
21
|
+
gem 'ffaker', '2.4.0'
|
|
21
22
|
gem 'pry-rails', '0.3.4'
|
|
22
|
-
gem '
|
|
23
|
+
gem 'rails', '5.0.1'
|
|
23
24
|
gem 'rspec-rails', '3.5.2'
|
|
24
|
-
gem '
|
|
25
|
-
gem '
|
|
26
|
-
gem '
|
|
25
|
+
gem 'rubocop', '0.46.0'
|
|
26
|
+
gem 'shoulda-matchers', '3.1.1'
|
|
27
|
+
gem 'sqlite3', '1.3.13'
|
|
27
28
|
gem 'tqdm', '0.3.0'
|
|
28
|
-
gem 'rails', '5.0.0.1'
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
+
gem 'codeclimate-test-reporter', '1.0.4', group: :test
|
|
31
32
|
gem 'simplecov', '0.12.0', group: :test
|
|
32
|
-
gem 'codeclimate-test-reporter', '1.0.0', group: :test
|
data/Gemfile.lock
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
monarchy (2.0.
|
|
4
|
+
monarchy (2.0.7)
|
|
5
5
|
active_record_union (= 1.2.0)
|
|
6
6
|
activerecord (>= 4.2.7.1)
|
|
7
7
|
closure_tree (= 6.2.0)
|
|
8
|
-
configurations (= 2.2.
|
|
8
|
+
configurations (= 2.2.2)
|
|
9
9
|
tqdm (= 0.3.0)
|
|
10
10
|
|
|
11
11
|
GEM
|
|
12
12
|
remote: https://rubygems.org/
|
|
13
13
|
specs:
|
|
14
|
-
actioncable (5.0.
|
|
15
|
-
actionpack (= 5.0.
|
|
14
|
+
actioncable (5.0.1)
|
|
15
|
+
actionpack (= 5.0.1)
|
|
16
16
|
nio4r (~> 1.2)
|
|
17
17
|
websocket-driver (~> 0.6.1)
|
|
18
|
-
actionmailer (5.0.
|
|
19
|
-
actionpack (= 5.0.
|
|
20
|
-
actionview (= 5.0.
|
|
21
|
-
activejob (= 5.0.
|
|
18
|
+
actionmailer (5.0.1)
|
|
19
|
+
actionpack (= 5.0.1)
|
|
20
|
+
actionview (= 5.0.1)
|
|
21
|
+
activejob (= 5.0.1)
|
|
22
22
|
mail (~> 2.5, >= 2.5.4)
|
|
23
23
|
rails-dom-testing (~> 2.0)
|
|
24
|
-
actionpack (5.0.
|
|
25
|
-
actionview (= 5.0.
|
|
26
|
-
activesupport (= 5.0.
|
|
24
|
+
actionpack (5.0.1)
|
|
25
|
+
actionview (= 5.0.1)
|
|
26
|
+
activesupport (= 5.0.1)
|
|
27
27
|
rack (~> 2.0)
|
|
28
28
|
rack-test (~> 0.6.3)
|
|
29
29
|
rails-dom-testing (~> 2.0)
|
|
30
30
|
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
|
31
|
-
actionview (5.0.
|
|
32
|
-
activesupport (= 5.0.
|
|
31
|
+
actionview (5.0.1)
|
|
32
|
+
activesupport (= 5.0.1)
|
|
33
33
|
builder (~> 3.1)
|
|
34
34
|
erubis (~> 2.7.0)
|
|
35
35
|
rails-dom-testing (~> 2.0)
|
|
36
36
|
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
|
37
37
|
active_record_union (1.2.0)
|
|
38
38
|
activerecord (>= 4.0)
|
|
39
|
-
activejob (5.0.
|
|
40
|
-
activesupport (= 5.0.
|
|
39
|
+
activejob (5.0.1)
|
|
40
|
+
activesupport (= 5.0.1)
|
|
41
41
|
globalid (>= 0.3.6)
|
|
42
|
-
activemodel (5.0.
|
|
43
|
-
activesupport (= 5.0.
|
|
44
|
-
activerecord (5.0.
|
|
45
|
-
activemodel (= 5.0.
|
|
46
|
-
activesupport (= 5.0.
|
|
42
|
+
activemodel (5.0.1)
|
|
43
|
+
activesupport (= 5.0.1)
|
|
44
|
+
activerecord (5.0.1)
|
|
45
|
+
activemodel (= 5.0.1)
|
|
46
|
+
activesupport (= 5.0.1)
|
|
47
47
|
arel (~> 7.0)
|
|
48
|
-
activesupport (5.0.
|
|
48
|
+
activesupport (5.0.1)
|
|
49
49
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
50
50
|
i18n (~> 0.7)
|
|
51
51
|
minitest (~> 5.1)
|
|
@@ -56,20 +56,21 @@ GEM
|
|
|
56
56
|
closure_tree (6.2.0)
|
|
57
57
|
activerecord (>= 4.1.0)
|
|
58
58
|
with_advisory_lock (>= 3.0.0)
|
|
59
|
-
codeclimate-test-reporter (1.0.
|
|
59
|
+
codeclimate-test-reporter (1.0.4)
|
|
60
|
+
simplecov
|
|
60
61
|
coderay (1.1.1)
|
|
61
|
-
concurrent-ruby (1.0.
|
|
62
|
-
configurations (2.2.
|
|
62
|
+
concurrent-ruby (1.0.4)
|
|
63
|
+
configurations (2.2.2)
|
|
63
64
|
database_cleaner (1.5.3)
|
|
64
65
|
diff-lcs (1.2.5)
|
|
65
66
|
docile (1.1.5)
|
|
66
67
|
erubis (2.7.0)
|
|
67
|
-
factory_girl (4.
|
|
68
|
+
factory_girl (4.8.0)
|
|
68
69
|
activesupport (>= 3.0.0)
|
|
69
|
-
factory_girl_rails (4.
|
|
70
|
-
factory_girl (~> 4.
|
|
70
|
+
factory_girl_rails (4.8.0)
|
|
71
|
+
factory_girl (~> 4.8.0)
|
|
71
72
|
railties (>= 3.0.0)
|
|
72
|
-
ffaker (2.
|
|
73
|
+
ffaker (2.4.0)
|
|
73
74
|
globalid (0.3.7)
|
|
74
75
|
activesupport (>= 4.1.0)
|
|
75
76
|
i18n (0.7.0)
|
|
@@ -83,11 +84,11 @@ GEM
|
|
|
83
84
|
mime-types-data (~> 3.2015)
|
|
84
85
|
mime-types-data (3.2016.0521)
|
|
85
86
|
mini_portile2 (2.1.0)
|
|
86
|
-
minitest (5.
|
|
87
|
+
minitest (5.10.1)
|
|
87
88
|
nio4r (1.2.1)
|
|
88
|
-
nokogiri (1.
|
|
89
|
+
nokogiri (1.7.0.1)
|
|
89
90
|
mini_portile2 (~> 2.1.0)
|
|
90
|
-
parser (2.3.1
|
|
91
|
+
parser (2.3.3.1)
|
|
91
92
|
ast (~> 2.2)
|
|
92
93
|
powerpack (0.1.1)
|
|
93
94
|
pry (0.10.4)
|
|
@@ -99,31 +100,31 @@ GEM
|
|
|
99
100
|
rack (2.0.1)
|
|
100
101
|
rack-test (0.6.3)
|
|
101
102
|
rack (>= 1.0)
|
|
102
|
-
rails (5.0.
|
|
103
|
-
actioncable (= 5.0.
|
|
104
|
-
actionmailer (= 5.0.
|
|
105
|
-
actionpack (= 5.0.
|
|
106
|
-
actionview (= 5.0.
|
|
107
|
-
activejob (= 5.0.
|
|
108
|
-
activemodel (= 5.0.
|
|
109
|
-
activerecord (= 5.0.
|
|
110
|
-
activesupport (= 5.0.
|
|
103
|
+
rails (5.0.1)
|
|
104
|
+
actioncable (= 5.0.1)
|
|
105
|
+
actionmailer (= 5.0.1)
|
|
106
|
+
actionpack (= 5.0.1)
|
|
107
|
+
actionview (= 5.0.1)
|
|
108
|
+
activejob (= 5.0.1)
|
|
109
|
+
activemodel (= 5.0.1)
|
|
110
|
+
activerecord (= 5.0.1)
|
|
111
|
+
activesupport (= 5.0.1)
|
|
111
112
|
bundler (>= 1.3.0, < 2.0)
|
|
112
|
-
railties (= 5.0.
|
|
113
|
+
railties (= 5.0.1)
|
|
113
114
|
sprockets-rails (>= 2.0.0)
|
|
114
|
-
rails-dom-testing (2.0.
|
|
115
|
+
rails-dom-testing (2.0.2)
|
|
115
116
|
activesupport (>= 4.2.0, < 6.0)
|
|
116
|
-
nokogiri (~> 1.6
|
|
117
|
+
nokogiri (~> 1.6)
|
|
117
118
|
rails-html-sanitizer (1.0.3)
|
|
118
119
|
loofah (~> 2.0)
|
|
119
|
-
railties (5.0.
|
|
120
|
-
actionpack (= 5.0.
|
|
121
|
-
activesupport (= 5.0.
|
|
120
|
+
railties (5.0.1)
|
|
121
|
+
actionpack (= 5.0.1)
|
|
122
|
+
activesupport (= 5.0.1)
|
|
122
123
|
method_source
|
|
123
124
|
rake (>= 0.8.7)
|
|
124
125
|
thor (>= 0.18.1, < 2.0)
|
|
125
|
-
rainbow (2.1
|
|
126
|
-
rake (
|
|
126
|
+
rainbow (2.2.1)
|
|
127
|
+
rake (12.0.0)
|
|
127
128
|
rspec (3.5.0)
|
|
128
129
|
rspec-core (~> 3.5.0)
|
|
129
130
|
rspec-expectations (~> 3.5.0)
|
|
@@ -145,7 +146,7 @@ GEM
|
|
|
145
146
|
rspec-mocks (~> 3.5.0)
|
|
146
147
|
rspec-support (~> 3.5.0)
|
|
147
148
|
rspec-support (3.5.0)
|
|
148
|
-
rubocop (0.
|
|
149
|
+
rubocop (0.46.0)
|
|
149
150
|
parser (>= 2.3.1.1, < 3.0)
|
|
150
151
|
powerpack (~> 0.1)
|
|
151
152
|
rainbow (>= 1.99.1, < 3.0)
|
|
@@ -160,20 +161,20 @@ GEM
|
|
|
160
161
|
simplecov-html (~> 0.10.0)
|
|
161
162
|
simplecov-html (0.10.0)
|
|
162
163
|
slop (3.6.0)
|
|
163
|
-
sprockets (3.7.
|
|
164
|
+
sprockets (3.7.1)
|
|
164
165
|
concurrent-ruby (~> 1.0)
|
|
165
166
|
rack (> 1, < 3)
|
|
166
167
|
sprockets-rails (3.2.0)
|
|
167
168
|
actionpack (>= 4.0)
|
|
168
169
|
activesupport (>= 4.0)
|
|
169
170
|
sprockets (>= 3.0.0)
|
|
170
|
-
sqlite3 (1.3.
|
|
171
|
-
thor (0.19.
|
|
171
|
+
sqlite3 (1.3.13)
|
|
172
|
+
thor (0.19.4)
|
|
172
173
|
thread_safe (0.3.5)
|
|
173
174
|
tqdm (0.3.0)
|
|
174
175
|
tzinfo (1.2.2)
|
|
175
176
|
thread_safe (~> 0.1)
|
|
176
|
-
unicode-display_width (1.1.
|
|
177
|
+
unicode-display_width (1.1.2)
|
|
177
178
|
websocket-driver (0.6.4)
|
|
178
179
|
websocket-extensions (>= 0.1.0)
|
|
179
180
|
websocket-extensions (0.1.2)
|
|
@@ -186,24 +187,24 @@ PLATFORMS
|
|
|
186
187
|
|
|
187
188
|
DEPENDENCIES
|
|
188
189
|
bundler (~> 1.12)
|
|
189
|
-
codeclimate-test-reporter (= 1.0.
|
|
190
|
+
codeclimate-test-reporter (= 1.0.4)
|
|
190
191
|
database_cleaner (= 1.5.3)
|
|
191
|
-
factory_girl_rails (= 4.
|
|
192
|
-
ffaker (= 2.
|
|
192
|
+
factory_girl_rails (= 4.8.0)
|
|
193
|
+
ffaker (= 2.4.0)
|
|
193
194
|
monarchy!
|
|
194
195
|
pry-rails (= 0.3.4)
|
|
195
|
-
rails (= 5.0.
|
|
196
|
-
rake (~>
|
|
196
|
+
rails (= 5.0.1)
|
|
197
|
+
rake (~> 12.0)
|
|
197
198
|
rspec (= 3.5.0)
|
|
198
199
|
rspec-rails (= 3.5.2)
|
|
199
|
-
rubocop (= 0.
|
|
200
|
+
rubocop (= 0.46.0)
|
|
200
201
|
shoulda-matchers (= 3.1.1)
|
|
201
202
|
simplecov (= 0.12.0)
|
|
202
|
-
sqlite3 (= 1.3.
|
|
203
|
+
sqlite3 (= 1.3.13)
|
|
203
204
|
tqdm (= 0.3.0)
|
|
204
205
|
|
|
205
206
|
RUBY VERSION
|
|
206
207
|
ruby 2.3.1p112
|
|
207
208
|
|
|
208
209
|
BUNDLED WITH
|
|
209
|
-
1.13.
|
|
210
|
+
1.13.7
|
data/README.md
CHANGED
|
@@ -17,12 +17,11 @@
|
|
|
17
17
|
</a>
|
|
18
18
|
</p>
|
|
19
19
|
|
|
20
|
-
Monarchy is a ruby gem offering a complete solution to manage an access in
|
|
21
|
-
Hierarchical structure and built-in roles inheritance options make it the most powerful tool to control an access to your resources.
|
|
20
|
+
Monarchy is a ruby gem offering a complete solution to manage an authorization access in Ruby on Rails applications. A hierarchical structure as well as built-in roles inheritance options make it the most powerful tool to control access to application data resources.
|
|
22
21
|
|
|
23
|
-
Thanks to [closure_tree](https://github.com/mceachen/closure_tree)
|
|
22
|
+
Thanks to [closure_tree](https://github.com/mceachen/closure_tree) - a gem used to manage binary trees - Monarchy can deliver the best-in-class algorithmic performance and enables developers to forget about hierarchies and complicated structures.
|
|
24
23
|
|
|
25
|
-
|
|
24
|
+
If you feel limited while using rolify, feel free to use Monarchy with its advanced capacity to inherit roles and collect all accessible resources with just one method.
|
|
26
25
|
|
|
27
26
|
## Usage Example
|
|
28
27
|
After Monarchy setup you can enjoy with roles inheritance and accessible resources.
|
data/docs/acts_as_hierarchy.md
CHANGED
|
@@ -16,6 +16,10 @@ You can select all hierarchies accessible for specific user by using a scope: `a
|
|
|
16
16
|
``` ruby
|
|
17
17
|
Monarchy.hierarchy_class.accessible_for(current_user) # returns [hierarchy1, hierarchy2, hierarchy5]
|
|
18
18
|
```
|
|
19
|
+
Optionally you can pass extra allowed roles which should be inherited for this request
|
|
20
|
+
``` ruby
|
|
21
|
+
Monarchy.hierarchy_class.accessible_for(current_user, [:blocked, :visitors]) # returns [hierarchy1, hierarchy2, hierarchy5, hierarchy6]
|
|
22
|
+
```
|
|
19
23
|
|
|
20
24
|
### .in(resource, true)
|
|
21
25
|
You can select all hierarchies scoped into another by using scope: `in`:
|
data/docs/acts_as_resource.md
CHANGED
|
@@ -69,6 +69,10 @@ You can select all resources accessible for specyfic user by using scope: `acces
|
|
|
69
69
|
``` ruby
|
|
70
70
|
Resource.accessible_for(current_user) # returns [resource1, resource2, resource5]
|
|
71
71
|
```
|
|
72
|
+
Optionally you can pass extra allowed roles which should be inherited for this request
|
|
73
|
+
``` ruby
|
|
74
|
+
Resource.accessible_for(current_user, [:blocked, :visitors]) # returns [resource1, resource2, resource5, resource6]
|
|
75
|
+
```
|
|
72
76
|
|
|
73
77
|
### .in(resource, true)
|
|
74
78
|
You can select all resources scoped into another by using scope: `in`:
|
|
@@ -29,10 +29,10 @@ module Monarchy
|
|
|
29
29
|
where(id: descendants ? hierarchy.descendants : hierarchy.children)
|
|
30
30
|
end)
|
|
31
31
|
|
|
32
|
-
scope :accessible_for, (lambda do |user|
|
|
32
|
+
scope :accessible_for, (lambda do |user, inherited_roles = []|
|
|
33
33
|
Monarchy::Validators.user(user)
|
|
34
34
|
user_id = user.id
|
|
35
|
-
where(id: accessible_roots_ids(user_id).union_all(accessible_leaves_ids(user_id)))
|
|
35
|
+
where(id: accessible_roots_ids(user_id).union_all(accessible_leaves_ids(user_id, inherited_roles)))
|
|
36
36
|
end)
|
|
37
37
|
end
|
|
38
38
|
|
|
@@ -44,30 +44,37 @@ module Monarchy
|
|
|
44
44
|
'members.hierarchy_id = monarchy_hierarchy_hierarchies.descendant_id').select(:id)
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
-
def accessible_leaves_ids(user_id)
|
|
48
|
-
ancestor_leaves_for_user(user_id)
|
|
47
|
+
def accessible_leaves_ids(user_id, inherited_roles = [])
|
|
48
|
+
ancestor_leaves_for_user(user_id, false)
|
|
49
49
|
.select('monarchy_hierarchy_hierarchies.ancestor_id AS id')
|
|
50
|
-
.union_all(descendant_leaves_for_user(user_id)).select(:id)
|
|
50
|
+
.union_all(descendant_leaves_for_user(user_id, inherited_roles)).select(:id)
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
-
def
|
|
54
|
-
|
|
53
|
+
def descendant_leaves_for_user(user_id, inherited_roles = [])
|
|
54
|
+
ancestor_leaves_for_user(user_id, true, inherited_roles)
|
|
55
|
+
.joins('INNER JOIN monarchy_hierarchy_hierarchies AS monarchy_descendants ON ' \
|
|
56
|
+
'monarchy_descendants.ancestor_id = monarchy_hierarchies.id')
|
|
57
|
+
.select('monarchy_descendants.descendant_id AS id')
|
|
58
|
+
end
|
|
55
59
|
|
|
60
|
+
def ancestor_leaves_for_user(user_id, inherited, inherited_roles = [])
|
|
56
61
|
unscoped
|
|
57
62
|
.joins('INNER JOIN monarchy_hierarchy_hierarchies ON ' \
|
|
58
63
|
'monarchy_hierarchies.id = monarchy_hierarchy_hierarchies.descendant_id')
|
|
59
64
|
.joins('INNER JOIN (SELECT id, hierarchy_id FROM monarchy_members WHERE ' \
|
|
60
65
|
"user_id = #{user_id}) as monarchy_members ON monarchy_members.hierarchy_id = monarchy_hierarchies.id")
|
|
61
66
|
.joins('INNER JOIN monarchy_members_roles ON monarchy_members_roles.member_id = monarchy_members.id')
|
|
62
|
-
.joins("INNER JOIN (
|
|
67
|
+
.joins("INNER JOIN (#{inheritance_query(inherited_roles, inherited)}) as " \
|
|
63
68
|
'monarchy_roles ON monarchy_members_roles.role_id = monarchy_roles.id')
|
|
64
69
|
end
|
|
65
70
|
|
|
66
|
-
def
|
|
67
|
-
|
|
68
|
-
.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
+
def inheritance_query(inherited_roles, inherited)
|
|
72
|
+
if inherited_roles.present?
|
|
73
|
+
Monarchy.role_class.select(:id, :inherited, :name)
|
|
74
|
+
.where('inherited = ? OR name IN (?)', inherited, inherited_roles).to_sql
|
|
75
|
+
else
|
|
76
|
+
Monarchy.role_class.select(:id, :inherited).where(inherited: inherited).to_sql
|
|
77
|
+
end
|
|
71
78
|
end
|
|
72
79
|
end
|
|
73
80
|
end
|
|
@@ -51,8 +51,9 @@ module Monarchy
|
|
|
51
51
|
joins(:hierarchy).where(monarchy_hierarchies: { id: hierarchies })
|
|
52
52
|
end)
|
|
53
53
|
|
|
54
|
-
scope :accessible_for, (lambda do |user|
|
|
55
|
-
joins(:hierarchy).where(monarchy_hierarchies: { id: Monarchy.hierarchy_class
|
|
54
|
+
scope :accessible_for, (lambda do |user, inherited_roles = []|
|
|
55
|
+
joins(:hierarchy).where(monarchy_hierarchies: { id: Monarchy.hierarchy_class
|
|
56
|
+
.accessible_for(user, inherited_roles) })
|
|
56
57
|
end)
|
|
57
58
|
end
|
|
58
59
|
|
|
@@ -84,11 +85,13 @@ module Monarchy
|
|
|
84
85
|
end
|
|
85
86
|
|
|
86
87
|
def ensure_hierarchy(force = false)
|
|
88
|
+
return nil unless self.class.automatic_hierarchy || force
|
|
89
|
+
|
|
87
90
|
self.hierarchy ||= Monarchy.hierarchy_class.create(
|
|
88
91
|
resource: self,
|
|
89
92
|
parent: parent.try(:hierarchy),
|
|
90
93
|
children: hierarchies_for(children)
|
|
91
|
-
)
|
|
94
|
+
)
|
|
92
95
|
end
|
|
93
96
|
|
|
94
97
|
private
|
|
@@ -9,8 +9,7 @@ module Monarchy
|
|
|
9
9
|
has_many :hierarchies, through: :members, class_name: "::#{Monarchy.hierarchy_class}"
|
|
10
10
|
|
|
11
11
|
scope :accessible_for, (lambda do |user|
|
|
12
|
-
where(id: Monarchy.
|
|
13
|
-
.joins(members: [:user]).select(:user_id)).union(where(id: user.id))
|
|
12
|
+
where(id: Monarchy.member_class.accessible_for(user).select('user_id AS id')).union(where(id: user.id))
|
|
14
13
|
end)
|
|
15
14
|
|
|
16
15
|
include Monarchy::ActsAsUser::InstanceMethods
|
|
@@ -110,9 +109,9 @@ module Monarchy
|
|
|
110
109
|
def revoking_last_role(role, resource, strategy)
|
|
111
110
|
case strategy
|
|
112
111
|
when :revoke_access
|
|
113
|
-
|
|
112
|
+
revoke_access(resource)
|
|
114
113
|
when :revoke_member
|
|
115
|
-
|
|
114
|
+
member_for(resource).delete
|
|
116
115
|
else
|
|
117
116
|
default_role = Monarchy::Validators.default_role?(resource, role)
|
|
118
117
|
raise Monarchy::Exceptions::RoleNotRevokable if default_role
|
data/lib/monarchy/version.rb
CHANGED
data/monarchy.gemspec
CHANGED
|
@@ -28,11 +28,11 @@ Gem::Specification.new do |s|
|
|
|
28
28
|
|
|
29
29
|
s.add_dependency 'activerecord', '>=4.2.7.1'
|
|
30
30
|
s.add_dependency 'closure_tree', '6.2.0'
|
|
31
|
-
s.add_dependency 'configurations', '2.2.
|
|
31
|
+
s.add_dependency 'configurations', '2.2.2'
|
|
32
32
|
s.add_dependency 'active_record_union', '1.2.0'
|
|
33
33
|
s.add_dependency 'tqdm', '0.3.0'
|
|
34
34
|
|
|
35
35
|
s.add_development_dependency 'bundler', '~> 1.12'
|
|
36
|
-
s.add_development_dependency 'rake', '~>
|
|
36
|
+
s.add_development_dependency 'rake', '~> 12.0'
|
|
37
37
|
s.add_development_dependency 'rspec', '3.5.0'
|
|
38
38
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: monarchy
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.
|
|
4
|
+
version: 2.0.7
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Exelord
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2017-01-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activerecord
|
|
@@ -44,14 +44,14 @@ dependencies:
|
|
|
44
44
|
requirements:
|
|
45
45
|
- - '='
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: 2.2.
|
|
47
|
+
version: 2.2.2
|
|
48
48
|
type: :runtime
|
|
49
49
|
prerelease: false
|
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
52
|
- - '='
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: 2.2.
|
|
54
|
+
version: 2.2.2
|
|
55
55
|
- !ruby/object:Gem::Dependency
|
|
56
56
|
name: active_record_union
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -100,14 +100,14 @@ dependencies:
|
|
|
100
100
|
requirements:
|
|
101
101
|
- - "~>"
|
|
102
102
|
- !ruby/object:Gem::Version
|
|
103
|
-
version: '
|
|
103
|
+
version: '12.0'
|
|
104
104
|
type: :development
|
|
105
105
|
prerelease: false
|
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
|
107
107
|
requirements:
|
|
108
108
|
- - "~>"
|
|
109
109
|
- !ruby/object:Gem::Version
|
|
110
|
-
version: '
|
|
110
|
+
version: '12.0'
|
|
111
111
|
- !ruby/object:Gem::Dependency
|
|
112
112
|
name: rspec
|
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|