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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2814cf6ff3fc8c2b60cb3b663aa0860d25161c8cd0971a6b76f3efd0b29df966
4
- data.tar.gz: 519245af607dff7b04652b65efb88584dc6559f6cc21a60a5591e7c081a9a00d
3
+ metadata.gz: af8d0733bb1c7ad78521684f1e9cd36879ce8fd2edac11554fae77a8857446a3
4
+ data.tar.gz: 8d4f390e60a0edc7fbbe8070145768c317524887643ac5afe055dd8675cfe87d
5
5
  SHA512:
6
- metadata.gz: d15e193b9f21739e577dbc8243e4bb44ff127fa048d4cef33551b58ee55349f27ccd1ca99ac16044c2eed5f844924389542df276f1d7ba06e89d294af5deb164
7
- data.tar.gz: 889853a5ce035794316072a74515842f4a43d41a056523de35993bccf270b51475ac195d5b2b96f08db5b1f6829ab47936616a9e162c7bac682b988ee641a6a5
6
+ metadata.gz: 607eb70c78ea78450ed752a1351c038736a7ad5f6023b969acb560ea59e20b95a3ff54a718b26465e01420ced20131a23d325bc05f34540a7fa77b6df6677c96
7
+ data.tar.gz: 22704e9424cdba8feb897dafb62710cf41ebe205dd36ca1d0a4356771c8b5419dfc1d823d2e73d03619c3bc9be4bb10c420a8a50829d396982ffac74cc8cfed7
@@ -1,8 +1,19 @@
1
- # Turns API calls to always UTC, leaving the APP the freedom to use local timezone
2
- module ActiveSupport
3
- class TimeWithZone
4
- def as_json(options = nil)
5
- utc
6
- end
7
- end
8
- end
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|
@@ -1,3 +1,3 @@
1
1
  module ModelDrivenApi
2
- VERSION = "3.10.0".freeze
2
+ VERSION = "3.11.0".freeze
3
3
  end
@@ -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,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: model_driven_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.10.0
4
+ version: 3.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriele Tassoni