content_signals 0.1.10 → 0.1.15
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: e2c1d01c7f6f684b573250d04429a365fa3ab703cb8dddac8ddac0a7131580b8
|
|
4
|
+
data.tar.gz: bb343e43a050d8007817062d8de52f64f3ed54ee51d459b1a4988689e420083d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4ca85cd8372d706ff93c3c9faa11ecf2920eff399fd7fa276f7f6cd09d7e81b569a8977cb1998189c43790c510500b8530f00a88a2d9860819909bc656eaa85e
|
|
7
|
+
data.tar.gz: 86dd62f5920ddc4565f4a619ba34ff9c57ef130e12f3a08af719fa11e6895bb28cd869d3278f338f3ef7004e231122b97cf9f1fe399f0d737d771cea3bff21c2
|
|
@@ -6,33 +6,21 @@ module ContentSignals
|
|
|
6
6
|
|
|
7
7
|
# Associations
|
|
8
8
|
belongs_to :trackable, polymorphic: true, counter_cache: :page_views_count
|
|
9
|
-
belongs_to :tenant, optional: true if ContentSignals.configuration.multitenancy?
|
|
10
9
|
belongs_to :user, optional: true
|
|
11
10
|
|
|
11
|
+
# tenant_id is a plain string (UUID), not a foreign key — declare explicitly
|
|
12
|
+
# Guard allows db:migrate to run on a fresh DB before the table exists
|
|
13
|
+
attribute :tenant_id, :string if connection.table_exists?(table_name) rescue nil
|
|
14
|
+
|
|
12
15
|
# Validations
|
|
13
16
|
validates :trackable_type, :trackable_id, :visitor_id, :viewed_at, presence: true
|
|
14
17
|
validates :country_code, length: { maximum: 2 }, allow_nil: true
|
|
15
18
|
validates :device_type, inclusion: { in: %w[desktop mobile tablet] }, allow_nil: true
|
|
16
19
|
validates :app_platform, inclusion: { in: %w[hybrid native] }, allow_nil: true
|
|
17
20
|
|
|
18
|
-
#
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
def self.current_tenant_id
|
|
23
|
-
return nil unless ContentSignals.configuration.multitenancy?
|
|
24
|
-
|
|
25
|
-
method_name = ContentSignals.configuration.current_tenant_method
|
|
26
|
-
return nil unless method_name
|
|
27
|
-
|
|
28
|
-
# Try to get tenant_id from Current, controller, or thread
|
|
29
|
-
if defined?(Current) && Current.respond_to?(method_name)
|
|
30
|
-
Current.send(method_name)
|
|
31
|
-
elsif Thread.current[method_name]
|
|
32
|
-
Thread.current[method_name]
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
end
|
|
21
|
+
# Tenant filtering — use explicitly instead of default_scope to avoid
|
|
22
|
+
# silent NULL filtering in background jobs, console, and migrations.
|
|
23
|
+
scope :for_tenant, ->(id) { where(tenant_id: id) }
|
|
36
24
|
|
|
37
25
|
# Time period scopes
|
|
38
26
|
scope :today, -> { where("viewed_at >= ?", Time.current.beginning_of_day) }
|
|
@@ -154,8 +154,8 @@ module ContentSignals
|
|
|
154
154
|
# Prefer X-Real-IP (set by reverse proxies like Caddy/Nginx) over
|
|
155
155
|
# remote_ip which may still contain an internal proxy IP when
|
|
156
156
|
# kamal-proxy overwrites X-Forwarded-For.
|
|
157
|
-
|
|
158
|
-
|
|
157
|
+
real_ip = @request.headers['X-Real-IP']
|
|
158
|
+
return real_ip if real_ip.present? && !private_ip?(real_ip)
|
|
159
159
|
|
|
160
160
|
@request.remote_ip
|
|
161
161
|
end
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
class CreateContentSignalsPageViews < ActiveRecord::Migration<%= migration_version %>
|
|
2
2
|
def change
|
|
3
3
|
create_table :content_signals_page_views do |t|
|
|
4
|
-
# Multi-tenancy support (optional)
|
|
5
|
-
t.
|
|
4
|
+
# Multi-tenancy support (optional, string to support both UUID and integer tenant IDs)
|
|
5
|
+
t.string :tenant_id, index: true
|
|
6
6
|
|
|
7
7
|
# Polymorphic trackable (Page, Profile, Event, etc.)
|
|
8
8
|
t.string :trackable_type, null: false
|