monarchy 2.0.0.pre.beta.1 → 2.0.4
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 -0
- data/CHANGELOG.md +155 -11
- data/Gemfile +3 -2
- data/Gemfile.lock +58 -53
- data/README.md +56 -8
- data/docs/acts_as_hierarchy.md +11 -11
- data/docs/acts_as_member.md +34 -0
- data/docs/acts_as_resource.md +13 -11
- data/docs/acts_as_role.md +12 -0
- data/docs/acts_as_user.md +11 -9
- data/docs/installation_and_usage.md +97 -0
- data/dummy/config/application.rb +0 -3
- data/dummy/config/environments/production.rb +1 -1
- data/dummy/config/environments/test.rb +2 -2
- data/lib/monarchy/acts_as_hierarchy.rb +28 -20
- data/lib/monarchy/acts_as_user.rb +13 -6
- data/lib/monarchy/version.rb +1 -1
- data/monarchy.gemspec +2 -1
- metadata +11 -15
- data/docs/installation.md +0 -30
- data/docs/usage.md +0 -22
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 668e988a05baee787f7ede9df0c24c0625559a86
|
|
4
|
+
data.tar.gz: 3e24077bf0b110a0db6afb69a6c75b013e24e67a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 32d61f36e24cac3b72e944d63aa2bf2758872f59adaaeaa8b3736308d3cfd543ad502c6f0c57bcb51ac8873068618bd964b651f1144065f0444d53d5aa5ccb0c
|
|
7
|
+
data.tar.gz: e26d3ef36d35f622889578eb1f6afebc0dc9b3b1cc3d2987090f9555e87929e50670f8c7d600959cb74f907e90bc329b6d7ecf983a53ae08636bfe021077ea02
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
future-release=2.0.4
|
data/CHANGELOG.md
CHANGED
|
@@ -1,11 +1,155 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
## [2.0.4](https://github.com/Exelord/Monarchy/tree/2.0.4) (2016-11-06)
|
|
4
|
+
[Full Changelog](https://github.com/Exelord/Monarchy/compare/v2.0.0-beta.1...2.0.4)
|
|
5
|
+
|
|
6
|
+
**Closed issues:**
|
|
7
|
+
|
|
8
|
+
- Improve performance [\#59](https://github.com/Exelord/Monarchy/issues/59)
|
|
9
|
+
- Default role - is it still needed? [\#48](https://github.com/Exelord/Monarchy/issues/48)
|
|
10
|
+
- Complete Readme and WIKI [\#5](https://github.com/Exelord/Monarchy/issues/5)
|
|
11
|
+
|
|
12
|
+
**Merged pull requests:**
|
|
13
|
+
|
|
14
|
+
- Improve AAH performance [\#60](https://github.com/Exelord/Monarchy/pull/60) ([Exelord](https://github.com/Exelord))
|
|
15
|
+
- Upgrade to Rails 5 [\#55](https://github.com/Exelord/Monarchy/pull/55) ([Exelord](https://github.com/Exelord))
|
|
16
|
+
- Update packages [\#54](https://github.com/Exelord/Monarchy/pull/54) ([Exelord](https://github.com/Exelord))
|
|
17
|
+
- Documentation, improvments and fixes [\#52](https://github.com/Exelord/Monarchy/pull/52) ([Exelord](https://github.com/Exelord))
|
|
18
|
+
|
|
19
|
+
## [v2.0.0-beta.1](https://github.com/Exelord/Monarchy/tree/v2.0.0-beta.1) (2016-09-10)
|
|
20
|
+
[Full Changelog](https://github.com/Exelord/Monarchy/compare/v1.2.0...v2.0.0-beta.1)
|
|
21
|
+
|
|
22
|
+
**Fixed bugs:**
|
|
23
|
+
|
|
24
|
+
- Quick fix for v2.0 [\#51](https://github.com/Exelord/Monarchy/pull/51) ([Exelord](https://github.com/Exelord))
|
|
25
|
+
|
|
26
|
+
**Merged pull requests:**
|
|
27
|
+
|
|
28
|
+
- Remove default role granting [\#50](https://github.com/Exelord/Monarchy/pull/50) ([Exelord](https://github.com/Exelord))
|
|
29
|
+
|
|
30
|
+
## [v1.2.0](https://github.com/Exelord/Monarchy/tree/v1.2.0) (2016-08-26)
|
|
31
|
+
[Full Changelog](https://github.com/Exelord/Monarchy/compare/v1.1.5...v1.2.0)
|
|
32
|
+
|
|
33
|
+
**Fixed bugs:**
|
|
34
|
+
|
|
35
|
+
- Probably missing tests [\#20](https://github.com/Exelord/Monarchy/issues/20)
|
|
36
|
+
- Rise errors where incorrect resource was assigned [\#19](https://github.com/Exelord/Monarchy/issues/19)
|
|
37
|
+
|
|
38
|
+
**Merged pull requests:**
|
|
39
|
+
|
|
40
|
+
- Feature exceptions [\#42](https://github.com/Exelord/Monarchy/pull/42) ([Exelord](https://github.com/Exelord))
|
|
41
|
+
|
|
42
|
+
## [v1.1.5](https://github.com/Exelord/Monarchy/tree/v1.1.5) (2016-08-19)
|
|
43
|
+
[Full Changelog](https://github.com/Exelord/Monarchy/compare/v1.1.4...v1.1.5)
|
|
44
|
+
|
|
45
|
+
**Fixed bugs:**
|
|
46
|
+
|
|
47
|
+
- Fix for assign parent [\#47](https://github.com/Exelord/Monarchy/pull/47) ([Exelord](https://github.com/Exelord))
|
|
48
|
+
|
|
49
|
+
## [v1.1.4](https://github.com/Exelord/Monarchy/tree/v1.1.4) (2016-08-16)
|
|
50
|
+
[Full Changelog](https://github.com/Exelord/Monarchy/compare/v1.1.3...v1.1.4)
|
|
51
|
+
|
|
52
|
+
**Fixed bugs:**
|
|
53
|
+
|
|
54
|
+
- Move tasks to Monarchy methods [\#46](https://github.com/Exelord/Monarchy/pull/46) ([Exelord](https://github.com/Exelord))
|
|
55
|
+
|
|
56
|
+
## [v1.1.3](https://github.com/Exelord/Monarchy/tree/v1.1.3) (2016-08-15)
|
|
57
|
+
[Full Changelog](https://github.com/Exelord/Monarchy/compare/v.1.1.1...v1.1.3)
|
|
58
|
+
|
|
59
|
+
**Merged pull requests:**
|
|
60
|
+
|
|
61
|
+
- Fix assign parent [\#45](https://github.com/Exelord/Monarchy/pull/45) ([Exelord](https://github.com/Exelord))
|
|
62
|
+
|
|
63
|
+
## [v.1.1.1](https://github.com/Exelord/Monarchy/tree/v.1.1.1) (2016-08-15)
|
|
64
|
+
[Full Changelog](https://github.com/Exelord/Monarchy/compare/v1.0.0...v.1.1.1)
|
|
65
|
+
|
|
66
|
+
**Fixed bugs:**
|
|
67
|
+
|
|
68
|
+
- Fix revoking role [\#44](https://github.com/Exelord/Monarchy/pull/44) ([Exelord](https://github.com/Exelord))
|
|
69
|
+
- Fix rake tasks [\#43](https://github.com/Exelord/Monarchy/pull/43) ([Exelord](https://github.com/Exelord))
|
|
70
|
+
|
|
71
|
+
**Closed issues:**
|
|
72
|
+
|
|
73
|
+
- Rise warnings [\#3](https://github.com/Exelord/Monarchy/issues/3)
|
|
74
|
+
|
|
75
|
+
**Merged pull requests:**
|
|
76
|
+
|
|
77
|
+
- Feature better restricted roles [\#41](https://github.com/Exelord/Monarchy/pull/41) ([Exelord](https://github.com/Exelord))
|
|
78
|
+
- Update gems [\#40](https://github.com/Exelord/Monarchy/pull/40) ([Exelord](https://github.com/Exelord))
|
|
79
|
+
|
|
80
|
+
## [v1.0.0](https://github.com/Exelord/Monarchy/tree/v1.0.0) (2016-08-05)
|
|
81
|
+
[Full Changelog](https://github.com/Exelord/Monarchy/compare/v0.3.1...v1.0.0)
|
|
82
|
+
|
|
83
|
+
**Fixed bugs:**
|
|
84
|
+
|
|
85
|
+
- Teams [\#36](https://github.com/Exelord/Monarchy/pull/36) ([Exelord](https://github.com/Exelord))
|
|
86
|
+
|
|
87
|
+
**Closed issues:**
|
|
88
|
+
|
|
89
|
+
- Dynamic relationships [\#32](https://github.com/Exelord/Monarchy/issues/32)
|
|
90
|
+
- Extend `parent\_as` method [\#17](https://github.com/Exelord/Monarchy/issues/17)
|
|
91
|
+
- Custom Up and down roles inheritence [\#15](https://github.com/Exelord/Monarchy/issues/15)
|
|
92
|
+
|
|
93
|
+
**Merged pull requests:**
|
|
94
|
+
|
|
95
|
+
- Revert "Update gems - Rails 5" [\#39](https://github.com/Exelord/Monarchy/pull/39) ([Exelord](https://github.com/Exelord))
|
|
96
|
+
- Feature dynamic classes [\#38](https://github.com/Exelord/Monarchy/pull/38) ([Exelord](https://github.com/Exelord))
|
|
97
|
+
- Update gems - Rails 5 [\#37](https://github.com/Exelord/Monarchy/pull/37) ([Exelord](https://github.com/Exelord))
|
|
98
|
+
|
|
99
|
+
## [v0.3.1](https://github.com/Exelord/Monarchy/tree/v0.3.1) (2016-05-29)
|
|
100
|
+
[Full Changelog](https://github.com/Exelord/Monarchy/compare/v0.2.0...v0.3.1)
|
|
101
|
+
|
|
102
|
+
**Fixed bugs:**
|
|
103
|
+
|
|
104
|
+
- Rework on roles\_for [\#28](https://github.com/Exelord/Monarchy/issues/28)
|
|
105
|
+
- Rspec warnings [\#25](https://github.com/Exelord/Monarchy/issues/25)
|
|
106
|
+
- Internal hierarchy model [\#4](https://github.com/Exelord/Monarchy/issues/4)
|
|
107
|
+
- Fix closure tree [\#30](https://github.com/Exelord/Monarchy/pull/30) ([PoslinskiNet](https://github.com/PoslinskiNet))
|
|
108
|
+
- Fix directory name [\#26](https://github.com/Exelord/Monarchy/pull/26) ([Exelord](https://github.com/Exelord))
|
|
109
|
+
|
|
110
|
+
**Closed issues:**
|
|
111
|
+
|
|
112
|
+
- Better revoking roles [\#18](https://github.com/Exelord/Monarchy/issues/18)
|
|
113
|
+
|
|
114
|
+
**Merged pull requests:**
|
|
115
|
+
|
|
116
|
+
- Add gitter channel [\#35](https://github.com/Exelord/Monarchy/pull/35) ([Exelord](https://github.com/Exelord))
|
|
117
|
+
- DEP\#27 Refactored specs and fixes [\#31](https://github.com/Exelord/Monarchy/pull/31) ([Exelord](https://github.com/Exelord))
|
|
118
|
+
- Another big bang theory [\#27](https://github.com/Exelord/Monarchy/pull/27) ([Exelord](https://github.com/Exelord))
|
|
119
|
+
|
|
120
|
+
## [v0.2.0](https://github.com/Exelord/Monarchy/tree/v0.2.0) (2016-04-20)
|
|
121
|
+
[Full Changelog](https://github.com/Exelord/Monarchy/compare/v0.1-alpha...v0.2.0)
|
|
122
|
+
|
|
123
|
+
**Fixed bugs:**
|
|
124
|
+
|
|
125
|
+
- Rename Hierarchy\_spec.rb to hierarchy\_spec.rb [\#23](https://github.com/Exelord/Monarchy/pull/23) ([Exelord](https://github.com/Exelord))
|
|
126
|
+
|
|
127
|
+
**Closed issues:**
|
|
128
|
+
|
|
129
|
+
- Renaming gem :D [\#21](https://github.com/Exelord/Monarchy/issues/21)
|
|
130
|
+
- Scope modules into Treelify [\#13](https://github.com/Exelord/Monarchy/issues/13)
|
|
131
|
+
- When deleting Role delete also members role relation [\#1](https://github.com/Exelord/Monarchy/issues/1)
|
|
132
|
+
|
|
133
|
+
**Merged pull requests:**
|
|
134
|
+
|
|
135
|
+
- Feature gem renaming [\#24](https://github.com/Exelord/Monarchy/pull/24) ([Exelord](https://github.com/Exelord))
|
|
136
|
+
- Feature scoped modules [\#22](https://github.com/Exelord/Monarchy/pull/22) ([Exelord](https://github.com/Exelord))
|
|
137
|
+
|
|
138
|
+
## [v0.1-alpha](https://github.com/Exelord/Monarchy/tree/v0.1-alpha) (2016-04-12)
|
|
139
|
+
**Closed issues:**
|
|
140
|
+
|
|
141
|
+
- Revoke user from resource [\#2](https://github.com/Exelord/Monarchy/issues/2)
|
|
142
|
+
|
|
143
|
+
**Merged pull requests:**
|
|
144
|
+
|
|
145
|
+
- Dependent destroy on MembersRole [\#14](https://github.com/Exelord/Monarchy/pull/14) ([Exelord](https://github.com/Exelord))
|
|
146
|
+
- User revoke [\#12](https://github.com/Exelord/Monarchy/pull/12) ([Exelord](https://github.com/Exelord))
|
|
147
|
+
- Update README.md [\#11](https://github.com/Exelord/Monarchy/pull/11) ([Exelord](https://github.com/Exelord))
|
|
148
|
+
- Resource documentation [\#10](https://github.com/Exelord/Monarchy/pull/10) ([Exelord](https://github.com/Exelord))
|
|
149
|
+
- Parent as option [\#9](https://github.com/Exelord/Monarchy/pull/9) ([Exelord](https://github.com/Exelord))
|
|
150
|
+
- Bump ruby to 2.3.0 [\#8](https://github.com/Exelord/Monarchy/pull/8) ([Exelord](https://github.com/Exelord))
|
|
151
|
+
- Add missing tests [\#7](https://github.com/Exelord/Monarchy/pull/7) ([Exelord](https://github.com/Exelord))
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
data/Gemfile
CHANGED
|
@@ -25,7 +25,8 @@ group :development, :test do
|
|
|
25
25
|
gem 'ffaker', '2.2.0'
|
|
26
26
|
gem 'database_cleaner', '1.5.3'
|
|
27
27
|
gem 'tqdm', '0.3.0'
|
|
28
|
+
gem 'rails', '5.0.0.1'
|
|
28
29
|
end
|
|
29
30
|
|
|
30
|
-
gem 'simplecov', '0.12.0',
|
|
31
|
-
gem 'codeclimate-test-reporter', group: :test
|
|
31
|
+
gem 'simplecov', '0.12.0', group: :test
|
|
32
|
+
gem 'codeclimate-test-reporter', '1.0.0', group: :test
|
data/Gemfile.lock
CHANGED
|
@@ -1,61 +1,62 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
monarchy (2.0.
|
|
4
|
+
monarchy (2.0.4)
|
|
5
5
|
active_record_union (= 1.2.0)
|
|
6
|
+
activerecord (>= 4.2.7.1)
|
|
6
7
|
closure_tree (= 6.2.0)
|
|
7
8
|
configurations (= 2.2.1)
|
|
8
|
-
rails (~> 4.2, >= 4.2.7.1)
|
|
9
9
|
tqdm (= 0.3.0)
|
|
10
10
|
|
|
11
11
|
GEM
|
|
12
12
|
remote: https://rubygems.org/
|
|
13
13
|
specs:
|
|
14
|
-
|
|
15
|
-
actionpack (=
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
actioncable (5.0.0.1)
|
|
15
|
+
actionpack (= 5.0.0.1)
|
|
16
|
+
nio4r (~> 1.2)
|
|
17
|
+
websocket-driver (~> 0.6.1)
|
|
18
|
+
actionmailer (5.0.0.1)
|
|
19
|
+
actionpack (= 5.0.0.1)
|
|
20
|
+
actionview (= 5.0.0.1)
|
|
21
|
+
activejob (= 5.0.0.1)
|
|
18
22
|
mail (~> 2.5, >= 2.5.4)
|
|
19
|
-
rails-dom-testing (~>
|
|
20
|
-
actionpack (
|
|
21
|
-
actionview (=
|
|
22
|
-
activesupport (=
|
|
23
|
-
rack (~>
|
|
24
|
-
rack-test (~> 0.6.
|
|
25
|
-
rails-dom-testing (~>
|
|
23
|
+
rails-dom-testing (~> 2.0)
|
|
24
|
+
actionpack (5.0.0.1)
|
|
25
|
+
actionview (= 5.0.0.1)
|
|
26
|
+
activesupport (= 5.0.0.1)
|
|
27
|
+
rack (~> 2.0)
|
|
28
|
+
rack-test (~> 0.6.3)
|
|
29
|
+
rails-dom-testing (~> 2.0)
|
|
26
30
|
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
|
27
|
-
actionview (
|
|
28
|
-
activesupport (=
|
|
31
|
+
actionview (5.0.0.1)
|
|
32
|
+
activesupport (= 5.0.0.1)
|
|
29
33
|
builder (~> 3.1)
|
|
30
34
|
erubis (~> 2.7.0)
|
|
31
|
-
rails-dom-testing (~>
|
|
35
|
+
rails-dom-testing (~> 2.0)
|
|
32
36
|
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
|
33
37
|
active_record_union (1.2.0)
|
|
34
38
|
activerecord (>= 4.0)
|
|
35
|
-
activejob (
|
|
36
|
-
activesupport (=
|
|
37
|
-
globalid (>= 0.3.
|
|
38
|
-
activemodel (
|
|
39
|
-
activesupport (=
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
39
|
+
activejob (5.0.0.1)
|
|
40
|
+
activesupport (= 5.0.0.1)
|
|
41
|
+
globalid (>= 0.3.6)
|
|
42
|
+
activemodel (5.0.0.1)
|
|
43
|
+
activesupport (= 5.0.0.1)
|
|
44
|
+
activerecord (5.0.0.1)
|
|
45
|
+
activemodel (= 5.0.0.1)
|
|
46
|
+
activesupport (= 5.0.0.1)
|
|
47
|
+
arel (~> 7.0)
|
|
48
|
+
activesupport (5.0.0.1)
|
|
49
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
46
50
|
i18n (~> 0.7)
|
|
47
|
-
json (~> 1.7, >= 1.7.7)
|
|
48
51
|
minitest (~> 5.1)
|
|
49
|
-
thread_safe (~> 0.3, >= 0.3.4)
|
|
50
52
|
tzinfo (~> 1.1)
|
|
51
|
-
arel (
|
|
53
|
+
arel (7.1.4)
|
|
52
54
|
ast (2.3.0)
|
|
53
55
|
builder (3.2.2)
|
|
54
56
|
closure_tree (6.2.0)
|
|
55
57
|
activerecord (>= 4.1.0)
|
|
56
58
|
with_advisory_lock (>= 3.0.0)
|
|
57
|
-
codeclimate-test-reporter (0.
|
|
58
|
-
simplecov (>= 0.7.1, < 1.0.0)
|
|
59
|
+
codeclimate-test-reporter (1.0.0)
|
|
59
60
|
coderay (1.1.1)
|
|
60
61
|
concurrent-ruby (1.0.2)
|
|
61
62
|
configurations (2.2.1)
|
|
@@ -72,7 +73,7 @@ GEM
|
|
|
72
73
|
globalid (0.3.7)
|
|
73
74
|
activesupport (>= 4.1.0)
|
|
74
75
|
i18n (0.7.0)
|
|
75
|
-
json (
|
|
76
|
+
json (2.0.2)
|
|
76
77
|
loofah (2.0.3)
|
|
77
78
|
nokogiri (>= 1.5.9)
|
|
78
79
|
mail (2.6.4)
|
|
@@ -83,6 +84,7 @@ GEM
|
|
|
83
84
|
mime-types-data (3.2016.0521)
|
|
84
85
|
mini_portile2 (2.1.0)
|
|
85
86
|
minitest (5.9.1)
|
|
87
|
+
nio4r (1.2.1)
|
|
86
88
|
nokogiri (1.6.8.1)
|
|
87
89
|
mini_portile2 (~> 2.1.0)
|
|
88
90
|
parser (2.3.1.4)
|
|
@@ -94,31 +96,30 @@ GEM
|
|
|
94
96
|
slop (~> 3.4)
|
|
95
97
|
pry-rails (0.3.4)
|
|
96
98
|
pry (>= 0.9.10)
|
|
97
|
-
rack (
|
|
99
|
+
rack (2.0.1)
|
|
98
100
|
rack-test (0.6.3)
|
|
99
101
|
rack (>= 1.0)
|
|
100
|
-
rails (
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
102
|
+
rails (5.0.0.1)
|
|
103
|
+
actioncable (= 5.0.0.1)
|
|
104
|
+
actionmailer (= 5.0.0.1)
|
|
105
|
+
actionpack (= 5.0.0.1)
|
|
106
|
+
actionview (= 5.0.0.1)
|
|
107
|
+
activejob (= 5.0.0.1)
|
|
108
|
+
activemodel (= 5.0.0.1)
|
|
109
|
+
activerecord (= 5.0.0.1)
|
|
110
|
+
activesupport (= 5.0.0.1)
|
|
108
111
|
bundler (>= 1.3.0, < 2.0)
|
|
109
|
-
railties (=
|
|
110
|
-
sprockets-rails
|
|
111
|
-
rails-
|
|
112
|
-
activesupport (>= 4.2.0.
|
|
113
|
-
rails-dom-testing (1.0.7)
|
|
114
|
-
activesupport (>= 4.2.0.beta, < 5.0)
|
|
112
|
+
railties (= 5.0.0.1)
|
|
113
|
+
sprockets-rails (>= 2.0.0)
|
|
114
|
+
rails-dom-testing (2.0.1)
|
|
115
|
+
activesupport (>= 4.2.0, < 6.0)
|
|
115
116
|
nokogiri (~> 1.6.0)
|
|
116
|
-
rails-deprecated_sanitizer (>= 1.0.1)
|
|
117
117
|
rails-html-sanitizer (1.0.3)
|
|
118
118
|
loofah (~> 2.0)
|
|
119
|
-
railties (
|
|
120
|
-
actionpack (=
|
|
121
|
-
activesupport (=
|
|
119
|
+
railties (5.0.0.1)
|
|
120
|
+
actionpack (= 5.0.0.1)
|
|
121
|
+
activesupport (= 5.0.0.1)
|
|
122
|
+
method_source
|
|
122
123
|
rake (>= 0.8.7)
|
|
123
124
|
thor (>= 0.18.1, < 2.0)
|
|
124
125
|
rainbow (2.1.0)
|
|
@@ -173,6 +174,9 @@ GEM
|
|
|
173
174
|
tzinfo (1.2.2)
|
|
174
175
|
thread_safe (~> 0.1)
|
|
175
176
|
unicode-display_width (1.1.1)
|
|
177
|
+
websocket-driver (0.6.4)
|
|
178
|
+
websocket-extensions (>= 0.1.0)
|
|
179
|
+
websocket-extensions (0.1.2)
|
|
176
180
|
with_advisory_lock (3.0.0)
|
|
177
181
|
activerecord (>= 3.2)
|
|
178
182
|
thread_safe
|
|
@@ -182,12 +186,13 @@ PLATFORMS
|
|
|
182
186
|
|
|
183
187
|
DEPENDENCIES
|
|
184
188
|
bundler (~> 1.12)
|
|
185
|
-
codeclimate-test-reporter
|
|
189
|
+
codeclimate-test-reporter (= 1.0.0)
|
|
186
190
|
database_cleaner (= 1.5.3)
|
|
187
191
|
factory_girl_rails (= 4.7.0)
|
|
188
192
|
ffaker (= 2.2.0)
|
|
189
193
|
monarchy!
|
|
190
194
|
pry-rails (= 0.3.4)
|
|
195
|
+
rails (= 5.0.0.1)
|
|
191
196
|
rake (~> 11.3)
|
|
192
197
|
rspec (= 3.5.0)
|
|
193
198
|
rspec-rails (= 3.5.2)
|
data/README.md
CHANGED
|
@@ -1,14 +1,60 @@
|
|
|
1
|
-
[](https://travis-ci.org/Exelord/Monarchy)
|
|
2
|
-
[](https://gemnasium.com/github.com/Exelord/Monarchy)
|
|
3
|
-
[](https://gitter.im/Exelord/Monarchy?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
|
4
|
-
[](https://codeclimate.com/github/Exelord/Monarchy)
|
|
5
|
-
|
|
6
1
|
<p align="center">
|
|
7
|
-
<img
|
|
2
|
+
<img src="monarchy.png?raw=true" alt="Sublime's custom image"/>
|
|
3
|
+
<a href="https://travis-ci.org/Exelord/Monarchy">
|
|
4
|
+
<img src="https://travis-ci.org/Exelord/Monarchy.svg?branch=master">
|
|
5
|
+
</a>
|
|
6
|
+
<a href="https://gemnasium.com/github.com/Exelord/Monarchy">
|
|
7
|
+
<img src="https://gemnasium.com/badges/github.com/Exelord/Monarchy.svg">
|
|
8
|
+
</a>
|
|
9
|
+
<a href="https://gitter.im/Exelord/Monarchy?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge">
|
|
10
|
+
<img src="https://badges.gitter.im/Exelord/Monarchy.svg">
|
|
11
|
+
</a>
|
|
12
|
+
<a href="https://codeclimate.com/github/Exelord/Monarchy">
|
|
13
|
+
<img src="https://codeclimate.com/github/Exelord/Monarchy/badges/gpa.svg">
|
|
14
|
+
</a>
|
|
8
15
|
</p>
|
|
9
16
|
|
|
17
|
+
Monarchy is a ruby gem offering a complete solution to manage an access in your web application.
|
|
18
|
+
Hierarchical structure and built-in roles inheritance options make it the most powerful tool to control an access to your resources.
|
|
19
|
+
|
|
20
|
+
Thanks to [closure_tree](https://github.com/mceachen/closure_tree), Monarchy can deliver the best in class algorithmic performance and allows you to forget about hierarchies and complicated structures.
|
|
21
|
+
|
|
22
|
+
It is like a [rolify](https://github.com/RolifyCommunity/rolify) but with advanced possibilities to inherit roles and collect all accessible resources with just one method.
|
|
23
|
+
|
|
24
|
+
## Usage Example
|
|
25
|
+
After Monarchy setup you can enjoy with roles inheritance and accessible resources.
|
|
26
|
+
|
|
27
|
+
```ruby
|
|
28
|
+
# Create roles
|
|
29
|
+
admin_role = Monarchy.role_class.create(name: :admin, level: 5, inherited: true)
|
|
30
|
+
manager_role = Monarchy.role_class.create(name: :manager, level: 4, inherited_role: admin_role, inherited: true)
|
|
31
|
+
|
|
32
|
+
# Create resources
|
|
33
|
+
project1 = Project.create()
|
|
34
|
+
project2 = Project.create(parent: project1)
|
|
35
|
+
project3 = Project.create(parent: project2)
|
|
36
|
+
project4 = Project.create()
|
|
37
|
+
|
|
38
|
+
# Grant user
|
|
39
|
+
user.grant(:manager, project2)
|
|
40
|
+
|
|
41
|
+
# Accessible projects
|
|
42
|
+
Project.accessible_for(user) # returns [Project1, Project2, Project3]
|
|
43
|
+
|
|
44
|
+
# User inherited roles
|
|
45
|
+
user.roles_for(project1) # returns a default role eg. [guest_role]
|
|
46
|
+
user.roles_for(project2) # returns [manager_role]
|
|
47
|
+
user.roles_for(project3) # returns [admin_role]
|
|
48
|
+
user.roles_for(project4) # returns empty array []
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Requirements
|
|
52
|
+
Monarchy requires:
|
|
53
|
+
- Ruby 2.3
|
|
54
|
+
|
|
10
55
|
## Documentation
|
|
11
|
-
|
|
56
|
+
We are preparing an official [website][5c7e0096] with documentation.
|
|
57
|
+
Meanwhile you can look to the `docs` directory for actual [documentation](https://github.com/Exelord/Monarchy/tree/master/docs).
|
|
12
58
|
|
|
13
59
|
## Contributing
|
|
14
60
|
|
|
@@ -16,4 +62,6 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/exelor
|
|
|
16
62
|
|
|
17
63
|
## License
|
|
18
64
|
|
|
19
|
-
|
|
65
|
+
This version of the gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
|
66
|
+
|
|
67
|
+
[5c7e0096]: https://exelord.github.io/Monarchy/ "Monarchy Website"
|
data/docs/acts_as_hierarchy.md
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
|
|
1
|
+
# Hierarchy
|
|
2
2
|
`Hierarchy` is an internal model of `Monarchy` and should not be used unless it is really necessary.
|
|
3
3
|
|
|
4
4
|
> hmm... sounds like `private`
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
## Methods
|
|
7
7
|
** We do not recommend to use it but if yo have to: **
|
|
8
8
|
We are using [Closure Tree][e5c808aa] behind `Hierarchy` class. There is a bunch of methods and functions available behind the hood. Check their documentation.
|
|
9
9
|
|
|
10
10
|
[e5c808aa]: https://github.com/mceachen/closure_tree "Closure Tree"
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
## Scopes:
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
### .accessible_for
|
|
15
15
|
You can select all hierarchies accessible for specific user by using a scope: `accessible_for`, eg:
|
|
16
16
|
``` ruby
|
|
17
|
-
Monarchy
|
|
17
|
+
Monarchy.hierarchy_class.accessible_for(current_user) # returns [hierarchy1, hierarchy2, hierarchy5]
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
### .in(resource, true)
|
|
21
21
|
You can select all hierarchies scoped into another by using scope: `in`:
|
|
22
22
|
|
|
23
23
|
- If the second argument is `true` (`true` is by default):
|
|
24
24
|
``` ruby
|
|
25
|
-
Monarchy
|
|
25
|
+
Monarchy.hierarchy_class.in(project.hierarchy) # returns [hierarchy1, hierarchy2, hierarchy5]
|
|
26
26
|
```
|
|
27
27
|
It will returns for you all `hierarchies` which parent is `project.hierarchy` or one of his children.
|
|
28
28
|
|
|
29
29
|
- If the second argument is `false`:
|
|
30
30
|
``` ruby
|
|
31
|
-
Monarchy
|
|
31
|
+
Monarchy.hierarchy_class.in(project.hierarchy, false) # returns [hierarchy1, hierarchy2]
|
|
32
32
|
```
|
|
33
33
|
It will returns for you all `hierarchies` which parent is `project.hierarchy`
|
|
34
34
|
|
|
35
35
|
|
|
36
36
|
## Relations
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
### #members
|
|
39
39
|
Return all members explicitly granted to the hierarchy.
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
### #users
|
|
42
42
|
Returns all users which have been granted explicitly to the hierarchy.
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
### #resource
|
|
45
45
|
Returns a resource model of the hierarchy.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Member
|
|
2
|
+
It is a model of class which was registered in Monarchy config and is acting as `acts_as_member`.
|
|
3
|
+
|
|
4
|
+
## Methods:
|
|
5
|
+
|
|
6
|
+
### #resource
|
|
7
|
+
Returns a resource of member, example:
|
|
8
|
+
``` ruby
|
|
9
|
+
User was granted to Project so the resource of his Member will be Project
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
### #resource=
|
|
13
|
+
You can overwrite a `#resource` for `member` by using:
|
|
14
|
+
```ruby
|
|
15
|
+
member.resource = new_resource_model
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Scopes:
|
|
19
|
+
|
|
20
|
+
### .accessible_for
|
|
21
|
+
You can select all members accessible for specific user by using a scope: `accessible_for`, eg:
|
|
22
|
+
``` ruby
|
|
23
|
+
Monarchy::member_class.accessible_for(current_user) # returns [member1, member2, member5]
|
|
24
|
+
```
|
|
25
|
+
## Public Relations:
|
|
26
|
+
|
|
27
|
+
### #roles
|
|
28
|
+
Returns all roles explicitly assigned to the member.
|
|
29
|
+
|
|
30
|
+
### #user
|
|
31
|
+
Returns a user model of the member.
|
|
32
|
+
|
|
33
|
+
### #hierarchy
|
|
34
|
+
Returns a hierarchy model of the member.
|
data/docs/acts_as_resource.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# Resource
|
|
2
|
+
|
|
1
3
|
To generate a new resource you can use:
|
|
2
4
|
```
|
|
3
5
|
rails g monarchy:resource [resource_name]
|
|
@@ -9,7 +11,7 @@ class Resource < ActiveRecord::Base
|
|
|
9
11
|
end
|
|
10
12
|
```
|
|
11
13
|
|
|
12
|
-
|
|
14
|
+
#### - Options
|
|
13
15
|
You can pass an options to `acts_as_resource`:
|
|
14
16
|
- `parent_as: :association_name`
|
|
15
17
|
|
|
@@ -27,7 +29,7 @@ You can pass an options to `acts_as_resource`:
|
|
|
27
29
|
|
|
28
30
|
## Methods
|
|
29
31
|
|
|
30
|
-
|
|
32
|
+
### #parent
|
|
31
33
|
You can easily assign parent by using `parent=` method, eg:
|
|
32
34
|
``` ruby
|
|
33
35
|
resource.parent = Project.last
|
|
@@ -39,7 +41,7 @@ resource.parent # returns Project.last
|
|
|
39
41
|
|
|
40
42
|
Parents can be only models which have `acts_as_resource`
|
|
41
43
|
|
|
42
|
-
|
|
44
|
+
### #children
|
|
43
45
|
You can easily assign children by using `children=` method, eg:
|
|
44
46
|
``` ruby
|
|
45
47
|
resource.children = [child1, child2, child3]
|
|
@@ -50,25 +52,25 @@ resource.children # returns [child1, child2, child3]
|
|
|
50
52
|
```
|
|
51
53
|
Children can be only models which have `acts_as_resource`
|
|
52
54
|
|
|
53
|
-
|
|
55
|
+
### #ensure_hierarchy
|
|
54
56
|
It creates a hierarchy for resource model if it not exist and `automatic_hierarchy` flag is set to true.
|
|
55
57
|
If you want to bypass `automatic_hierarchy` flag you can pass `true` to the method params.
|
|
56
58
|
|
|
57
|
-
|
|
59
|
+
### .default_role_name
|
|
58
60
|
Returns default role name for the class
|
|
59
61
|
|
|
60
|
-
|
|
62
|
+
### .default_role
|
|
61
63
|
Returns default role object `Monarchy::Role` for the class
|
|
62
64
|
|
|
63
65
|
### Scopes:
|
|
64
66
|
|
|
65
|
-
|
|
67
|
+
### .accessible_for
|
|
66
68
|
You can select all resources accessible for specyfic user by using scope: `accessible_for`, eg:
|
|
67
69
|
``` ruby
|
|
68
70
|
Resource.accessible_for(current_user) # returns [resource1, resource2, resource5]
|
|
69
71
|
```
|
|
70
72
|
|
|
71
|
-
|
|
73
|
+
### .in(resource, true)
|
|
72
74
|
You can select all resources scoped into another by using scope: `in`:
|
|
73
75
|
|
|
74
76
|
- If the second argument is `true` (`true` is by default):
|
|
@@ -86,13 +88,13 @@ It will return for you all `resources` which parent is `Project.first`
|
|
|
86
88
|
|
|
87
89
|
## Relations
|
|
88
90
|
|
|
89
|
-
|
|
91
|
+
### #members
|
|
90
92
|
Return all members explicitly granted to the resource.
|
|
91
93
|
|
|
92
|
-
|
|
94
|
+
### #users
|
|
93
95
|
Returns all users which have been granted explicitly to the resource.
|
|
94
96
|
|
|
95
|
-
|
|
97
|
+
### #hierarchy
|
|
96
98
|
Returns a hierarchy model of the resource. (DO NOT USE UNLESS IS NECESSARY)
|
|
97
99
|
|
|
98
100
|
## Flags
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Role
|
|
2
|
+
|
|
3
|
+
It is a model of a class which was registered in Monarchy config and is acting as `acts_as_role`.
|
|
4
|
+
|
|
5
|
+
## Public Relations:
|
|
6
|
+
|
|
7
|
+
### #members
|
|
8
|
+
Returns all members with the role which was explicitly assigned.
|
|
9
|
+
|
|
10
|
+
### #inherited_role
|
|
11
|
+
Returns a `role` which will be inherited to lower level resources.
|
|
12
|
+
> If you would like to know more about `inherited_role` check the `Usage` page.
|
data/docs/acts_as_user.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# User
|
|
2
|
+
|
|
1
3
|
You have to add it to your user model or the custom one specified in a config file.
|
|
2
4
|
|
|
3
5
|
``` ruby
|
|
@@ -8,43 +10,43 @@ end
|
|
|
8
10
|
|
|
9
11
|
## Relations
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
### .hierarchies
|
|
12
14
|
Return all hierarchies in which user is explicitly granted.
|
|
13
15
|
|
|
14
|
-
|
|
16
|
+
### .members
|
|
15
17
|
Returns all memberships (`member` model) of the user
|
|
16
18
|
|
|
17
19
|
## Scopes
|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
### .accessible_for (user)
|
|
20
22
|
Returns all users accessible for the specific user
|
|
21
23
|
It includes all users from all resource which the user has any access.
|
|
22
24
|
|
|
23
25
|
## Methods
|
|
24
26
|
|
|
25
|
-
|
|
27
|
+
### #roles_for(resource, inheritance = true)
|
|
26
28
|
Returns all roles for the user to the specific `resource`.
|
|
27
29
|
You can choose if this method should return also inherited roles or just these, granted explicitly.
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
### #member_for(resource)
|
|
30
32
|
Returns a `member` object for the user in specyfic resource.
|
|
31
33
|
|
|
32
|
-
|
|
34
|
+
### #grant(role_names, resource)
|
|
33
35
|
By this method, you can give the user an access to a specific resource.
|
|
34
36
|
You can specify a role name or an array of roles names.
|
|
35
37
|
**Remember to use `symbols`!**
|
|
36
38
|
|
|
37
|
-
|
|
39
|
+
### #revoke_access(resource)
|
|
38
40
|
You can revoke total access of a user from the resource and his children by using this method.
|
|
39
41
|
Optionally you can specify `hierarchies` as the second argument from which user's members should be deleted.
|
|
40
42
|
|
|
41
|
-
|
|
43
|
+
### #revoke_role(role_name, resource)
|
|
42
44
|
It revokes specified role from a user's member of the resource.
|
|
43
45
|
If is it last role and the default for the resource it will raise an error `Monarchy::Exceptions::RoleNotRevokable`. Otherwise, if it's just a last role it will remove the one and grant a user with default one.
|
|
44
46
|
|
|
45
47
|
**It guaranty that user will have always last role or a default one**
|
|
46
48
|
|
|
47
|
-
|
|
49
|
+
### #revoke_role!(role_name, resource)
|
|
48
50
|
It behaves exactly like `#revoke_role` but with one difference during revoking last_role.
|
|
49
51
|
Depend on which `revoke_strategy` did you choose in configuration,
|
|
50
52
|
it will delete a member after revoking the last role or will revoke an access to the resource.
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Installation and Usage
|
|
2
|
+
|
|
3
|
+
## Install a gem
|
|
4
|
+
Add this line to your application's Gemfile:
|
|
5
|
+
|
|
6
|
+
```ruby
|
|
7
|
+
gem 'monarchy'
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
And then execute:
|
|
11
|
+
|
|
12
|
+
$ bundle
|
|
13
|
+
|
|
14
|
+
To create initials migrations and necessary files run:
|
|
15
|
+
```
|
|
16
|
+
rails g monarchy:setup
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
This will create for you:
|
|
20
|
+
|
|
21
|
+
1. Migrations:
|
|
22
|
+
- `monarchy_create_users`
|
|
23
|
+
- `monarchy_create_hierarchies`
|
|
24
|
+
- `monarchy_create_memberships`
|
|
25
|
+
2. Configuration file in `config/initializers/monarchy`
|
|
26
|
+
3. Default `User` model (optional)
|
|
27
|
+
|
|
28
|
+
**If you want to use your current `User` model just skip generation of: **
|
|
29
|
+
- `db/migrate/monarchy_create_users.rb`
|
|
30
|
+
- `app/models/user.rb`
|
|
31
|
+
|
|
32
|
+
And add to your current `User` model `acts_as_user`
|
|
33
|
+
|
|
34
|
+
## Create roles
|
|
35
|
+
Go to `rails console` or create a migration with your new roles.
|
|
36
|
+
|
|
37
|
+
### How to create a role?
|
|
38
|
+
Think about your roles structure.
|
|
39
|
+
You can access role class through: `Monarchy.role_class`
|
|
40
|
+
|
|
41
|
+
Below you can find `Role` parameters with description.
|
|
42
|
+
|
|
43
|
+
#### Properties description
|
|
44
|
+
|
|
45
|
+
- `name` - `REQUIRED` - `symbol` - name of the role
|
|
46
|
+
|
|
47
|
+
- `level` - `0 as DEFAULT` - `number` - higher level means higher level of access, eg. Admin has 10, User has 1
|
|
48
|
+
|
|
49
|
+
- `inherited` - `true by DEFAULT` - `boolean` - defines if role should be down inherited or not
|
|
50
|
+
- `inherited_role_id` - `(SELF) as DEFAULT` - `number` - id of role which should be inherited to lower resources (ROLE HAS TO EXIST), eg.
|
|
51
|
+
- Role `manager` has `inherited_role` as `member` and `inherited` flag has been set to `true`.
|
|
52
|
+
- Example `User` has been granted as `manager` to `Project`.
|
|
53
|
+
- In all resources bellow `Project`, the user will have a `member` role which was down inherited from `manager`
|
|
54
|
+
|
|
55
|
+
#### Example hash:
|
|
56
|
+
``` ruby
|
|
57
|
+
hash_with_properties = {
|
|
58
|
+
name: :admin,
|
|
59
|
+
level: 5,
|
|
60
|
+
inherited_role_id: 4,
|
|
61
|
+
inherited: true
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
#### Role creating
|
|
66
|
+
```ruby
|
|
67
|
+
Monarchy.role_class.create(hash_with_properties)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Setup actors
|
|
71
|
+
|
|
72
|
+
### Mark user as actor
|
|
73
|
+
Setup your resources by adding `acts_as_resource` (for docs look to `Resource` page).
|
|
74
|
+
|
|
75
|
+
For your current `User` model or freshly generated one, add or check if exist, `acts_as_user`.
|
|
76
|
+
``` ruby
|
|
77
|
+
class User < ActiveRecord::Base
|
|
78
|
+
acts_as_user
|
|
79
|
+
end
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
> Check documentation of [Acts as user] (https://github.com/Exelord/Monarchy/wiki/Acts-as-user)
|
|
83
|
+
|
|
84
|
+
### Mark resources as actors
|
|
85
|
+
For all models that you want to be accessible for users and controlled by `Monarchy` add `acts_as_resource`.
|
|
86
|
+
|
|
87
|
+
> Check documentation of [Acts as resource] (https://github.com/Exelord/Monarchy/wiki/Acts-as-resource)
|
|
88
|
+
|
|
89
|
+
## Build a tree!
|
|
90
|
+
Build Hierarchies and a tree with just one command in `rails console`
|
|
91
|
+
|
|
92
|
+
``` ruby
|
|
93
|
+
Monarchy.rebuild!
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
That's it...
|
|
97
|
+
> Have a long monarchy! :)
|
data/dummy/config/application.rb
CHANGED
|
@@ -18,8 +18,5 @@ module Dummy
|
|
|
18
18
|
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
|
19
19
|
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
|
20
20
|
# config.i18n.default_locale = :de
|
|
21
|
-
|
|
22
|
-
# Do not swallow errors in after_commit/after_rollback callbacks.
|
|
23
|
-
config.active_record.raise_in_transactional_callbacks = true
|
|
24
21
|
end
|
|
25
22
|
end
|
|
@@ -23,7 +23,7 @@ Rails.application.configure do
|
|
|
23
23
|
|
|
24
24
|
# Disable serving static files from the `/public` folder by default since
|
|
25
25
|
# Apache or NGINX already handles this.
|
|
26
|
-
config.
|
|
26
|
+
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
|
|
27
27
|
|
|
28
28
|
# Compress JavaScripts and CSS.
|
|
29
29
|
config.assets.js_compressor = :uglifier
|
|
@@ -14,8 +14,8 @@ Rails.application.configure do
|
|
|
14
14
|
config.eager_load = false
|
|
15
15
|
|
|
16
16
|
# Configure static file server for tests with Cache-Control for performance.
|
|
17
|
-
config.
|
|
18
|
-
config.
|
|
17
|
+
config.public_file_server.enabled = true
|
|
18
|
+
config.public_file_server.headers = { 'Cache-Control' => 'public, max-age=3600' }
|
|
19
19
|
|
|
20
20
|
# Show full error reports and disable caching.
|
|
21
21
|
config.consider_all_requests_local = true
|
|
@@ -31,35 +31,43 @@ module Monarchy
|
|
|
31
31
|
|
|
32
32
|
scope :accessible_for, (lambda do |user|
|
|
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
36
|
end)
|
|
36
37
|
end
|
|
37
38
|
|
|
38
|
-
def
|
|
39
|
-
unscoped.joins('INNER JOIN
|
|
40
|
-
'
|
|
41
|
-
.joins('INNER JOIN
|
|
42
|
-
|
|
43
|
-
.
|
|
39
|
+
def accessible_roots_ids(user_id)
|
|
40
|
+
unscoped.joins('INNER JOIN monarchy_hierarchy_hierarchies ON ' \
|
|
41
|
+
'monarchy_hierarchies.id = monarchy_hierarchy_hierarchies.ancestor_id')
|
|
42
|
+
.joins('INNER JOIN (SELECT hierarchy_id FROM monarchy_members ' \
|
|
43
|
+
"WHERE monarchy_members.user_id = #{user_id}) as members ON " \
|
|
44
|
+
'members.hierarchy_id = monarchy_hierarchy_hierarchies.descendant_id').select(:id)
|
|
44
45
|
end
|
|
45
46
|
|
|
46
|
-
def
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
descendant_leaves
|
|
51
|
-
.where('monarchy_hierarchy_hierarchies.ancestor_id': descendant_leaves_for_user(user)
|
|
52
|
-
.where.not('monarchy_roles.inherited': false))
|
|
53
|
-
)
|
|
47
|
+
def accessible_leaves_ids(user_id)
|
|
48
|
+
ancestor_leaves_for_user(user_id)
|
|
49
|
+
.select('monarchy_hierarchy_hierarchies.ancestor_id AS id')
|
|
50
|
+
.union_all(descendant_leaves_for_user(user_id)).select(:id)
|
|
54
51
|
end
|
|
55
52
|
|
|
56
|
-
def
|
|
57
|
-
|
|
53
|
+
def ancestor_leaves_for_user(user_id, inherited = false)
|
|
54
|
+
inherited = inherited ? 't' : 'f'
|
|
55
|
+
|
|
56
|
+
unscoped
|
|
57
|
+
.joins('INNER JOIN monarchy_hierarchy_hierarchies ON ' \
|
|
58
|
+
'monarchy_hierarchies.id = monarchy_hierarchy_hierarchies.descendant_id')
|
|
59
|
+
.joins('INNER JOIN (SELECT id, hierarchy_id FROM monarchy_members WHERE ' \
|
|
60
|
+
"user_id = #{user_id}) as monarchy_members ON monarchy_members.hierarchy_id = monarchy_hierarchies.id")
|
|
61
|
+
.joins('INNER JOIN monarchy_members_roles ON monarchy_members_roles.member_id = monarchy_members.id')
|
|
62
|
+
.joins("INNER JOIN (SELECT id, inherited FROM monarchy_roles WHERE inherited = '#{inherited}') as " \
|
|
63
|
+
'monarchy_roles ON monarchy_members_roles.role_id = monarchy_roles.id')
|
|
58
64
|
end
|
|
59
65
|
|
|
60
|
-
def
|
|
61
|
-
|
|
62
|
-
'
|
|
66
|
+
def descendant_leaves_for_user(user_id)
|
|
67
|
+
ancestor_leaves_for_user(user_id, true)
|
|
68
|
+
.joins('INNER JOIN monarchy_hierarchy_hierarchies AS monarchy_descendants ON ' \
|
|
69
|
+
'monarchy_descendants.ancestor_id = monarchy_hierarchies.id')
|
|
70
|
+
.select('monarchy_descendants.descendant_id AS id')
|
|
63
71
|
end
|
|
64
72
|
end
|
|
65
73
|
end
|
|
@@ -63,17 +63,24 @@ module Monarchy
|
|
|
63
63
|
|
|
64
64
|
def resource_and_inheritance_roles(resource)
|
|
65
65
|
hierarchy_ids = resource.hierarchy.ancestors.select(:id)
|
|
66
|
+
|
|
66
67
|
Monarchy.role_class.where(id:
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
68
|
+
Monarchy.role_class
|
|
69
|
+
.joins('INNER JOIN monarchy_members_roles ON monarchy_roles.id = monarchy_members_roles.role_id')
|
|
70
|
+
.joins("INNER JOIN (SELECT id, hierarchy_id FROM monarchy_members WHERE user_id = #{id}) as " \
|
|
71
|
+
'monarchy_members ON monarchy_members.id = monarchy_members_roles.member_id')
|
|
72
|
+
.where('monarchy_roles.inherited': 't')
|
|
73
|
+
.where('monarchy_members.hierarchy_id': hierarchy_ids)
|
|
74
|
+
.select('monarchy_roles.inherited_role_id'))
|
|
70
75
|
.union(resource_roles(resource))
|
|
71
|
-
.distinct
|
|
72
76
|
end
|
|
73
77
|
|
|
74
78
|
def resource_roles(resource)
|
|
75
|
-
Monarchy.role_class
|
|
76
|
-
.
|
|
79
|
+
Monarchy.role_class
|
|
80
|
+
.joins('INNER JOIN monarchy_members_roles ON monarchy_roles.id = monarchy_members_roles.role_id')
|
|
81
|
+
.joins('INNER JOIN (SELECT id, hierarchy_id FROM monarchy_members WHERE ' \
|
|
82
|
+
"hierarchy_id = #{resource.hierarchy.id} AND user_id = #{id}) as monarchy_members ON " \
|
|
83
|
+
'monarchy_members.id = monarchy_members_roles.member_id')
|
|
77
84
|
end
|
|
78
85
|
|
|
79
86
|
def descendant_role(resource)
|
data/lib/monarchy/version.rb
CHANGED
data/monarchy.gemspec
CHANGED
|
@@ -24,8 +24,9 @@ Gem::Specification.new do |s|
|
|
|
24
24
|
s.bindir = 'exe'
|
|
25
25
|
s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
26
26
|
s.require_paths = ['lib']
|
|
27
|
+
s.required_ruby_version = '>= 2.3'
|
|
27
28
|
|
|
28
|
-
s.
|
|
29
|
+
s.add_dependency 'activerecord', '>=4.2.7.1'
|
|
29
30
|
s.add_dependency 'closure_tree', '6.2.0'
|
|
30
31
|
s.add_dependency 'configurations', '2.2.1'
|
|
31
32
|
s.add_dependency 'active_record_union', '1.2.0'
|
metadata
CHANGED
|
@@ -1,22 +1,19 @@
|
|
|
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.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Exelord
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-
|
|
11
|
+
date: 2016-11-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
14
|
+
name: activerecord
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - "~>"
|
|
18
|
-
- !ruby/object:Gem::Version
|
|
19
|
-
version: '4.2'
|
|
20
17
|
- - ">="
|
|
21
18
|
- !ruby/object:Gem::Version
|
|
22
19
|
version: 4.2.7.1
|
|
@@ -24,9 +21,6 @@ dependencies:
|
|
|
24
21
|
prerelease: false
|
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
26
23
|
requirements:
|
|
27
|
-
- - "~>"
|
|
28
|
-
- !ruby/object:Gem::Version
|
|
29
|
-
version: '4.2'
|
|
30
24
|
- - ">="
|
|
31
25
|
- !ruby/object:Gem::Version
|
|
32
26
|
version: 4.2.7.1
|
|
@@ -136,6 +130,7 @@ extensions: []
|
|
|
136
130
|
extra_rdoc_files: []
|
|
137
131
|
files:
|
|
138
132
|
- ".codeclimate.yml"
|
|
133
|
+
- ".github_changelog_generator"
|
|
139
134
|
- ".gitignore"
|
|
140
135
|
- ".rspec"
|
|
141
136
|
- ".rubocop.yml"
|
|
@@ -155,11 +150,12 @@ files:
|
|
|
155
150
|
- bin/console
|
|
156
151
|
- bin/setup
|
|
157
152
|
- docs/acts_as_hierarchy.md
|
|
153
|
+
- docs/acts_as_member.md
|
|
158
154
|
- docs/acts_as_resource.md
|
|
155
|
+
- docs/acts_as_role.md
|
|
159
156
|
- docs/acts_as_user.md
|
|
160
157
|
- docs/configuration.md
|
|
161
|
-
- docs/
|
|
162
|
-
- docs/usage.md
|
|
158
|
+
- docs/installation_and_usage.md
|
|
163
159
|
- dummy/.rspec
|
|
164
160
|
- dummy/README.rdoc
|
|
165
161
|
- dummy/Rakefile
|
|
@@ -255,15 +251,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
255
251
|
requirements:
|
|
256
252
|
- - ">="
|
|
257
253
|
- !ruby/object:Gem::Version
|
|
258
|
-
version: '
|
|
254
|
+
version: '2.3'
|
|
259
255
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
260
256
|
requirements:
|
|
261
|
-
- - "
|
|
257
|
+
- - ">="
|
|
262
258
|
- !ruby/object:Gem::Version
|
|
263
|
-
version:
|
|
259
|
+
version: '0'
|
|
264
260
|
requirements: []
|
|
265
261
|
rubyforge_project:
|
|
266
|
-
rubygems_version: 2.6.
|
|
262
|
+
rubygems_version: 2.6.8
|
|
267
263
|
signing_key:
|
|
268
264
|
specification_version: 4
|
|
269
265
|
summary: Hierarchical access management system with roles inheritance.
|
data/docs/installation.md
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# Installation
|
|
2
|
-
Add this line to your application's Gemfile:
|
|
3
|
-
|
|
4
|
-
```ruby
|
|
5
|
-
gem 'monarchy'
|
|
6
|
-
```
|
|
7
|
-
|
|
8
|
-
And then execute:
|
|
9
|
-
|
|
10
|
-
$ bundle
|
|
11
|
-
|
|
12
|
-
To create initials migrations and necessary files run:
|
|
13
|
-
```
|
|
14
|
-
rails g monarchy:setup
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
This will create for you:
|
|
18
|
-
|
|
19
|
-
1. Migrations:
|
|
20
|
-
- `monarchy_create_users`
|
|
21
|
-
- `monarchy_create_hierarchies`
|
|
22
|
-
- `monarchy_create_memberships`
|
|
23
|
-
2. Configuration file in `config/initializers/monarchy`
|
|
24
|
-
3. Default `User` model (optional)
|
|
25
|
-
|
|
26
|
-
**If you want to use your current `User` model just skip generation of: **
|
|
27
|
-
- `db/migrate/monarchy_create_users.rb`
|
|
28
|
-
- `app/models/user.rb`
|
|
29
|
-
|
|
30
|
-
And add to your current `User` model `acts_as_user`
|
data/docs/usage.md
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# Usage
|
|
2
|
-
The only think you have to do is mark models to be one of part of Monarchy.
|
|
3
|
-
|
|
4
|
-
You can use 2 available markers:
|
|
5
|
-
|
|
6
|
-
1. `acts_as_user`
|
|
7
|
-
2. `acts_as_resource`
|
|
8
|
-
|
|
9
|
-
## Acts as user
|
|
10
|
-
For your current `User` model or freshly generated one, add or check if exist, `acts_as_user`.
|
|
11
|
-
``` ruby
|
|
12
|
-
class User < ActiveRecord::Base
|
|
13
|
-
acts_as_user
|
|
14
|
-
end
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
> Check documentation of [Acts as user] (https://github.com/Exelord/Monarchy/wiki/Acts-as-user)
|
|
18
|
-
|
|
19
|
-
## Acts as resource
|
|
20
|
-
For all models that you want to be accessible for users add `acts_as_resource`.
|
|
21
|
-
|
|
22
|
-
> Check documentation of [Acts as resource] (https://github.com/Exelord/Monarchy/wiki/Acts-as-resource)
|