bp3-core 0.3.0 → 0.5.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: 76165d42f4b28714655519eeddedc6d08dd0b5bc9a5e919b389f173aa0bf20a0
4
- data.tar.gz: dba935fa44898891607c50b377cbb4d8636300c7285592838826331cc47d5da6
3
+ metadata.gz: 79806b260b17bc4842100c7802cad04174a30f9f36c2f7f7e4f42458d4b4e414
4
+ data.tar.gz: a4d1260efdb7987a6bacb036ae71165612a55c474e72b73ea0c8877ea2c93d02
5
5
  SHA512:
6
- metadata.gz: 548dd80c8000de996d2abe85c4e158b979e9c809957f1403f15519280ee2dcb3c1fa865bf4355bc6fa25d9a6cf19791bc09cf3d6d0a84b7c0a7888cdd4960c21
7
- data.tar.gz: 6dbc07299dcc22c84643250fd8fe018dc2b8c94de6a30fe303431d61f38438ffa32c897f43132a49d4fa9d75491ceb33cf11e988c9c2a88e21406a7dd33e6abc
6
+ metadata.gz: 2663ec6e12e101bb279ba701ee6d20f84b989f679191dfa6685f74dda2141d85ceeecbc94eb063ebf7fd3cfc503872bed303146b18c8538ce0ea3866e5adcf32
7
+ data.tar.gz: f82eff08e30e02419ee52afab7975ac11c6ffcb291d8c23c2961211e26a5d10311a24d1619e1dc5aa8daa7cfc339270d35ec843baea71071942cfaad563e9f9c
data/CHANGELOG.md CHANGED
@@ -1,8 +1,30 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ### Changed
4
+
5
+ ## [0.5.0] - 2026-11-02
6
+
7
+ - `Bp3::Core::SystemLogs` writes to the Rails log at the level it was called with, instead of always at
8
+ `debug`. An exception is always written as `error`, whatever the level, and so is a message whose level
9
+ is not a logger level
10
+
11
+ ## [0.4.0] - 2026-10-30
12
+
13
+ ### Security
14
+
15
+ - Tighten ransack allowlist. Add `Bp3::Core::Ransackable::Explore`, a stricter answer to ransack's allowlist
16
+ questions. Asked with `Bp3::Core::Ransackable::EXPLORE` as the `auth_object`, `Ransackable` no longer allows every
17
+ column and association: it refuses encrypted attributes, columns matching `filter_parameters`, columns
18
+ of a `json`, `jsonb`, `binary`, `tsvector`, `vector` or `halfvec` type, and what a model names in
19
+ `unexplorable_columns`, and allows only the associations a model names in `explorable_associations`.
20
+ Any other `auth_object` gets the answer it always got
21
+ - A model that must not allow plain ransack includes `Explore` alone; it answers nothing to any other
22
+ `auth_object`
23
+
3
24
  ## [0.3.0] - 2026-10-26
4
25
 
5
26
  ### Breaking
27
+
6
28
  - Scope Tenantable by the primary login
7
29
  Tenantable default scopes reach as far as the primary login, the request state's
8
30
  `current_login` (the least privileged one signed in), rather than as far as any root or admin signed
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bp3-core (0.3.0)
4
+ bp3-core (0.5.0)
5
5
  actionview (~> 8.1)
6
6
  activesupport (~> 8.1)
7
7
  bp3-request_state (~> 0.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.3)
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)
@@ -66,6 +67,7 @@ GEM
66
67
  prism (~> 1.5)
67
68
  nokogiri (1.19.4-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)
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/concern'
4
+ require 'active_support/core_ext/class/attribute'
5
+ require 'active_support/parameter_filter'
6
+
7
+ module Bp3
8
+ module Core
9
+ module Ransackable
10
+ EXPLORE = :explore
11
+
12
+ # Explore answers ransack's allowlist questions when asked with EXPLORE as the auth_object. It
13
+ # allows the columns and the ransackers, but never an encrypted attribute, a column matching
14
+ # filter_parameters, a column of a type that cannot be grouped or read as a value, or one the
15
+ # model names in unexplorable_columns; and only the associations the model names in
16
+ # explorable_associations. Ransack asks a joined model with the same auth_object, so the target
17
+ # of an allowed association is held to the same rules.
18
+ #
19
+ # Ransackable includes this. A model that must not allow plain ransack includes this alone: it
20
+ # answers nothing to any other auth_object, since defining these methods is what ransack takes
21
+ # as an allowlist.
22
+ module Explore
23
+ extend ActiveSupport::Concern
24
+
25
+ UNEXPLORABLE_TYPES = %i[json jsonb binary tsvector vector halfvec].freeze
26
+
27
+ included do
28
+ # Override in subclasses: the associations an explore filter may join through
29
+ class_attribute :explorable_associations, instance_accessor: false, default: []
30
+ # Override in subclasses: columns explore may not touch that no other rule catches
31
+ class_attribute :unexplorable_columns, instance_accessor: false, default: []
32
+ end
33
+
34
+ class_methods do
35
+ def ransackable_attributes(auth_object = nil)
36
+ return [] unless auth_object == EXPLORE
37
+
38
+ exceptions = Ransackable.attribute_exceptions.map(&:to_s)
39
+ column_names.map(&:to_s) + _ransackers.keys - exceptions - unexplorable_attributes
40
+ end
41
+
42
+ def ransackable_associations(auth_object = nil)
43
+ return [] unless auth_object == EXPLORE
44
+
45
+ reflect_on_all_associations.map { |reflection| reflection.name.to_s } & explorable_associations.map(&:to_s)
46
+ end
47
+
48
+ def unexplorable_attributes
49
+ filter = ActiveSupport::ParameterFilter.new(Ransackable.filter_parameters + filter_attributes)
50
+ names = column_names.map(&:to_s)
51
+ filtered = names.reject { |name| filter.filter(name => name)[name] == name }
52
+ typed = columns.select { |column| UNEXPLORABLE_TYPES.include?(column.type) }.map(&:name)
53
+ encrypted_attributes.to_a.map(&:to_s) + filtered + typed + unexplorable_columns.map(&:to_s)
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -1,14 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'ransackable/explore'
4
+
3
5
  module Bp3
4
- # Bp3::Ransackable provides class methods expected by models that use ransack
6
+ # Bp3::Ransackable provides class methods expected by models that use ransack. It allows every column
7
+ # and association, except when asked with EXPLORE as the auth_object: Explore answers that.
5
8
  module Core
6
9
  module Ransackable
7
10
  extend ActiveSupport::Concern
8
11
 
12
+ include Explore
13
+
9
14
  mattr_accessor :attribute_exceptions, default: []
10
15
  mattr_accessor :association_exceptions, default: []
11
16
 
17
+ def self.filter_parameters
18
+ defined?(Rails) ? Rails.application.config.filter_parameters : []
19
+ end
20
+
12
21
  class_methods do
13
22
  def ransackable_fields(auth_object = nil)
14
23
  fields =
@@ -18,12 +27,16 @@ module Bp3
18
27
  fields.map(&:to_sym).uniq
19
28
  end
20
29
 
21
- def ransackable_attributes(_auth_object = nil)
30
+ def ransackable_attributes(auth_object = nil)
31
+ return super if auth_object == EXPLORE
32
+
22
33
  except = attribute_exceptions.map(&:to_s)
23
34
  column_names.map(&:to_s) - except
24
35
  end
25
36
 
26
- def ransackable_associations(_auth_object = nil)
37
+ def ransackable_associations(auth_object = nil)
38
+ return super if auth_object == EXPLORE
39
+
27
40
  except = association_exceptions.map(&:to_s)
28
41
  reflect_on_all_associations.map(&:name).map(&:to_s) - except
29
42
  end
@@ -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.debug do
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
- rails_logger.debug { "SystemLogs, #{level}, #{key}, #{message}" } if system_log_options[:log_to_io]
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
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Bp3
4
4
  module Core
5
- VERSION = '0.3.0'
5
+ VERSION = '0.5.0'
6
6
  end
7
7
  end
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.3.0
4
+ version: 0.5.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
@@ -146,6 +145,7 @@ files:
146
145
  - lib/bp3/core/displayable.rb
147
146
  - lib/bp3/core/feature_flags.rb
148
147
  - lib/bp3/core/ransackable.rb
148
+ - lib/bp3/core/ransackable/explore.rb
149
149
  - lib/bp3/core/rqid.rb
150
150
  - lib/bp3/core/settings.rb
151
151
  - lib/bp3/core/sqnr.rb
@@ -177,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
177
  - !ruby/object:Gem::Version
178
178
  version: '0'
179
179
  requirements: []
180
- rubygems_version: 4.0.4
180
+ rubygems_version: 4.0.23
181
181
  specification_version: 4
182
182
  summary: bp3-core provides core concerns for BP3 (persuavis/black_phoebe_3).
183
183
  test_files: []
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- ruby-3.4.6