jpie 4.1.11.pre.202611230311 → 4.2.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: 93ba5c9dc7c7fe7ddb0316d8845a715a48b7e5980306c99d9c7dff64e10f1907
4
- data.tar.gz: c82d2586cc0d85c5601cb6df5a4f96df0f51d423d974979864bdae1f3c5e35cf
3
+ metadata.gz: a2c905bb8a16dd6c75c41cb25219cff95625bbce95df01c061a26ab22e82fda5
4
+ data.tar.gz: 4f78eaa61f0690aae23a7a45d2038f7c4d039112c30d671111f251fb07e66736
5
5
  SHA512:
6
- metadata.gz: 7bf71ac957ebca8dea66977c763f133725581c2e1fb09ac1016763fc1e918090e5fd5aefcad6fac755036062e34049a2096104fb493f9527582d13a50a9440c4
7
- data.tar.gz: cddb14cb4da52248ede921af7709483e313ca2d5ddc33ca8636334dfb4fb1c3d177c25c69c80e63cfcd7f96a6af880a84e815a18a8fae45003390e07aab845c8
6
+ metadata.gz: 7d4684d2714737a79ba4204638172cfc09cc2b2809562dde0966a3f4c6627c593350dfeb4fd123a79caf3abe8d8e450e3c5b1e2ff258a7458cca576a0e6576ca
7
+ data.tar.gz: 9e6552a9d3acc2c4c8ece83d01587fb93712bb980683b12cd061fbf5e8ff4510c84f11d8cb3512f49e66a9aa00964f1d1d312eb6b42eb38c8df42d478b6fc619
data/CHANGELOG.md CHANGED
@@ -7,6 +7,23 @@ at release time.
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [4.2.0] - 2026-11-24
11
+
12
+ ### Changed
13
+
14
+ - **Gate an attachment by the declared write lists, as a relationship is gated.**
15
+ A resource that declares `creatable_fields` or `updatable_fields` now refuses a
16
+ write to an ActiveStorage attachment that the list does not name. The refusal
17
+ is 403 Forbidden, the same as for an unnamed relationship. It covers:
18
+ - an attachment named under `relationships` in a POST or PATCH body;
19
+ - `DELETE /<type>/<id>/relationships/<attachment>`, which purged the file with
20
+ no check.
21
+
22
+ A resource that declares no list for the action keeps the older behavior.
23
+ **Upgrade:** add each attachment that clients write to the resource's field
24
+ lists. This changes behavior, so release it as a minor version.
25
+ Regression spec: `attachment_allowlist_spec.rb`.
26
+
10
27
  ## [4.1.10] - 2026-11-20
11
28
 
12
29
  ### Fixed
data/README.md CHANGED
@@ -176,8 +176,10 @@ adjusts the inherited list — `super - [:role]` — returns a plain array, the
176
176
  as one that states a fresh list, so jpie cannot tell the two apart. Call the DSL
177
177
  to close the list.
178
178
 
179
- The gate never runs for an ActiveStorage attachment, so a `has_one` backed by
180
- `has_one_attached` needs no entry in either list.
179
+ The gate covers an ActiveStorage attachment the same way. Name the attachment in
180
+ a declared list to let a client attach a file in a POST or PATCH body, or remove
181
+ one through `DELETE /<type>/<id>/relationships/<attachment>`. A client that
182
+ writes an attachment the action's list omits meets 403 Forbidden.
181
183
 
182
184
  ## Relationship Endpoints
183
185
 
@@ -12,6 +12,7 @@ module JSONAPI
12
12
 
13
13
  def remove_relationship(relationship_data)
14
14
  if active_storage_attachment?(@relationship_name, @resource.class)
15
+ ensure_relationship_writable!(nil)
15
16
  return remove_active_storage_relationship(relationship_data)
16
17
  end
17
18
 
@@ -96,12 +96,12 @@ module JSONAPI
96
96
  RelationshipHelpers.polymorphic_association?(@resource_class, @relationship_name)
97
97
  end
98
98
 
99
+ # The field-list gate comes first, so it covers an attachment too.
99
100
  def ensure_relationship_writable!(association)
100
- return if active_storage_writable?(association)
101
-
102
101
  unless @resource_class.relationship_field_writable?(@relationship_name, :update)
103
102
  raise JSONAPI::AuthorizationError, "Relationship '#{@relationship_name}' is not updatable"
104
103
  end
104
+ return if active_storage_writable?(association)
105
105
 
106
106
  relationship_def = find_relationship_definition
107
107
  readonly = relationship_def && (relationship_def[:options] || {})[:readonly] == true
@@ -115,12 +115,16 @@ module JSONAPI
115
115
  self.class.active_storage_attachment?(association_name, @model_class)
116
116
  end
117
117
 
118
+ # An attachment passes the same field-list gate as a relationship. It has no association
119
+ # reflection, so the readonly check after the gate does not apply to it.
118
120
  def ensure_relationship_writable!(association_name)
119
- return if active_storage_attachment?(association_name)
121
+ field_writable = @definition.relationship_field_writable?(association_name, @action)
122
+ if active_storage_attachment?(association_name)
123
+ return JSONAPI::RelationshipGuard.ensure_writable!(nil, association_name, field_writable:)
124
+ end
120
125
 
121
126
  association = @model_class.reflect_on_association(association_name.to_sym)
122
127
  readonly = relationship_options_for(association_name)[:readonly] == true
123
- field_writable = @definition.relationship_field_writable?(association_name, @action)
124
128
  JSONAPI::RelationshipGuard.ensure_writable!(association, association_name, readonly:, field_writable:)
125
129
  end
126
130
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JSONAPI
4
- VERSION = "4.1.11.pre.202611230311"
4
+ VERSION = "4.2.0"
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.11.pre.202611230311
4
+ version: 4.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emil Kampp