forest_admin_datasource_mongoid 1.19.1 → 1.19.3
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/lib/forest_admin_datasource_mongoid/parser/relation.rb +6 -4
- data/lib/forest_admin_datasource_mongoid/parser/validation.rb +23 -21
- data/lib/forest_admin_datasource_mongoid/utils/add_null_values.rb +5 -3
- data/lib/forest_admin_datasource_mongoid/utils/helpers.rb +2 -1
- data/lib/forest_admin_datasource_mongoid/utils/pipeline/filter_generator.rb +1 -1
- data/lib/forest_admin_datasource_mongoid/utils/pipeline/lookup_generator.rb +13 -11
- data/lib/forest_admin_datasource_mongoid/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: b27ac1b878a98f85863c4f7ada5ce6cf2622f15c326487509c3d73d4a6964d35
|
|
4
|
+
data.tar.gz: 1246128bdb1f69f137c978402b0268530593a7369e40b24507d1270ead86cebe
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6e3e496fb16697f1513b1f0c5241cfc97c6110621bbced44f852ef6ecca207641affcf856768417d27f79f0480c06d9579b97bbee2086bdf253ceacaa7eeb98f
|
|
7
|
+
data.tar.gz: c4389a71350ac95b3015b2cee66581d0039e0e4ad132f01f543525915dadbcbb7940520f6f62ff823fa0fe5323b7e612e9ad9e25b341fa2d25c500733781556e
|
|
@@ -4,10 +4,12 @@ module ForestAdminDatasourceMongoid
|
|
|
4
4
|
def get_polymorphic_types(relation_name)
|
|
5
5
|
types = {}
|
|
6
6
|
|
|
7
|
-
ObjectSpace.each_object(Class).
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
ObjectSpace.each_object(Class).each do |klass|
|
|
8
|
+
next unless klass < Mongoid::Document
|
|
9
|
+
|
|
10
|
+
if klass.relations.any? { |_, relation| relation.options[:as] == relation_name.to_sym }
|
|
11
|
+
primary_key = klass.fields.keys.find { |key| klass.fields[key].options[:as] == :id } || :_id
|
|
12
|
+
types[klass.name.gsub('::', '__')] = primary_key.to_s
|
|
11
13
|
end
|
|
12
14
|
end
|
|
13
15
|
|
|
@@ -4,33 +4,35 @@ module ForestAdminDatasourceMongoid
|
|
|
4
4
|
include ForestAdminDatasourceToolkit::Components::Query::ConditionTree
|
|
5
5
|
def get_validations(model, column)
|
|
6
6
|
return [] if column.is_a?(Hash)
|
|
7
|
+
return [] if before_validation_callback?(model)
|
|
8
|
+
return [] unless model._validators? && model._validators[column.name.to_sym].size.positive?
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
parse_column_validators(model._validators[column.name.to_sym], column)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def before_validation_callback?(model)
|
|
11
14
|
default_callback_excluded = [:normalize_changed_in_place_attributes]
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
model._validation_callbacks.any? do |callback|
|
|
16
|
+
!default_callback_excluded.include?(callback.filter) && callback.kind == :before
|
|
17
|
+
end
|
|
18
|
+
end
|
|
15
19
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
+
def parse_column_validators(validators, column)
|
|
21
|
+
validations = []
|
|
22
|
+
validators.each do |validator|
|
|
23
|
+
next if validator.options[:if] || validator.options[:unless] || validator.options[:on]
|
|
20
24
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
end
|
|
25
|
+
case validator.class.to_s
|
|
26
|
+
when Mongoid::Validatable::PresenceValidator.to_s
|
|
27
|
+
validations << { operator: Operators::PRESENT }
|
|
28
|
+
when ActiveModel::Validations::NumericalityValidator.to_s
|
|
29
|
+
validations = parse_numericality_validator(validator, validations)
|
|
30
|
+
when Mongoid::Validatable::LengthValidator.to_s
|
|
31
|
+
validations = parse_length_validator(validator, validations, column)
|
|
32
|
+
when Mongoid::Validatable::FormatValidator.to_s
|
|
33
|
+
validations = parse_format_validator(validator, validations)
|
|
31
34
|
end
|
|
32
35
|
end
|
|
33
|
-
|
|
34
36
|
validations
|
|
35
37
|
end
|
|
36
38
|
|
|
@@ -28,11 +28,13 @@ module ForestAdminDatasourceMongoid
|
|
|
28
28
|
result[field_prefix] ||= nil
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
-
nested_prefixes = projection.
|
|
31
|
+
nested_prefixes = projection.filter_map { |field| field.split(':').first if field.include?(':') }.uniq
|
|
32
32
|
|
|
33
33
|
nested_prefixes.each do |nested_prefix|
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
prefix_with_colon = "#{nested_prefix}:"
|
|
35
|
+
child_paths = projection.filter_map do |field|
|
|
36
|
+
field[(nested_prefix.size + 1)..] if field.start_with?(prefix_with_colon)
|
|
37
|
+
end
|
|
36
38
|
|
|
37
39
|
next unless result[nested_prefix] && !result[nested_prefix].nil?
|
|
38
40
|
|
|
@@ -5,7 +5,8 @@ module ForestAdminDatasourceMongoid
|
|
|
5
5
|
# @example
|
|
6
6
|
# unnest(['firstname', 'book.title', 'book.author'], 'book') == ['title', 'author']
|
|
7
7
|
def unnest(strings, prefix)
|
|
8
|
-
|
|
8
|
+
prefix_with_dot = "#{prefix}."
|
|
9
|
+
strings.filter_map { |field| field[(prefix.size + 1)..] if field.start_with?(prefix_with_dot) }
|
|
9
10
|
end
|
|
10
11
|
|
|
11
12
|
def escape(str)
|
|
@@ -76,7 +76,7 @@ module ForestAdminDatasourceMongoid
|
|
|
76
76
|
if condition_tree.is_a? Nodes::ConditionTreeBranch
|
|
77
77
|
condition_tree.conditions.each { |condition| list_fields_used_in_filter_tree(condition, fields) }
|
|
78
78
|
elsif condition_tree&.field&.include?(':')
|
|
79
|
-
list_paths(condition_tree.field)
|
|
79
|
+
fields.merge(list_paths(condition_tree.field))
|
|
80
80
|
end
|
|
81
81
|
end
|
|
82
82
|
|
|
@@ -35,23 +35,25 @@ module ForestAdminDatasourceMongoid
|
|
|
35
35
|
return {} if options[:include] && !options[:include].include?(name)
|
|
36
36
|
return {} if options[:exclude]&.include?(name)
|
|
37
37
|
|
|
38
|
-
projection.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
projection.each_with_object({}) do |field_name, acc|
|
|
39
|
+
next unless field_name.include?('@@@')
|
|
40
|
+
|
|
41
|
+
curr = "#{name}.#{field_name.tr(":", ".")}"
|
|
42
|
+
acc[curr] = "$#{curr.gsub("@@@", ".")}"
|
|
43
|
+
end
|
|
43
44
|
end
|
|
44
45
|
|
|
45
46
|
def self.lookup_relation(current_path, schema_stack, name, projection, options)
|
|
46
|
-
models = ObjectSpace
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
models = ObjectSpace.each_object(Class).with_object({}) do |klass, hash|
|
|
48
|
+
next unless klass < Mongoid::Document && klass.name && !klass.name.start_with?('Mongoid::')
|
|
49
|
+
|
|
50
|
+
hash[klass.name] = klass
|
|
51
|
+
end
|
|
50
52
|
|
|
51
53
|
as = current_path ? "#{current_path}.#{name}" : name
|
|
52
54
|
|
|
53
|
-
last_schema = schema_stack
|
|
54
|
-
previous_schema = schema_stack
|
|
55
|
+
last_schema = schema_stack.last
|
|
56
|
+
previous_schema = schema_stack
|
|
55
57
|
|
|
56
58
|
return {} if options[:include] && !options[:include].include?(as)
|
|
57
59
|
return {} if options[:exclude]&.include?(as)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: forest_admin_datasource_mongoid
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.19.
|
|
4
|
+
version: 1.19.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Matthieu
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: exe
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2026-01-05 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: mongoid
|