forest_admin_datasource_active_record 1.8.8 → 1.8.9
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8b8f6e9f395e33f43bbb6ec70f2b7996f96a1d221f3af6381fdada96fbff238b
|
|
4
|
+
data.tar.gz: 1365ef5b16b1f09905ecb07b983910eebcf2ae713befd9253ee33cd0faefc840
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 21b34c3b3a59ca7b2f2687a15ad5c793a2b80a97848296e61ab61658c446069c8fd52840a5d4dea5d28af7778ea231aeae4195f0fd31e3e1d28e3803bb7d37fc
|
|
7
|
+
data.tar.gz: 653cb5cf19aa48b4ffd3d27ec0c5bc96ad11383ba940b1082667b4c033b79d05f57b4d8ec0e840fc7f2720da252ced9d492e428c79541f628993554d4103a34a
|
|
@@ -21,7 +21,8 @@ module ForestAdminDatasourceActiveRecord
|
|
|
21
21
|
@aggregation.groups.each do |group|
|
|
22
22
|
field = format_field(group[:field])
|
|
23
23
|
if group[:operation]
|
|
24
|
-
|
|
24
|
+
# Pass original field name for validation before SQL generation
|
|
25
|
+
date_trunc_expression = date_trunc_sql(group[:operation], field, group[:field])
|
|
25
26
|
@select << "#{date_trunc_expression} AS \"#{group[:field]}\""
|
|
26
27
|
group_fields << date_trunc_expression
|
|
27
28
|
else
|
|
@@ -56,11 +57,31 @@ module ForestAdminDatasourceActiveRecord
|
|
|
56
57
|
@query
|
|
57
58
|
end
|
|
58
59
|
|
|
60
|
+
# Whitelist of valid date truncation operations
|
|
61
|
+
VALID_DATE_OPERATIONS = %w[
|
|
62
|
+
second
|
|
63
|
+
minute
|
|
64
|
+
hour
|
|
65
|
+
day
|
|
66
|
+
week
|
|
67
|
+
month
|
|
68
|
+
quarter
|
|
69
|
+
year
|
|
70
|
+
].freeze
|
|
71
|
+
|
|
59
72
|
private
|
|
60
73
|
|
|
61
|
-
def date_trunc_sql(operation, field)
|
|
74
|
+
def date_trunc_sql(operation, field, original_field_name = nil)
|
|
62
75
|
adapter_name = @collection.model.connection.adapter_name.downcase
|
|
63
|
-
operation = operation.downcase
|
|
76
|
+
operation = operation.to_s.downcase
|
|
77
|
+
|
|
78
|
+
unless VALID_DATE_OPERATIONS.include?(operation)
|
|
79
|
+
raise ForestAdminDatasourceToolkit::Exceptions::ValidationError,
|
|
80
|
+
"Invalid date truncation operation: '#{operation}'. " \
|
|
81
|
+
"Allowed values: #{VALID_DATE_OPERATIONS.join(", ")}"
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
validate_field_exists!(original_field_name || field)
|
|
64
85
|
|
|
65
86
|
case adapter_name
|
|
66
87
|
when 'postgresql'
|
|
@@ -74,6 +95,14 @@ module ForestAdminDatasourceActiveRecord
|
|
|
74
95
|
end
|
|
75
96
|
end
|
|
76
97
|
|
|
98
|
+
def validate_field_exists!(field)
|
|
99
|
+
ForestAdminDatasourceToolkit::Utils::Collection.get_field_schema(@collection, field)
|
|
100
|
+
rescue ForestAdminDatasourceToolkit::Exceptions::ForestException => e
|
|
101
|
+
# Re-raise as ValidationError for consistency with other validation errors in this class
|
|
102
|
+
raise ForestAdminDatasourceToolkit::Exceptions::ValidationError,
|
|
103
|
+
"Invalid field '#{field}': #{e.message}"
|
|
104
|
+
end
|
|
105
|
+
|
|
77
106
|
# rubocop:disable Layout/LineLength
|
|
78
107
|
def mysql_date_trunc(operation, field)
|
|
79
108
|
case operation
|