bp3-core 0.4.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 +15 -0
- data/Gemfile.lock +27 -25
- data/lib/bp3/core/system_logs.rb +11 -2
- data/lib/bp3/core/tenantable.rb +50 -0
- data/lib/bp3/core/version.rb +1 -1
- metadata +2 -3
- data/.ruby-version +0 -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
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
### Changed
|
|
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
|
+
|
|
12
|
+
## [0.5.0] - 2026-11-02
|
|
13
|
+
|
|
14
|
+
- `Bp3::Core::SystemLogs` writes to the Rails log at the level it was called with, instead of always at
|
|
15
|
+
`debug`. An exception is always written as `error`, whatever the level, and so is a message whose level
|
|
16
|
+
is not a logger level
|
|
17
|
+
|
|
3
18
|
## [0.4.0] - 2026-10-30
|
|
4
19
|
|
|
5
20
|
### Security
|
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)
|
|
@@ -41,9 +41,10 @@ GEM
|
|
|
41
41
|
ast (2.4.3)
|
|
42
42
|
base64 (0.3.0)
|
|
43
43
|
bigdecimal (4.1.3)
|
|
44
|
-
bp3-request_state (0.1.
|
|
44
|
+
bp3-request_state (0.1.4)
|
|
45
45
|
actionpack (~> 8.1)
|
|
46
46
|
activesupport (~> 8.1)
|
|
47
|
+
ostruct (>= 0.6)
|
|
47
48
|
request_store (>= 1.5.1)
|
|
48
49
|
builder (3.3.0)
|
|
49
50
|
concurrent-ruby (1.3.8)
|
|
@@ -58,21 +59,22 @@ GEM
|
|
|
58
59
|
language_server-protocol (3.17.0.6)
|
|
59
60
|
lint_roller (1.1.0)
|
|
60
61
|
logger (1.7.0)
|
|
61
|
-
loofah (2.25.
|
|
62
|
+
loofah (2.25.3)
|
|
62
63
|
crass (~> 1.0.2)
|
|
63
|
-
nokogiri (>= 1.
|
|
64
|
-
minitest (6.0
|
|
64
|
+
nokogiri (>= 1.19.5)
|
|
65
|
+
minitest (6.1.0)
|
|
65
66
|
drb (~> 2.0)
|
|
66
|
-
prism (
|
|
67
|
-
nokogiri (1.19.
|
|
67
|
+
prism (>= 1.5, < 3)
|
|
68
|
+
nokogiri (1.19.7-x86_64-darwin)
|
|
68
69
|
racc (~> 1.4)
|
|
70
|
+
ostruct (0.6.3)
|
|
69
71
|
parallel (2.3.0)
|
|
70
72
|
parser (3.3.13.0)
|
|
71
73
|
ast (~> 2.4.1)
|
|
72
74
|
racc
|
|
73
|
-
prism (1.
|
|
75
|
+
prism (2.1.0-x86_64-darwin)
|
|
74
76
|
racc (1.8.1)
|
|
75
|
-
rack (3.2.
|
|
77
|
+
rack (3.2.8)
|
|
76
78
|
rack-session (2.1.2)
|
|
77
79
|
base64 (>= 0.1.0)
|
|
78
80
|
rack (>= 3.0.0)
|
|
@@ -82,8 +84,8 @@ GEM
|
|
|
82
84
|
activesupport (>= 5.0.0)
|
|
83
85
|
minitest
|
|
84
86
|
nokogiri (>= 1.6)
|
|
85
|
-
rails-html-sanitizer (1.7.
|
|
86
|
-
loofah (~> 2.25, >= 2.25.
|
|
87
|
+
rails-html-sanitizer (1.7.2)
|
|
88
|
+
loofah (~> 2.25, >= 2.25.3)
|
|
87
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)
|
|
88
90
|
rainbow (3.1.1)
|
|
89
91
|
rake (13.4.2)
|
|
@@ -94,16 +96,16 @@ GEM
|
|
|
94
96
|
rspec-core (~> 3.13.0)
|
|
95
97
|
rspec-expectations (~> 3.13.0)
|
|
96
98
|
rspec-mocks (~> 3.13.0)
|
|
97
|
-
rspec-core (3.13.
|
|
99
|
+
rspec-core (3.13.7)
|
|
98
100
|
rspec-support (~> 3.13.0)
|
|
99
|
-
rspec-expectations (3.13.
|
|
101
|
+
rspec-expectations (3.13.6)
|
|
100
102
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
101
103
|
rspec-support (~> 3.13.0)
|
|
102
|
-
rspec-mocks (3.13.
|
|
104
|
+
rspec-mocks (3.13.9)
|
|
103
105
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
104
106
|
rspec-support (~> 3.13.0)
|
|
105
|
-
rspec-support (3.13.
|
|
106
|
-
rubocop (1.92.
|
|
107
|
+
rspec-support (3.13.8)
|
|
108
|
+
rubocop (1.92.2)
|
|
107
109
|
json (>= 2.3)
|
|
108
110
|
language_server-protocol (~> 3.17.0.2)
|
|
109
111
|
lint_roller (~> 1.1.0)
|
|
@@ -114,9 +116,9 @@ GEM
|
|
|
114
116
|
rubocop-ast (>= 1.49.0, < 2.0)
|
|
115
117
|
ruby-progressbar (~> 1.7)
|
|
116
118
|
unicode-display_width (>= 2.4.0, < 4.0)
|
|
117
|
-
rubocop-ast (1.
|
|
119
|
+
rubocop-ast (1.51.0)
|
|
118
120
|
parser (>= 3.3.7.2)
|
|
119
|
-
prism (
|
|
121
|
+
prism (>= 1.7)
|
|
120
122
|
rubocop-rake (0.7.1)
|
|
121
123
|
lint_roller (~> 1.1)
|
|
122
124
|
rubocop (>= 1.72.1)
|
data/lib/bp3/core/system_logs.rb
CHANGED
|
@@ -8,6 +8,7 @@ module Bp3
|
|
|
8
8
|
extend ActiveSupport::Concern
|
|
9
9
|
|
|
10
10
|
SYSTEM_LOG_DEFAULTS = { log_to_db: true, log_to_io: true }.freeze
|
|
11
|
+
IO_LEVELS = %w[debug info warn error].freeze
|
|
11
12
|
|
|
12
13
|
mattr_accessor :system_exception_name, :system_log_name
|
|
13
14
|
|
|
@@ -27,7 +28,7 @@ module Bp3
|
|
|
27
28
|
record = nil
|
|
28
29
|
if exception
|
|
29
30
|
if system_log_options[:log_to_io]
|
|
30
|
-
rails_logger.
|
|
31
|
+
rails_logger.error do
|
|
31
32
|
"SystemLogs, #{level}, #{key}, #{exception.message}"
|
|
32
33
|
end
|
|
33
34
|
end
|
|
@@ -35,7 +36,9 @@ module Bp3
|
|
|
35
36
|
end
|
|
36
37
|
return record if (message || '').strip == ''
|
|
37
38
|
|
|
38
|
-
|
|
39
|
+
if system_log_options[:log_to_io]
|
|
40
|
+
rails_logger.public_send(io_level(level)) { "SystemLogs, #{level}, #{key}, #{message}" }
|
|
41
|
+
end
|
|
39
42
|
begin
|
|
40
43
|
system_logger.log_message(level:, key:, message:, details:) if system_log_options[:log_to_db]
|
|
41
44
|
rescue StandardError => e
|
|
@@ -68,6 +71,12 @@ module Bp3
|
|
|
68
71
|
log(level: 'exception', key:, exception:, details:, **system_log_options)
|
|
69
72
|
end
|
|
70
73
|
|
|
74
|
+
# The logger method for a log level. Anything that is not a logger level is written as an error.
|
|
75
|
+
# The level can come from data, so it never names a method directly.
|
|
76
|
+
def io_level(level)
|
|
77
|
+
IO_LEVELS.include?(level.to_s) ? level.to_s : 'error'
|
|
78
|
+
end
|
|
79
|
+
|
|
71
80
|
def rails_logger
|
|
72
81
|
return Rails.logger if defined?(Rails)
|
|
73
82
|
|
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
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bp3-core
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Wim den Braven
|
|
@@ -129,7 +129,6 @@ extra_rdoc_files: []
|
|
|
129
129
|
files:
|
|
130
130
|
- ".rspec"
|
|
131
131
|
- ".rubocop.yml"
|
|
132
|
-
- ".ruby-version"
|
|
133
132
|
- ".yardopts"
|
|
134
133
|
- CHANGELOG.md
|
|
135
134
|
- CLAUDE.md
|
|
@@ -178,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
178
177
|
- !ruby/object:Gem::Version
|
|
179
178
|
version: '0'
|
|
180
179
|
requirements: []
|
|
181
|
-
rubygems_version: 4.0.
|
|
180
|
+
rubygems_version: 4.0.23
|
|
182
181
|
specification_version: 4
|
|
183
182
|
summary: bp3-core provides core concerns for BP3 (persuavis/black_phoebe_3).
|
|
184
183
|
test_files: []
|
data/.ruby-version
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
ruby-3.4.6
|