jpie 4.1.8 → 4.1.10

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: d42b5ce17662c2c8b8562e0948d6bba493823a9cd65e1d43ce79c2864d395a38
4
- data.tar.gz: f968fca6f255f5949a20f1e2a99f70f34f9e3e620dd6e71dad16348e136cb48f
3
+ metadata.gz: d8d3c11476bf4a2516d2e4284a6b65ebee79e077f6cf03a77b04af05cd1e8a62
4
+ data.tar.gz: 6a2ebc8fae87604a7e046419b2a29423ade4d6fcc6cfd8bf6c42eaf7f7c9f3f0
5
5
  SHA512:
6
- metadata.gz: '093d9ab5bc2c337b7a8829aa7918fc6b174d7db815ec87b14b7460dbd41cd2c44e1da755d47c569314bbd4838b3b0c53b8ef9159508599035d42e1341b392ca1'
7
- data.tar.gz: f3c12becc5f46da8061360f859d4b49e50f63ca6e3a4a2c4b720959c3969b8cb09c31c34281019f2cc5245ab9276a9bd02d7aeb954fc3325ba72fb1b49d592fa
6
+ metadata.gz: 9c67a26c087d7e291a2880b0a60b922274e4403fa95f20b4d6b4611597500c43ce2c186ffd8476925d2e9572c6db4c6e667b268fb0cb88d48707ba9838989c1d
7
+ data.tar.gz: 1cc10806f7c34d36dc64124c90ebe821f7ae50b031b293b1eede2e6162cdf274fc3b5b889ffece5cee3a6d1b9656b99cad6088b74c1b22067ef1e9b11c03c6da
data/CHANGELOG.md CHANGED
@@ -7,6 +7,26 @@ at release time.
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [4.1.10] - 2026-11-20
11
+
12
+ ### Fixed
13
+
14
+ - **Check only the targets a write body names as relationships.** 4.1.9 also
15
+ checked a foreign key that a body sent as an attribute. A resource can expose a
16
+ foreign key as a creatable attribute on purpose, and its policy then decides who
17
+ may name the target. The check now covers only a target named under
18
+ `relationships`. Regression spec: `authorization_scope_body_write_target_spec.rb`.
19
+
20
+ ## [4.1.9] - 2026-11-20
21
+
22
+ ### Fixed
23
+
24
+ - **Refuse a write body that names a hidden target.** In 4.1.8 a write body that
25
+ named a target hidden by `authorization_scope` set the key to nil. An update
26
+ then cleared the stored relationship and answered 200. The write now stops
27
+ with 400, as a relationship route does for a hidden target or a missing
28
+ target. Regression spec: `authorization_scope_body_write_target_spec.rb`.
29
+
10
30
  ## [4.1.8] - 2026-11-20
11
31
 
12
32
  ### Fixed
@@ -64,7 +64,8 @@ module JSONAPI
64
64
  target = model_class || self.model_class
65
65
  payload = data.nil? ? raw_jsonapi_data : symbolize_data(data)
66
66
  attrs = JSONAPI::Deserializer.new(payload, model_class: target, action:, definition:).to_model_attributes
67
- JSONAPI::ResourceIdentifier.withhold_hidden_targets(attrs, target, self)
67
+ named = (payload[:relationships] || {}).keys.map { it.to_s.underscore }
68
+ JSONAPI::ResourceIdentifier.reject_hidden_targets(attrs, target, self, named:)
68
69
  end
69
70
 
70
71
  def resource_url(resource)
@@ -35,20 +35,27 @@ module JSONAPI
35
35
  end
36
36
 
37
37
  # A write body assigns the raw foreign key and leaves the lookup to the model. A target the
38
- # caller's scope hides must act like a target that does not exist. So the key becomes nil, and
39
- # the model answers the same for a hidden id and a missing id.
40
- def withhold_hidden_targets(attrs, model_class, controller)
38
+ # caller's scope hides must fail like a target that does not exist, as it does on a
39
+ # relationship route. The write stops, so it never clears the stored relationship.
40
+ # `named` lists the relationships the body names. A resource can expose a foreign key as a
41
+ # creatable attribute on purpose, and its policy then decides who may name the target.
42
+ def reject_hidden_targets(attrs, model_class, controller, named:)
41
43
  return attrs unless controller && JSONAPI.configuration.authorization_scope
42
44
 
43
- model_class.reflect_on_all_associations(:belongs_to).each do |association|
44
- next if association.polymorphic?
45
+ named_associations(model_class, named).each do |association|
46
+ id = attrs[association.foreign_key.to_s]
47
+ next if id.nil? || visible_target?(association, id, controller)
45
48
 
46
- key = association.foreign_key.to_s
47
- attrs[key] = nil unless attrs[key].nil? || visible_target?(association, attrs[key], controller)
49
+ raise ArgumentError, "Related resource not found: #{association.name} with id #{id}"
48
50
  end
49
51
  attrs
50
52
  end
51
53
 
54
+ def named_associations(model_class, named)
55
+ associations = model_class.reflect_on_all_associations(:belongs_to)
56
+ associations.select { named.include?(it.name.to_s) && !it.polymorphic? }
57
+ end
58
+
52
59
  def visible_target?(association, id, controller)
53
60
  related_class = association.klass
54
61
  scope = authorized_related_scope(target_records(related_class), related_class, controller)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JSONAPI
4
- VERSION = "4.1.8"
4
+ VERSION = "4.1.10"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jpie
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.8
4
+ version: 4.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Kampp