model_driven_api 3.10.0 → 3.11.0
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/config/initializers/time_with_zone.rb +19 -8
- data/lib/model_driven_api/engine.rb +13 -0
- data/lib/model_driven_api/version.rb +1 -1
- data/lib/model_driven_api.rb +16 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: af8d0733bb1c7ad78521684f1e9cd36879ce8fd2edac11554fae77a8857446a3
|
|
4
|
+
data.tar.gz: 8d4f390e60a0edc7fbbe8070145768c317524887643ac5afe055dd8675cfe87d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 607eb70c78ea78450ed752a1351c038736a7ad5f6023b969acb560ea59e20b95a3ff54a718b26465e01420ced20131a23d325bc05f34540a7fa77b6df6677c96
|
|
7
|
+
data.tar.gz: 22704e9424cdba8feb897dafb62710cf41ebe205dd36ca1d0a4356771c8b5419dfc1d823d2e73d03619c3bc9be4bb10c420a8a50829d396982ffac74cc8cfed7
|
|
@@ -1,8 +1,19 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
# REMOVED (3.11.0): this file used to monkey-patch ActiveSupport::TimeWithZone#as_json
|
|
2
|
+
# to always return `utc` ("Force json rendered datetimes to UTC", 2021):
|
|
3
|
+
#
|
|
4
|
+
# class ActiveSupport::TimeWithZone
|
|
5
|
+
# def as_json(options = nil) = utc
|
|
6
|
+
# end
|
|
7
|
+
#
|
|
8
|
+
# Why it was removed: the patch flattened EVERY TimeWithZone to UTC at JSON time, so any
|
|
9
|
+
# value deliberately localized for the client — e.g. TimeZoneAware's `<field>_server_tz` /
|
|
10
|
+
# `<field>_record_tz` (thecore_backend_commons), also reused by mytask's Gantt endpoint —
|
|
11
|
+
# was rendered as the bare UTC value ("...T08:00:00.000Z" instead of
|
|
12
|
+
# "...T10:00:00.000+02:00"), making those attributes identical to the raw field.
|
|
13
|
+
#
|
|
14
|
+
# Why removing it is safe: the guarantee the patch provided ("API datetimes are UTC") is now
|
|
15
|
+
# enforced at its source instead — ModelDrivenApi::Engine refuses to boot unless
|
|
16
|
+
# `config.time_zone` is UTC (see the :enforce_utc_time_zone initializer in
|
|
17
|
+
# lib/model_driven_api/engine.rb). With Time.zone pinned to UTC, every plain datetime column
|
|
18
|
+
# still serializes through Rails' standard TimeWithZone#as_json as "...Z", exactly as before;
|
|
19
|
+
# only values explicitly converted with `in_time_zone(...)` now keep their own offset.
|
|
@@ -7,6 +7,19 @@ module ModelDrivenApi
|
|
|
7
7
|
ActionDispatch::Request.parameter_parsers[:json]
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
+
# The backend works exclusively in UTC: every thecore app must keep Rails' default
|
|
11
|
+
# `config.time_zone = "UTC"` (and ActiveRecord's default `:utc` storage), so every datetime
|
|
12
|
+
# the API renders is UTC ("...Z") and localization is left entirely to the frontends.
|
|
13
|
+
# Values a model deliberately localizes (e.g. TimeZoneAware's `_server_tz`/`_record_tz`)
|
|
14
|
+
# are the only ones rendered with an offset. This replaces the old global
|
|
15
|
+
# TimeWithZone#as_json -> utc monkey-patch (see config/initializers/time_with_zone.rb for
|
|
16
|
+
# why that was removed). Runs before Rails applies the zone, so a misconfigured app fails
|
|
17
|
+
# at boot instead of silently rendering local times.
|
|
18
|
+
initializer :enforce_utc_time_zone, before: "active_support.initialize_time_zone" do |app|
|
|
19
|
+
db_zone = app.config.active_record.default_timezone if app.config.respond_to?(:active_record)
|
|
20
|
+
ModelDrivenApi.enforce_utc!(app.config.time_zone, db_zone)
|
|
21
|
+
end
|
|
22
|
+
|
|
10
23
|
initializer :append_migrations do |app|
|
|
11
24
|
unless app.root.to_s == root.to_s
|
|
12
25
|
config.paths["db/migrate"].expanded.each do |expanded_path|
|
data/lib/model_driven_api.rb
CHANGED
|
@@ -26,6 +26,22 @@ require "api/open_api/v3"
|
|
|
26
26
|
require "api/v3/serializer_factory"
|
|
27
27
|
|
|
28
28
|
module ModelDrivenApi
|
|
29
|
+
UTC_ZONE_NAMES = %w[UTC Etc/UTC].freeze
|
|
30
|
+
|
|
31
|
+
# Raises unless the app is UTC-only: +time_zone+ is config.time_zone, +db_zone+ is
|
|
32
|
+
# config.active_record.default_timezone (nil = Rails' default, :utc). Called at boot by
|
|
33
|
+
# ModelDrivenApi::Engine's :enforce_utc_time_zone initializer.
|
|
34
|
+
def self.enforce_utc!(time_zone, db_zone = nil)
|
|
35
|
+
unless UTC_ZONE_NAMES.include?(time_zone.to_s)
|
|
36
|
+
raise ArgumentError, "model_driven_api requires config.time_zone to be UTC (got #{time_zone.inspect}). " \
|
|
37
|
+
"The backend is UTC-only; localize dates in the frontend instead."
|
|
38
|
+
end
|
|
39
|
+
return if db_zone.nil? || db_zone.to_sym == :utc
|
|
40
|
+
|
|
41
|
+
raise ArgumentError, "model_driven_api requires config.active_record.default_timezone to be :utc " \
|
|
42
|
+
"(got #{db_zone.inspect})."
|
|
43
|
+
end
|
|
44
|
+
|
|
29
45
|
def self.smart_merge src, dest
|
|
30
46
|
src.deeper_merge! dest, {
|
|
31
47
|
extend_existing_arrays: true,
|