bp3-core 0.5.0 → 0.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 +4 -4
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +24 -24
- data/lib/bp3/core/tenantable.rb +50 -0
- data/lib/bp3/core/version.rb +1 -1
- 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: d56fbb0e78a3828d04c5657ab2c584cf4b19d286d56de319715341b0747d7eac
|
|
4
|
+
data.tar.gz: ce04a176d7ec32b9dbc899cd9f5c2d722a0ce2fd5441bdfa2ed88ad7f37973a3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c3e5677335456935d817787d45ff7e3bdf73ae506fd33861d17ca284963d30ee217c784322b3cb604b55cf4106d788aa63d334bd7512e99ea38a2d17166c8d4f
|
|
7
|
+
data.tar.gz: e62b3abcba275736ee1f89cb5ffb19f9f02c2d21eb700ac05d6bddc50162cf5a336fccf95278562ce29d94956a2202cb0c9b26fbc773b8faf025c53e7c8173f3
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
### Changed
|
|
4
4
|
|
|
5
|
+
## [0.6.0] - 2026-11-14
|
|
6
|
+
|
|
7
|
+
### Breaking (in a good way)
|
|
8
|
+
|
|
9
|
+
- Validate that belongs_to records match site
|
|
10
|
+
- Update gems
|
|
11
|
+
|
|
5
12
|
## [0.5.0] - 2026-11-02
|
|
6
13
|
|
|
7
14
|
- `Bp3::Core::SystemLogs` writes to the Rails log at the level it was called with, instead of always at
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
bp3-core (0.
|
|
4
|
+
bp3-core (0.6.0)
|
|
5
5
|
actionview (~> 8.1)
|
|
6
6
|
activesupport (~> 8.1)
|
|
7
7
|
bp3-request_state (~> 0.1)
|
|
@@ -9,9 +9,9 @@ PATH
|
|
|
9
9
|
GEM
|
|
10
10
|
remote: https://rubygems.org/
|
|
11
11
|
specs:
|
|
12
|
-
actionpack (8.1.4)
|
|
13
|
-
actionview (= 8.1.4)
|
|
14
|
-
activesupport (= 8.1.4)
|
|
12
|
+
actionpack (8.1.4.1)
|
|
13
|
+
actionview (= 8.1.4.1)
|
|
14
|
+
activesupport (= 8.1.4.1)
|
|
15
15
|
nokogiri (>= 1.8.5)
|
|
16
16
|
rack (>= 2.2.4)
|
|
17
17
|
rack-session (>= 1.0.1)
|
|
@@ -19,13 +19,13 @@ GEM
|
|
|
19
19
|
rails-dom-testing (~> 2.2)
|
|
20
20
|
rails-html-sanitizer (~> 1.6)
|
|
21
21
|
useragent (~> 0.16)
|
|
22
|
-
actionview (8.1.4)
|
|
23
|
-
activesupport (= 8.1.4)
|
|
22
|
+
actionview (8.1.4.1)
|
|
23
|
+
activesupport (= 8.1.4.1)
|
|
24
24
|
builder (~> 3.1)
|
|
25
25
|
erubi (~> 1.11)
|
|
26
26
|
rails-dom-testing (~> 2.2)
|
|
27
|
-
rails-html-sanitizer (~> 1.6)
|
|
28
|
-
activesupport (8.1.4)
|
|
27
|
+
rails-html-sanitizer (~> 1.6, >= 1.7.2)
|
|
28
|
+
activesupport (8.1.4.1)
|
|
29
29
|
base64
|
|
30
30
|
bigdecimal
|
|
31
31
|
concurrent-ruby (~> 1.0, >= 1.3.1)
|
|
@@ -59,22 +59,22 @@ GEM
|
|
|
59
59
|
language_server-protocol (3.17.0.6)
|
|
60
60
|
lint_roller (1.1.0)
|
|
61
61
|
logger (1.7.0)
|
|
62
|
-
loofah (2.25.
|
|
62
|
+
loofah (2.25.3)
|
|
63
63
|
crass (~> 1.0.2)
|
|
64
|
-
nokogiri (>= 1.
|
|
65
|
-
minitest (6.0
|
|
64
|
+
nokogiri (>= 1.19.5)
|
|
65
|
+
minitest (6.1.0)
|
|
66
66
|
drb (~> 2.0)
|
|
67
|
-
prism (
|
|
68
|
-
nokogiri (1.19.
|
|
67
|
+
prism (>= 1.5, < 3)
|
|
68
|
+
nokogiri (1.19.7-x86_64-darwin)
|
|
69
69
|
racc (~> 1.4)
|
|
70
70
|
ostruct (0.6.3)
|
|
71
71
|
parallel (2.3.0)
|
|
72
72
|
parser (3.3.13.0)
|
|
73
73
|
ast (~> 2.4.1)
|
|
74
74
|
racc
|
|
75
|
-
prism (1.
|
|
75
|
+
prism (2.1.0-x86_64-darwin)
|
|
76
76
|
racc (1.8.1)
|
|
77
|
-
rack (3.2.
|
|
77
|
+
rack (3.2.8)
|
|
78
78
|
rack-session (2.1.2)
|
|
79
79
|
base64 (>= 0.1.0)
|
|
80
80
|
rack (>= 3.0.0)
|
|
@@ -84,8 +84,8 @@ GEM
|
|
|
84
84
|
activesupport (>= 5.0.0)
|
|
85
85
|
minitest
|
|
86
86
|
nokogiri (>= 1.6)
|
|
87
|
-
rails-html-sanitizer (1.7.
|
|
88
|
-
loofah (~> 2.25, >= 2.25.
|
|
87
|
+
rails-html-sanitizer (1.7.2)
|
|
88
|
+
loofah (~> 2.25, >= 2.25.3)
|
|
89
89
|
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
|
|
90
90
|
rainbow (3.1.1)
|
|
91
91
|
rake (13.4.2)
|
|
@@ -96,16 +96,16 @@ GEM
|
|
|
96
96
|
rspec-core (~> 3.13.0)
|
|
97
97
|
rspec-expectations (~> 3.13.0)
|
|
98
98
|
rspec-mocks (~> 3.13.0)
|
|
99
|
-
rspec-core (3.13.
|
|
99
|
+
rspec-core (3.13.7)
|
|
100
100
|
rspec-support (~> 3.13.0)
|
|
101
|
-
rspec-expectations (3.13.
|
|
101
|
+
rspec-expectations (3.13.6)
|
|
102
102
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
103
103
|
rspec-support (~> 3.13.0)
|
|
104
|
-
rspec-mocks (3.13.
|
|
104
|
+
rspec-mocks (3.13.9)
|
|
105
105
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
106
106
|
rspec-support (~> 3.13.0)
|
|
107
|
-
rspec-support (3.13.
|
|
108
|
-
rubocop (1.92.
|
|
107
|
+
rspec-support (3.13.8)
|
|
108
|
+
rubocop (1.92.2)
|
|
109
109
|
json (>= 2.3)
|
|
110
110
|
language_server-protocol (~> 3.17.0.2)
|
|
111
111
|
lint_roller (~> 1.1.0)
|
|
@@ -116,9 +116,9 @@ GEM
|
|
|
116
116
|
rubocop-ast (>= 1.49.0, < 2.0)
|
|
117
117
|
ruby-progressbar (~> 1.7)
|
|
118
118
|
unicode-display_width (>= 2.4.0, < 4.0)
|
|
119
|
-
rubocop-ast (1.
|
|
119
|
+
rubocop-ast (1.51.0)
|
|
120
120
|
parser (>= 3.3.7.2)
|
|
121
|
-
prism (
|
|
121
|
+
prism (>= 1.7)
|
|
122
122
|
rubocop-rake (0.7.1)
|
|
123
123
|
lint_roller (~> 1.1)
|
|
124
124
|
rubocop (>= 1.72.1)
|
data/lib/bp3/core/tenantable.rb
CHANGED
|
@@ -5,6 +5,9 @@ module Bp3
|
|
|
5
5
|
module Tenantable
|
|
6
6
|
extend ActiveSupport::Concern
|
|
7
7
|
|
|
8
|
+
# The belongs_to associations with a site check of their own
|
|
9
|
+
SITE_CHECKED_ASSOCIATIONS = %i[sites_site tenant workspaces_workspace].freeze
|
|
10
|
+
|
|
8
11
|
# The application's request state, the Bp3::RequestState::Base subclass Bp3::Core::Rqid is
|
|
9
12
|
# configured with
|
|
10
13
|
def self.global_request_state
|
|
@@ -70,6 +73,51 @@ module Bp3
|
|
|
70
73
|
errors.add(:workspaces_workspace, :must_match_site)
|
|
71
74
|
end
|
|
72
75
|
|
|
76
|
+
# Every record the row belongs to that has a site must have the row's site. A root's default scope
|
|
77
|
+
# reaches every site, so an id from another site is found and would otherwise be stored. Checked
|
|
78
|
+
# when the foreign key, or a polymorphic type, is set or changed, so an unchanged row costs nothing.
|
|
79
|
+
def belongs_to_records_match_site
|
|
80
|
+
site_id = sites_site_id || sites_site&.id
|
|
81
|
+
return if site_id.nil?
|
|
82
|
+
|
|
83
|
+
self.class.reflect_on_all_associations(:belongs_to).each do |reflection|
|
|
84
|
+
next if SITE_CHECKED_ASSOCIATIONS.include?(reflection.name) || !belonged_record_changed?(reflection)
|
|
85
|
+
|
|
86
|
+
belonged_site_id = belonged_record_site_id(reflection)
|
|
87
|
+
next if belonged_site_id.nil? || belonged_site_id == site_id
|
|
88
|
+
|
|
89
|
+
errors.add(reflection.name, :must_match_site)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def belonged_record_changed?(reflection)
|
|
94
|
+
attribute_changed?(reflection.foreign_key.to_s) ||
|
|
95
|
+
(reflection.polymorphic? && attribute_changed?(reflection.foreign_type.to_s)) ||
|
|
96
|
+
association(reflection.name).target&.new_record?
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# The site of the record the association points to, nil when that record has no site
|
|
100
|
+
def belonged_record_site_id(reflection)
|
|
101
|
+
loaded = association(reflection.name)
|
|
102
|
+
if loaded.loaded? && !loaded.stale_target? && loaded.target
|
|
103
|
+
return loaded.target.respond_to?(:sites_site_id) ? loaded.target.sites_site_id : nil
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
klass = belonged_record_class(reflection)
|
|
107
|
+
id = self[reflection.foreign_key]
|
|
108
|
+
return if klass.nil? || id.nil? || !klass.column_names.include?('sites_site_id')
|
|
109
|
+
|
|
110
|
+
klass.unscoped.where(klass.primary_key => id).pick(:sites_site_id)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def belonged_record_class(reflection)
|
|
114
|
+
klass = reflection.polymorphic? ? self[reflection.foreign_type]&.safe_constantize : reflection.klass
|
|
115
|
+
klass if klass.is_a?(Class) && klass < ActiveRecord::Base
|
|
116
|
+
rescue NameError
|
|
117
|
+
nil
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# rubocop:disable-next Metrics/BlockLength
|
|
73
121
|
class_methods do
|
|
74
122
|
def configure_tenancy(tenancy_configuration = {})
|
|
75
123
|
@tenancy_configuration = default_configuration.merge(tenancy_configuration)
|
|
@@ -93,6 +141,8 @@ module Bp3
|
|
|
93
141
|
|
|
94
142
|
before_validation :set_sites_site_id
|
|
95
143
|
|
|
144
|
+
validate :belongs_to_records_match_site
|
|
145
|
+
|
|
96
146
|
default_scope lambda {
|
|
97
147
|
site = Bp3::Core::Tenantable.global_request_state.either_site
|
|
98
148
|
site = nil if Bp3::Core::Tenantable.reaches_every_site?
|
data/lib/bp3/core/version.rb
CHANGED