rhino_project_core 0.21.0.beta.47 → 0.21.0.beta.52
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/helpers/rhino/omniauth_helper.rb +2 -1
- data/lib/rhino/resource/active_record_extension/params.rb +8 -3
- data/lib/rhino/resource/active_record_extension/properties_describe.rb +22 -8
- data/lib/rhino/resource/active_record_tree.rb +1 -1
- data/lib/rhino/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1b7f68ae4e2c0c7329a629b27b7066d998be5d3644da8c19dafb35b582bc6de
|
4
|
+
data.tar.gz: dd08f384dee74cfea82940c8871771ffc670dacc7bdb30ebe39943117a778933
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 698a1c7aceb4e0cb879467ef14d9097db425bd67de34bba52cb74e1f6c57fe5415a13611ef33e94e989b3c2c53d81e7c5315ebfe52837c9218d31e8635135661
|
7
|
+
data.tar.gz: 9fd1a98e8584be9cc5f3a90b967b143b6f542a5579c40a5015b9fd01725ec501ea338d112be44930348f8841c2a2cf7a437cca7a88f468b746d398743cf5b6d4
|
@@ -50,7 +50,8 @@ module Rhino
|
|
50
50
|
[
|
51
51
|
client_id: ENV["AUTH_AZURE_OAUTH2_CLIENT_ID"],
|
52
52
|
client_secret: ENV["AUTH_AZURE_OAUTH2_SECRET_KEY"],
|
53
|
-
|
53
|
+
# common is the default for multi-tenant applications
|
54
|
+
tenant_id: ENV.fetch("AUTH_AZURE_OAUTH2_TENANT_ID", "common"),
|
54
55
|
]
|
55
56
|
end
|
56
57
|
|
@@ -154,7 +154,7 @@ module Rhino
|
|
154
154
|
# rubocop:todo Metrics/CyclomaticComplexity
|
155
155
|
def transform_params_recursive(params, parent = self) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/PerceivedComplexity
|
156
156
|
hash = {}
|
157
|
-
params.each do |param_key, param_value|
|
157
|
+
params.each do |param_key, param_value| # rubocop:todo Metrics/BlockLength
|
158
158
|
association = parent.reflect_on_association(param_key)
|
159
159
|
|
160
160
|
# Its a regular attribute
|
@@ -187,19 +187,24 @@ module Rhino
|
|
187
187
|
# if its a cardinal though, such as blog: 1 instead of blog: {name : 'my blog' }
|
188
188
|
# fallback to transforming to the foreign key
|
189
189
|
if param_value.is_a?(ActionController::Parameters)
|
190
|
+
assoc = parent.reflections[param_key]
|
190
191
|
klasses = assoc_from_sym(param_key, parent)
|
191
192
|
|
193
|
+
# We only want to transform the params for the klass that matches the foreign_type
|
194
|
+
klasses.select! { |k| k.name == params[assoc.foreign_type] } if assoc.polymorphic?
|
195
|
+
|
192
196
|
next hash[attr_key] = klasses.map { |klass| parent.transform_params_recursive(param_value, klass) }.reduce(:merge)
|
193
197
|
end
|
194
198
|
end
|
195
199
|
|
196
200
|
# Map association name to foreign key, ie blog => blog_id
|
197
201
|
# or blog: { id: } => blog_id
|
198
|
-
if param_value.is_a?(ActionController::Parameters)
|
202
|
+
if param_value.is_a?(ActionController::Parameters) && !association.has_one?
|
199
203
|
next hash[association.foreign_key] = param_value[association.klass.identifier_property]
|
200
204
|
end
|
201
205
|
|
202
|
-
|
206
|
+
# If its a has_one, there is no foreign key on this model
|
207
|
+
hash[association.foreign_key] = param_value unless association.has_one?
|
203
208
|
end
|
204
209
|
|
205
210
|
# Force permit since we should have already been permitted at this point
|
@@ -8,6 +8,20 @@ module Rhino
|
|
8
8
|
module PropertiesDescribe # rubocop:disable Metrics/ModuleLength
|
9
9
|
extend ActiveSupport::Concern
|
10
10
|
|
11
|
+
class PolymorphicModelName
|
12
|
+
include ActiveSupport::Inflector
|
13
|
+
|
14
|
+
attr_reader :name
|
15
|
+
|
16
|
+
def initialize(name)
|
17
|
+
@name = name.to_s
|
18
|
+
end
|
19
|
+
|
20
|
+
def singular
|
21
|
+
underscore(name).tr("/", "_").singularize
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
11
25
|
class_methods do # rubocop:disable Metrics/BlockLength
|
12
26
|
def describe_property(property) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
13
27
|
name = property_name(property).to_s
|
@@ -43,7 +57,7 @@ module Rhino
|
|
43
57
|
def ref_descriptor(names)
|
44
58
|
{
|
45
59
|
type: :reference,
|
46
|
-
anyOf: names.map { |name| { :$ref => "#/components/schemas/#{name.
|
60
|
+
anyOf: names.map { |name| { :$ref => "#/components/schemas/#{name.singular}" } }
|
47
61
|
}
|
48
62
|
end
|
49
63
|
|
@@ -86,19 +100,19 @@ module Rhino
|
|
86
100
|
|
87
101
|
# rubocop:todo Metrics/PerceivedComplexity
|
88
102
|
# rubocop:todo Metrics/AbcSize
|
89
|
-
def property_type_and_format_ref(name) # rubocop:todo Metrics/
|
103
|
+
def property_type_and_format_ref(name) # rubocop:todo Metrics/AbcSize
|
90
104
|
assoc = reflections[name]
|
91
|
-
klasses = if assoc.
|
92
|
-
#
|
105
|
+
klasses = if assoc.polymorphic?
|
106
|
+
# Delegated type
|
93
107
|
if assoc.active_record.respond_to?("#{assoc.name}_types")
|
94
|
-
assoc.active_record.send("#{assoc.name}_types").map
|
108
|
+
assoc.active_record.send(:"#{assoc.name}_types").map { |x| x.constantize.model_name }
|
95
109
|
else
|
96
110
|
# FIXME: This is wrong, but there is no good way to introspect general polymorphic models
|
97
|
-
|
111
|
+
# FIXME: This should be an OpenAPI discriminator with all possible types (all models)
|
112
|
+
[PolymorphicModelName.new(name)]
|
98
113
|
end
|
99
114
|
else
|
100
|
-
|
101
|
-
[assoc.options[:class_name]&.underscore&.tr("/", "_") || name]
|
115
|
+
[assoc.klass.model_name]
|
102
116
|
end
|
103
117
|
|
104
118
|
return ref_descriptor(klasses) unless reflections[name].macro == :has_many
|
@@ -20,7 +20,7 @@ module Rhino
|
|
20
20
|
def describe_property(property)
|
21
21
|
return super unless property == "children"
|
22
22
|
|
23
|
-
super.deep_merge({ type: :array, items: ref_descriptor([model_name
|
23
|
+
super.deep_merge({ type: :array, items: ref_descriptor([model_name]) })
|
24
24
|
end
|
25
25
|
|
26
26
|
# FIXME: Need to recurse to a MAX DEPTH
|
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.52
|
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-
|
11
|
+
date: 2024-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|