rhino_project_core 0.21.0.beta.44 → 0.21.0.beta.46
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/resources/rhino/info_graph.rb +1 -1
- data/lib/rhino/resource/active_record_extension/owner.rb +45 -0
- data/lib/rhino/resource/active_record_extension.rb +2 -0
- data/lib/rhino/resource/owner.rb +26 -27
- data/lib/rhino/resource.rb +15 -11
- data/lib/rhino/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5523b3587da0f1a5099bb649e0f1243a716a85b27379372ab513c9beb759f3fa
|
4
|
+
data.tar.gz: be28497ecfe5fec48183bdddab3b5a13f4e4c0d4a3fa0e2c01bc9153509bf31e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f5728dd8cc8a7cd570b01af965bd87365f216910ac66011b40023d1e8a632be9edf4275de5b66ed1d89ea054c741e6ea55b0393fd1f848c3ee2d8fa5933009f3
|
7
|
+
data.tar.gz: 5a10bba5d890d5f71d8930b34e65de0094130c7b477ffcfc5121877e432103107e45fbf2b360cd4b11bfb1e3741cebe78962b902a7edb47d4ebc554f6890d0cb
|
@@ -26,7 +26,7 @@ module Rhino
|
|
26
26
|
g.vertex_iterator { |c| Rhino.resource_classes.each(&c) }
|
27
27
|
|
28
28
|
# If its owned by another resoource, link it
|
29
|
-
g.adjacent_iterator { |v, c| c.call(v.
|
29
|
+
g.adjacent_iterator { |v, c| c.call(v.owner_class) if v&.resource_owned_by && !v.global_owner? }
|
30
30
|
|
31
31
|
g.directed = true
|
32
32
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Rhino
|
4
|
+
module Resource
|
5
|
+
module ActiveRecordExtension
|
6
|
+
module Owner
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
# The self is actually required to work with class_attribute properly
|
10
|
+
class_methods do
|
11
|
+
def owner_class
|
12
|
+
reflect_on_association(resource_owned_by).klass
|
13
|
+
end
|
14
|
+
|
15
|
+
# Test if rhino_owner[rdoc-ref:rhino_owner] is the global owner
|
16
|
+
# Also available on the instance
|
17
|
+
def global_owned?
|
18
|
+
chained_scope = self
|
19
|
+
while !chained_scope.auth_owner? && !chained_scope.base_owner? && !chained_scope.global_owner?
|
20
|
+
chained_scope = chained_scope.owner_class
|
21
|
+
end
|
22
|
+
|
23
|
+
chained_scope.global_owner?
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
def simple_joins_for(parent)
|
28
|
+
# FIXME: There is probably a more rubyish way to do this
|
29
|
+
chained_scope = self
|
30
|
+
joins = []
|
31
|
+
|
32
|
+
# The ownership could be a many, so we classify first
|
33
|
+
while chained_scope.owner_class.name != parent.to_s.classify
|
34
|
+
joins << chained_scope.resource_owned_by
|
35
|
+
chained_scope = chained_scope.owner_class
|
36
|
+
end
|
37
|
+
joins << chained_scope.resource_owned_by
|
38
|
+
|
39
|
+
joins.reverse
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -5,6 +5,7 @@ require_relative 'active_record_extension/properties'
|
|
5
5
|
require_relative 'active_record_extension/reference'
|
6
6
|
require_relative 'active_record_extension/describe'
|
7
7
|
require_relative 'active_record_extension/routing'
|
8
|
+
require_relative 'active_record_extension/owner'
|
8
9
|
require_relative 'active_record_extension/params'
|
9
10
|
require_relative 'active_record_extension/serialization'
|
10
11
|
require_relative 'active_record_extension/search'
|
@@ -23,6 +24,7 @@ module Rhino
|
|
23
24
|
include Rhino::Resource::ActiveRecordExtension::Reference
|
24
25
|
include Rhino::Resource::ActiveRecordExtension::Describe
|
25
26
|
include Rhino::Resource::ActiveRecordExtension::Routing
|
27
|
+
include Rhino::Resource::ActiveRecordExtension::Owner
|
26
28
|
include Rhino::Resource::ActiveRecordExtension::Params
|
27
29
|
include Rhino::Resource::ActiveRecordExtension::Serialization
|
28
30
|
include Rhino::Resource::ActiveRecordExtension::Search
|
data/lib/rhino/resource/owner.rb
CHANGED
@@ -35,13 +35,13 @@ module Rhino
|
|
35
35
|
self == Rhino.base_owner
|
36
36
|
end
|
37
37
|
|
38
|
-
# Test if rhino_owner[rdoc-ref:rhino_owner] is the
|
38
|
+
# Test if rhino_owner[rdoc-ref:rhino_owner] is the global owner
|
39
39
|
# Also available on the instance
|
40
40
|
def global_owner?
|
41
41
|
self.resource_owned_by == :global
|
42
42
|
end
|
43
43
|
|
44
|
-
# Test if rhino_owner[rdoc-ref:rhino_owner] is the
|
44
|
+
# Test if rhino_owner[rdoc-ref:rhino_owner] is globally owned at the top of the hierarchy
|
45
45
|
# Also available on the instance
|
46
46
|
def global_owned?
|
47
47
|
chained_scope = self
|
@@ -89,7 +89,6 @@ module Rhino
|
|
89
89
|
#
|
90
90
|
def rhino_owner(name, **_options)
|
91
91
|
self.resource_owned_by = name
|
92
|
-
rhino_policy :global if global_owned?
|
93
92
|
end
|
94
93
|
|
95
94
|
# Sets rhino_owner[rdoc-ref:rhino_owner] to be the base owner
|
@@ -133,40 +132,40 @@ module Rhino
|
|
133
132
|
end
|
134
133
|
|
135
134
|
private
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
135
|
+
def simple_joins_for(parent)
|
136
|
+
# FIXME: There is probably a more rubyish way to do this
|
137
|
+
chained_scope = self
|
138
|
+
joins = []
|
139
|
+
|
140
|
+
# The ownership could be a many, so we classify first
|
141
|
+
while chained_scope.resource_owned_by.to_s.classify != parent.to_s.classify
|
142
|
+
joins << chained_scope.resource_owned_by
|
143
|
+
chained_scope = chained_scope.resource_owned_by.to_s.classify.constantize
|
144
|
+
end
|
143
145
|
joins << chained_scope.resource_owned_by
|
144
|
-
chained_scope = chained_scope.resource_owned_by.to_s.classify.constantize
|
145
|
-
end
|
146
|
-
joins << chained_scope.resource_owned_by
|
147
146
|
|
148
|
-
|
149
|
-
|
147
|
+
joins.reverse
|
148
|
+
end
|
150
149
|
|
151
|
-
|
152
|
-
|
153
|
-
|
150
|
+
def simple_joins_for_base_owner
|
151
|
+
simple_joins_for(Rhino.base_owner)
|
152
|
+
end
|
154
153
|
end
|
155
154
|
# rubocop:enable Style/RedundantSelf
|
156
155
|
end
|
157
156
|
|
158
157
|
private
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
158
|
+
# We use the parent as the starting point because if the record is not
|
159
|
+
# persisted yet, we won't be able to find it
|
160
|
+
def owner_ids(joins)
|
161
|
+
bo = Rhino.base_owner
|
163
162
|
|
164
|
-
|
163
|
+
return [] unless owner
|
165
164
|
|
166
|
-
|
167
|
-
|
165
|
+
parent_klass = owner.class
|
166
|
+
pk = parent_klass.primary_key
|
168
167
|
|
169
|
-
|
170
|
-
|
168
|
+
parent_klass.joins(parent_klass.send(joins)).where("#{pk}": owner[pk]).pluck("#{bo.table_name}.#{bo.primary_key}")
|
169
|
+
end
|
171
170
|
end
|
172
171
|
end
|
data/lib/rhino/resource.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
4
|
-
require_relative
|
5
|
-
require_relative
|
6
|
-
require_relative
|
7
|
-
require_relative
|
8
|
-
require_relative
|
9
|
-
require_relative
|
10
|
-
require_relative
|
3
|
+
require_relative "resource/owner"
|
4
|
+
require_relative "resource/properties"
|
5
|
+
require_relative "resource/reference"
|
6
|
+
require_relative "resource/describe"
|
7
|
+
require_relative "resource/routing"
|
8
|
+
require_relative "resource/params"
|
9
|
+
require_relative "resource/serialization"
|
10
|
+
require_relative "resource/sieves"
|
11
11
|
|
12
|
-
require_relative
|
12
|
+
require_relative "../../app/policies/rhino/crud_policy"
|
13
13
|
|
14
14
|
module Rhino
|
15
15
|
module Resource
|
@@ -25,7 +25,7 @@ module Rhino
|
|
25
25
|
include Rhino::Resource::Sieves
|
26
26
|
|
27
27
|
included do
|
28
|
-
class_attribute :_policy_class
|
28
|
+
class_attribute :_policy_class
|
29
29
|
|
30
30
|
def owner
|
31
31
|
send self.class.resource_owned_by
|
@@ -41,7 +41,11 @@ module Rhino
|
|
41
41
|
|
42
42
|
class_methods do
|
43
43
|
def policy_class
|
44
|
-
_policy_class
|
44
|
+
self._policy_class ||= begin
|
45
|
+
return Rhino::GlobalPolicy if global_owned?
|
46
|
+
|
47
|
+
Rhino::CrudPolicy
|
48
|
+
end
|
45
49
|
end
|
46
50
|
|
47
51
|
def rhino_policy(policy)
|
data/lib/rhino/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rhino_project_core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.21.0.beta.
|
4
|
+
version: 0.21.0.beta.46
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JP Rosevear
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -465,6 +465,7 @@ files:
|
|
465
465
|
- lib/rhino/resource/active_model_extension/serialization.rb
|
466
466
|
- lib/rhino/resource/active_record_extension.rb
|
467
467
|
- lib/rhino/resource/active_record_extension/describe.rb
|
468
|
+
- lib/rhino/resource/active_record_extension/owner.rb
|
468
469
|
- lib/rhino/resource/active_record_extension/params.rb
|
469
470
|
- lib/rhino/resource/active_record_extension/properties.rb
|
470
471
|
- lib/rhino/resource/active_record_extension/properties_describe.rb
|