monarchy 2.2.0 → 2.2.1
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 +25 -7
- data/Gemfile.lock +1 -1
- data/lib/monarchy/acts_as_user.rb +39 -9
- data/lib/monarchy/version.rb +1 -1
- 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: c15282927b5b58ca3da1c4102405a299faa6e6a9
|
4
|
+
data.tar.gz: 0ad457f343ef448dbede073ade8fe820011b13dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79f77cba2b572d85260f640727bdca9dc6f3b53d80e72e5cab50e2f48f5584a19ed03d31d0d1e2128e0c3b66ea366e0a923c8541f606bb13e3e616ba22c571e7
|
7
|
+
data.tar.gz: ea747c578065b293e644d3b4ef982a9b6b62c21e50636895a39ed5898779ef217d0fbf1e72205fe3bf9fb5a464744b89bd02b49c943effa164e3cd13d90d1898
|
data/.github_changelog_generator
CHANGED
@@ -1 +1 @@
|
|
1
|
-
future-release=2.1
|
1
|
+
future-release=2.2.1
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,30 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## [2.1
|
4
|
-
[Full Changelog](https://github.com/Exelord/Monarchy/compare/v2.0
|
3
|
+
## [2.2.1](https://github.com/Exelord/Monarchy/tree/2.2.1) (2017-05-29)
|
4
|
+
[Full Changelog](https://github.com/Exelord/Monarchy/compare/v2.2.0...2.2.1)
|
5
|
+
|
6
|
+
**Merged pull requests:**
|
7
|
+
|
8
|
+
- Fix potential n-query [\#74](https://github.com/Exelord/Monarchy/pull/74) ([Exelord](https://github.com/Exelord))
|
9
|
+
|
10
|
+
## [v2.2.0](https://github.com/Exelord/Monarchy/tree/v2.2.0) (2017-04-14)
|
11
|
+
[Full Changelog](https://github.com/Exelord/Monarchy/compare/v2.1.0...v2.2.0)
|
12
|
+
|
13
|
+
**Merged pull requests:**
|
14
|
+
|
15
|
+
- Feature model accessible for [\#72](https://github.com/Exelord/Monarchy/pull/72) ([Exelord](https://github.com/Exelord))
|
16
|
+
- Update gems [\#71](https://github.com/Exelord/Monarchy/pull/71) ([Exelord](https://github.com/Exelord))
|
17
|
+
|
18
|
+
## [v2.1.0](https://github.com/Exelord/Monarchy/tree/v2.1.0) (2017-03-30)
|
19
|
+
[Full Changelog](https://github.com/Exelord/Monarchy/compare/v2.0.8...v2.1.0)
|
20
|
+
|
21
|
+
**Fixed bugs:**
|
22
|
+
|
23
|
+
- Fix roles order [\#63](https://github.com/Exelord/Monarchy/pull/63) ([Exelord](https://github.com/Exelord))
|
24
|
+
|
25
|
+
**Closed issues:**
|
26
|
+
|
27
|
+
- Improve performance [\#59](https://github.com/Exelord/Monarchy/issues/59)
|
5
28
|
|
6
29
|
**Merged pull requests:**
|
7
30
|
|
@@ -27,10 +50,6 @@
|
|
27
50
|
## [v2.0.6](https://github.com/Exelord/Monarchy/tree/v2.0.6) (2016-11-29)
|
28
51
|
[Full Changelog](https://github.com/Exelord/Monarchy/compare/v2.0.5...v2.0.6)
|
29
52
|
|
30
|
-
**Fixed bugs:**
|
31
|
-
|
32
|
-
- Fix roles order [\#63](https://github.com/Exelord/Monarchy/pull/63) ([Exelord](https://github.com/Exelord))
|
33
|
-
|
34
53
|
## [v2.0.5](https://github.com/Exelord/Monarchy/tree/v2.0.5) (2016-11-10)
|
35
54
|
[Full Changelog](https://github.com/Exelord/Monarchy/compare/v2.0.4...v2.0.5)
|
36
55
|
|
@@ -44,7 +63,6 @@
|
|
44
63
|
|
45
64
|
**Closed issues:**
|
46
65
|
|
47
|
-
- Improve performance [\#59](https://github.com/Exelord/Monarchy/issues/59)
|
48
66
|
- Default role - is it still needed? [\#48](https://github.com/Exelord/Monarchy/issues/48)
|
49
67
|
- Complete Readme and WIKI [\#5](https://github.com/Exelord/Monarchy/issues/5)
|
50
68
|
|
data/Gemfile.lock
CHANGED
@@ -63,7 +63,8 @@ module Monarchy
|
|
63
63
|
private
|
64
64
|
|
65
65
|
def accessible_roles_for(resource, inheritnce)
|
66
|
-
return Monarchy.role_class.none unless resource.
|
66
|
+
return Monarchy.role_class.none unless resource.persisted?
|
67
|
+
|
67
68
|
accessible_roles = if inheritnce
|
68
69
|
resource_and_inheritance_roles(resource)
|
69
70
|
else
|
@@ -75,29 +76,32 @@ module Monarchy
|
|
75
76
|
end
|
76
77
|
|
77
78
|
def resource_and_inheritance_roles(resource)
|
78
|
-
hierarchy_ids = resource.hierarchy.ancestors.select(:id)
|
79
|
-
|
80
79
|
Monarchy.role_class.where(id:
|
81
80
|
Monarchy.role_class
|
82
81
|
.joins('INNER JOIN monarchy_members_roles ON monarchy_roles.id = monarchy_members_roles.role_id')
|
83
82
|
.joins("INNER JOIN (SELECT id, hierarchy_id FROM monarchy_members WHERE user_id = #{id}) as " \
|
84
83
|
'monarchy_members ON monarchy_members.id = monarchy_members_roles.member_id')
|
85
84
|
.where('monarchy_roles.inherited': 't')
|
86
|
-
.where('monarchy_members.hierarchy_id':
|
85
|
+
.where('monarchy_members.hierarchy_id': ancestors_for(resource).select(:id))
|
87
86
|
.select('monarchy_roles.inherited_role_id'))
|
88
87
|
.union(resource_roles(resource))
|
89
88
|
end
|
90
89
|
|
91
90
|
def resource_roles(resource)
|
91
|
+
resource_hierarchy = hierarchies_for(resource).select(:id)
|
92
|
+
|
93
|
+
user_memberships = Monarchy.member_class
|
94
|
+
.where(hierarchy_id: resource_hierarchy, user_id: id)
|
95
|
+
.select(:id, :hierarchy_id).to_sql
|
96
|
+
|
92
97
|
Monarchy.role_class
|
93
98
|
.joins('INNER JOIN monarchy_members_roles ON monarchy_roles.id = monarchy_members_roles.role_id')
|
94
|
-
.joins(
|
95
|
-
"hierarchy_id = #{resource.hierarchy.id} AND user_id = #{id}) as monarchy_members ON " \
|
99
|
+
.joins("INNER JOIN (#{user_memberships}) as monarchy_members ON " \
|
96
100
|
'monarchy_members.id = monarchy_members_roles.member_id')
|
97
101
|
end
|
98
102
|
|
99
103
|
def descendant_role(resource)
|
100
|
-
descendants = resource
|
104
|
+
descendants = descendants_for(resource)
|
101
105
|
children_access = members_for(descendants).present?
|
102
106
|
|
103
107
|
if children_access
|
@@ -148,12 +152,38 @@ module Monarchy
|
|
148
152
|
member
|
149
153
|
end
|
150
154
|
|
155
|
+
def inherited_default_role
|
156
|
+
@inherited_default_role ||= Monarchy.role_class.find_by(name: Monarchy.configuration.inherited_default_role)
|
157
|
+
end
|
158
|
+
|
159
|
+
# TODO: Make these methods public in related interfaces
|
160
|
+
|
151
161
|
def members_for(hierarchies)
|
152
162
|
Monarchy.member_class.where(hierarchy: hierarchies, user_id: id)
|
153
163
|
end
|
154
164
|
|
155
|
-
def
|
156
|
-
|
165
|
+
def hierarchies_for(resources)
|
166
|
+
Monarchy.hierarchy_class.where(resource: resources)
|
167
|
+
end
|
168
|
+
|
169
|
+
def descendants_for(resources)
|
170
|
+
resources_hierarchies = hierarchies_for(resources).select(:id)
|
171
|
+
|
172
|
+
Monarchy.hierarchy_class
|
173
|
+
.joins('INNER JOIN monarchy_hierarchy_hierarchies ON ' \
|
174
|
+
'monarchy_hierarchies.id = monarchy_hierarchy_hierarchies.descendant_id')
|
175
|
+
.where(monarchy_hierarchy_hierarchies: { ancestor_id: resources_hierarchies })
|
176
|
+
.where.not(monarchy_hierarchies: { id: resources_hierarchies })
|
177
|
+
end
|
178
|
+
|
179
|
+
def ancestors_for(resources)
|
180
|
+
resources_hierarchies = hierarchies_for(resources).select(:id)
|
181
|
+
|
182
|
+
Monarchy.hierarchy_class
|
183
|
+
.joins('INNER JOIN monarchy_hierarchy_hierarchies ON ' \
|
184
|
+
'monarchy_hierarchies.id = monarchy_hierarchy_hierarchies.ancestor_id')
|
185
|
+
.where(monarchy_hierarchy_hierarchies: { descendant_id: resources_hierarchies })
|
186
|
+
.where.not(monarchy_hierarchies: { id: resources_hierarchies })
|
157
187
|
end
|
158
188
|
end
|
159
189
|
end
|
data/lib/monarchy/version.rb
CHANGED
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.2.
|
4
|
+
version: 2.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Exelord
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|