thecore_backend_commons 3.5.1 → 3.6.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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f6ec05c4d8a628a806dea48ae8df9448d8292c0cabfc24e527b6134f947ad70b
|
|
4
|
+
data.tar.gz: ade58f1987fc9036d1177ec8aa13f66556b398fb382c5a361598160354319f03
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cc964bdd0ddaed6a82194249ae4ae43021488ffde211f64148e1345915301d9751cb5a52f10a4bd6193dfafb80cddbb43e2e9686bed0dbd99c89cabeb589d2d9
|
|
7
|
+
data.tar.gz: 4477a604d9a15b2e2c82cd52d66335cabff4792f5571fd06ab78833eb2a3318a59fdfebd195369c2a0d61ee18a08547fdc2f3fe0ac713329ccda965e600e0285
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
module TimeZoneAware
|
|
2
|
+
extend ActiveSupport::Concern
|
|
3
|
+
|
|
4
|
+
class_methods do
|
|
5
|
+
# Declares that +field+ (an existing UTC datetime column) is time-zone aware:
|
|
6
|
+
# adds a nullable, client-writable +<field>_time_zone+ column reader/validation,
|
|
7
|
+
# and exposes +<field>_server_tz+/+<field>_record_tz+ computed JSON attributes.
|
|
8
|
+
# The +<field>_time_zone+ column itself must already exist (added via migration).
|
|
9
|
+
def time_zone_aware(*fields)
|
|
10
|
+
fields.each do |field|
|
|
11
|
+
time_zone_attr = :"#{field}_time_zone"
|
|
12
|
+
|
|
13
|
+
validate do
|
|
14
|
+
TimeZoneAware.validate_zone(self, time_zone_attr)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
define_method(:"#{field}_server_tz") do
|
|
18
|
+
TimeZoneAware.localize(read_attribute(field), TimeZoneAware.server_time_zone)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
define_method(:"#{field}_record_tz") do
|
|
22
|
+
zone = read_attribute(time_zone_attr).presence || TimeZoneAware.server_time_zone
|
|
23
|
+
TimeZoneAware.localize(read_attribute(field), zone)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
cattr_accessor :json_attrs unless respond_to?(:json_attrs)
|
|
27
|
+
self.json_attrs = ::ModelDrivenApi.smart_merge(json_attrs || {}, {
|
|
28
|
+
methods: [:"#{field}_server_tz", :"#{field}_record_tz"],
|
|
29
|
+
})
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# The deployment-wide IANA time zone identifier (ThecoreSettings ns: :main, key: :time_zone),
|
|
35
|
+
# or nil when unset — callers treat a nil zone as "leave the UTC value unshifted".
|
|
36
|
+
def self.server_time_zone
|
|
37
|
+
::Settings.ns(:main).time_zone.presence
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# NULL-safe: localizes +value+ (a UTC datetime) to +zone_name+, or returns it
|
|
41
|
+
# unshifted when there is no zone to localize to (nil value, blank/invalid zone name).
|
|
42
|
+
def self.localize(value, zone_name)
|
|
43
|
+
return nil if value.nil?
|
|
44
|
+
|
|
45
|
+
zone = zone_name.present? ? ActiveSupport::TimeZone[zone_name] : nil
|
|
46
|
+
zone ? value.in_time_zone(zone) : value
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def self.valid_zone?(value)
|
|
50
|
+
value.blank? || ActiveSupport::TimeZone[value].present?
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def self.validate_zone(record, attr)
|
|
54
|
+
record.errors.add(attr, :invalid) unless valid_zone?(record.read_attribute(attr))
|
|
55
|
+
end
|
|
56
|
+
end
|
data/app/models/push_message.rb
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
class PushMessage < ApplicationRecord
|
|
2
|
+
include TimeZoneAware
|
|
3
|
+
|
|
4
|
+
time_zone_aware :sent_at, :received_at, :read_at
|
|
5
|
+
|
|
2
6
|
belongs_to :push_subscriber
|
|
3
7
|
belongs_to :sender, class_name: "User", foreign_key: :sender_user_id, optional: true
|
|
4
8
|
validates :title, presence: true
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
class AddTimeZoneColumnsToPushMessages < ActiveRecord::Migration[7.2]
|
|
2
|
+
def change
|
|
3
|
+
add_column :push_messages, :sent_at_time_zone, :string
|
|
4
|
+
add_column :push_messages, :received_at_time_zone, :string
|
|
5
|
+
add_column :push_messages, :read_at_time_zone, :string
|
|
6
|
+
end
|
|
7
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: thecore_backend_commons
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Gabriele Tassoni
|
|
@@ -205,6 +205,7 @@ files:
|
|
|
205
205
|
- app/channels/push_notification_channel.rb
|
|
206
206
|
- app/jobs/push_dispatch_job.rb
|
|
207
207
|
- app/mailers/concerns/smtp_deliverable.rb
|
|
208
|
+
- app/models/concerns/time_zone_aware.rb
|
|
208
209
|
- app/models/push_message.rb
|
|
209
210
|
- app/models/push_subscriber.rb
|
|
210
211
|
- config/initializers/abilities.rb
|
|
@@ -227,6 +228,7 @@ files:
|
|
|
227
228
|
- db/migrate/20260616000002_create_push_messages.rb
|
|
228
229
|
- db/migrate/20260625000001_add_sender_user_id_to_push_messages.rb
|
|
229
230
|
- db/migrate/20260629000001_add_message_type_to_push_messages.rb
|
|
231
|
+
- db/migrate/20260908000010_add_time_zone_columns_to_push_messages.rb
|
|
230
232
|
- db/seeds.rb
|
|
231
233
|
- lib/tasks/thecore_backend_commons_tasks.rake
|
|
232
234
|
- lib/thecore_backend_commons.rb
|