model_driven_api 3.13.0 → 3.13.2

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: 9fcc02687ce88ff1cc47523ddd04f9d1a7c4918d40c2f2765d59f19a1697c0dd
4
- data.tar.gz: 2eb8c0586bbbdaed24d44d5c8de670ff5339df53c7d6609eedcb8559cc49e16a
3
+ metadata.gz: c732a9df157ab49d14dabd4ce1da1644b1e60e0d85e305c5e69104b385729a11
4
+ data.tar.gz: 9b0c718f18a0bbb90cbf53ec9b80948a093533b6ec3f76429140b007a381cd30
5
5
  SHA512:
6
- metadata.gz: c48fa599733f52da66626b80067df10d3cb223c3f950a3f3e4f62afe104e50f5b93778cf228b95b89268227b811e74e3b10455fd8d8a3cff0f9d8b8d0f1caf5b
7
- data.tar.gz: bb50aa93d2b0ce0616e8128b9634b6e38e7fd066bb8fd7a0dba61429000dbf3d125b49930273ebe333126f8ee1104d922cf78eec8f4db6d946cb3f47768d8708
6
+ metadata.gz: 845cec2e92cce1b52fd4b2bb9682fdd39cd326079280461e2d4892990147012fbb00ec694999ee7c74419aba5edda2322d90cf02648075cc42771947ebc6c0b5
7
+ data.tar.gz: 91a6b504d7194a3446d5f183afcd27f436e9cacbb1510f850aed2e22eb41562d742064a095553c27b98d15245e5bc4c7a627dbb9ae0b6c58d6e0a96ec6733265
data/README.md CHANGED
@@ -461,10 +461,6 @@ simplest safe default. A model with its own `Api::ModelName` concern (or `ModelD
461
461
  freely overrides or merges on top of it via `ModelDrivenApi.smart_merge`. Only a model with no
462
462
  concern at all keeps the bare default.
463
463
 
464
- **Temporary dependency note**: this currently requires `thecore_backend_commons` from a Gemfile
465
- `git:` pin to its `release/3` branch, since the RubyGems release hasn't caught up with the
466
- registry yet — see this repo's `CLAUDE.md` for the exact commit/removal condition.
467
-
468
464
  ---
469
465
 
470
466
  ## Raw SQL endpoint
@@ -0,0 +1,28 @@
1
+ {
2
+ "ignored_warnings": [
3
+ {
4
+ "warning_type": "Remote Code Execution",
5
+ "warning_code": 24,
6
+ "fingerprint": "3a0e243d6afeb081594823f1d9102c5c6f9235211b4d2bcf3121eb57e91b65b9",
7
+ "check_name": "UnsafeReflection",
8
+ "message": "Unsafe reflection method `constantize` called on parameter value",
9
+ "file": "app/controllers/api/v2/application_controller.rb",
10
+ "line": 146,
11
+ "link": "https://brakemanscanner.org/docs/warning_types/remote_code_execution/",
12
+ "code": "\"Endpoints::#{params[:ctrl].to_s.classify}\".constantize",
13
+ "render_path": null,
14
+ "location": {
15
+ "type": "method",
16
+ "class": "Api::V2::ApplicationController",
17
+ "method": "public_custom_action?"
18
+ },
19
+ "user_input": "params[:ctrl].to_s.classify",
20
+ "confidence": "High",
21
+ "cwe_id": [
22
+ 470
23
+ ],
24
+ "note": "False positive (host Odoo #5884). The class name is always prefixed with Endpoints:: and ActiveSupport's constantize never falls back to a top-level constant (Endpoints::String raises NameError), so only an existing Endpoints::* class can be loaded; nothing is instantiated here. Guarded by the host's test/integration/api_reflection_test.rb."
25
+ }
26
+ ],
27
+ "brakeman_version": "8.1.0"
28
+ }
@@ -84,29 +84,30 @@ module AutoIncludeInstanceJson
84
84
  include AutoIncludeJson
85
85
 
86
86
  def to_json(options = nil)
87
- preload_and_sanitize!(options)
88
- super
87
+ super(preload_and_sanitize(options))
89
88
  end
90
89
 
91
90
  def as_json(options = nil)
92
- preload_and_sanitize!(options)
93
- super
91
+ super(preload_and_sanitize(options))
94
92
  end
95
93
 
96
94
  private
97
95
 
98
- def preload_and_sanitize!(options)
99
- Rails.logger.debug "AutoIncludeJson - Instance JSON preload_and_sanitize! from #{caller_locations(1,1).first.label}"
100
- return unless options.is_a?(Hash) && options[:include]
96
+ # Returns a sanitized copy of the options, never mutating them: Rails 8.1's JSON encoder hands
97
+ # as_json a frozen options hash, and the caller's hash is often a model's shared json_attrs.
98
+ def preload_and_sanitize(options)
99
+ Rails.logger.debug "AutoIncludeJson - Instance JSON preload_and_sanitize from #{caller_locations(1,1).first.label}"
100
+ return options unless options.is_a?(Hash) && options[:include]
101
101
 
102
102
  includes_hash = build_includes(options[:include])
103
103
  sanitized_includes = sanitize_includes(options[:include])
104
- options[:include] = sanitized_includes
105
104
 
106
105
  ActiveRecord::Associations::Preloader.new(
107
106
  records: [self],
108
107
  associations: includes_hash
109
108
  ).call
109
+
110
+ options.merge(include: sanitized_includes)
110
111
  end
111
112
 
112
113
  end
@@ -4,17 +4,26 @@ module Api
4
4
 
5
5
  # Resolve model from params, controller_path, or controller_name.
6
6
  # Returns nil when no class can be resolved (info/utility controllers use this path).
7
- # Raises NotFound when a class is resolved but is not an ActiveRecord model (and not TestApi).
7
+ # Raises NotFound when a class is resolved but is not a concrete ActiveRecord model (and not TestApi).
8
+ #
9
+ # The names come from the request path, so a resolved class is only ever inspected, never
10
+ # instantiated: checking a model with `.new` used to run the constructor of any class the
11
+ # path named (GET /api/v2/tempfiles created a file on the server).
8
12
  def self.resolve(params, controller_path, controller_name)
9
- model = (params[:ctrl].classify.constantize rescue
10
- params[:path].split("/").first.classify.constantize rescue
11
- controller_path.classify.constantize rescue
12
- controller_name.classify.constantize rescue
13
- nil)
14
- if model && model != TestApi
15
- raise NotFound unless (model.new.is_a?(ActiveRecord::Base) rescue false)
16
- end
13
+ model = [
14
+ params[:ctrl],
15
+ params[:path].to_s.split("/").first,
16
+ controller_path,
17
+ controller_name
18
+ ].lazy.filter_map { |name| name.to_s.classify.safe_constantize }.first
19
+ raise NotFound if model && model != TestApi && !model?(model)
20
+
17
21
  model
18
22
  end
23
+
24
+ def self.model?(klass)
25
+ klass.is_a?(Class) && klass < ActiveRecord::Base && !klass.abstract_class?
26
+ end
27
+ private_class_method :model?
19
28
  end
20
29
  end
@@ -1,3 +1,3 @@
1
1
  module ModelDrivenApi
2
- VERSION = "3.13.0".freeze
2
+ VERSION = "3.13.2".freeze
3
3
  end
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: model_driven_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.13.0
4
+ version: 3.13.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriele Tassoni
8
+ autorequire:
8
9
  bindir: bin
9
10
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
11
+ date: 2026-11-24 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: thecore_backend_commons
@@ -192,6 +193,7 @@ files:
192
193
  - app/models/endpoints/test_api.rb
193
194
  - app/models/test_api.rb
194
195
  - app/models/used_token.rb
196
+ - config/brakeman.ignore
195
197
  - config/initializers/after_initialize_for_model_driven_api.rb
196
198
  - config/initializers/auto_include_json.rb
197
199
  - config/initializers/cors_api_thecore.rb
@@ -229,6 +231,7 @@ licenses:
229
231
  - MIT
230
232
  metadata:
231
233
  allowed_push_host: https://rubygems.org
234
+ post_install_message:
232
235
  rdoc_options: []
233
236
  require_paths:
234
237
  - lib
@@ -243,7 +246,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
243
246
  - !ruby/object:Gem::Version
244
247
  version: '0'
245
248
  requirements: []
246
- rubygems_version: 3.6.9
249
+ rubygems_version: 3.5.22
250
+ signing_key:
247
251
  specification_version: 4
248
252
  summary: Convention based RoR engine which uses DB schema introspection to create
249
253
  REST APIs.