thecore_backend_commons 3.5.1 → 3.7.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/app/models/concerns/time_zone_aware.rb +56 -0
- data/app/models/push_message.rb +4 -0
- data/config/initializers/application_config.rb +8 -0
- data/db/migrate/20260908000010_add_time_zone_columns_to_push_messages.rb +7 -0
- data/lib/thecore_backend_commons/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 82db8e6c6b82cca8191867896dff88204e7fee3d3c9630a2479ba01d217da73f
|
|
4
|
+
data.tar.gz: 1f86cbae0d9a88ea2d9c11547a241523b428d561ce0284779511b6cb7259fa1a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d2e8cfc24547a64c22ece5deb69850716462ff57354563a2ad5356dbd3ef7cfc062eeb5221363560dda8bbb7f7c6d620715dc464474ba92a7d52536ee01384c0
|
|
7
|
+
data.tar.gz: aaf01c35547236f4fce81905966d44d70a6eea017bace4336e1a47fcdd4be5063a83a929354996434eee945c8c25224aee28b8a779ed89b86643e5c9afb42182
|
|
@@ -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
|
|
@@ -7,3 +7,11 @@ Rails.application.config.active_storage.routes_prefix = ENV.fetch("RAILS_RELATIV
|
|
|
7
7
|
Rails.application.config.action_mailer.delivery_method = :smtp
|
|
8
8
|
|
|
9
9
|
Rails.application.config.action_cable.allowed_request_origins = [/http:\/\/*/, /https:\/\/*/, /file:\/\/*/, 'file://', nil]
|
|
10
|
+
|
|
11
|
+
# Every Thecore app ships a dedicated Sidekiq worker service alongside the web backend (see
|
|
12
|
+
# thecore_devcontainer's docker-compose.yml) — this gem already hard-requires the sidekiq gems
|
|
13
|
+
# and mounts Sidekiq::Web unconditionally (thecore_background_jobs), so ActiveJob should actually
|
|
14
|
+
# route through it rather than defaulting to Rails' in-process :async, which silently drops any
|
|
15
|
+
# job in flight when its process restarts. Production only: :async remains the default in
|
|
16
|
+
# development/test so neither requires a reachable Redis. See docs/adr/0001, CONTEXT.md.
|
|
17
|
+
Rails.application.config.active_job.queue_adapter = :sidekiq if Rails.env.production?
|
|
@@ -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.7.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
|