atlas_rb 1.8.3 → 1.8.4

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: d25a6bf4fdadf6bacf1de67390aeb15343547dba8384c511d8c34b62c1fb058e
4
- data.tar.gz: f002dfcb1638bd8c5c5cb668121b9a8515f85765aaab4b229770d8d7b6b3587c
3
+ metadata.gz: a319cfd0891ed913d8c08f8138d7e11cc12a3f13d79d1b41d9eab95a45e67824
4
+ data.tar.gz: a840bfac145c02f79f59b53e226d293d90a89a18466511d4b9dbb9bd90460f59
5
5
  SHA512:
6
- metadata.gz: 9b7f605825d8d4ebb6c44c93c16bc8a7f16a6ee5cb3d7a83c2cba05c7de59e9c25fc92811f35a332ff326dc929b63c057c2743ed8d5fdeb807288f49f2cb2c79
7
- data.tar.gz: 20066bd2c7f096a70d3ace6d3c36ed888d135f91e2e31dec7f7828f6eb1f0298e46e4fb0b06fe112be840846675240f6a026787f2479e8e7c73599414f3830d9
6
+ metadata.gz: ba9b973ba96cbf0f132617bafe8d0475c0bba7b3f76328fbd54adfa20175c96f97fab5e6c4a66a025ea92890d3d2d90f00616674d143a7442dc10da763052013
7
+ data.tar.gz: 0cc2ce817a804eb2925963f8aae21108bd4151e85cf437c0220574c067025a37544212dc298b2a97b197a063ac258ff8d759ee140f957e3e9ba10f7e3f6a15ce
data/.version CHANGED
@@ -1 +1 @@
1
- 1.8.3
1
+ 1.8.4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.8.4
4
+
5
+ ### Added — per-tier derivative-visibility policy (`Work.set_derivative_permissions`)
6
+
7
+ New binding for the departmental "each download rendition has its own permissions"
8
+ model: `AtlasRb::Work.set_derivative_permissions(id, policy:, …)` PATCHes a per-tier
9
+ read policy to `PATCH /works/:id/derivative_permissions`. `policy` is a map of tier
10
+ (`small` / `medium` / `large` / `service`) => array of read-group tokens (the resource
11
+ vocabulary: `"public"`, Grouper group names, `[]` = private). Whole-object replace;
12
+ omitted tiers inherit by cascade (an absent tier inherits the next lower-resolution
13
+ tier; `small` inherits the Work). Atlas enforces two invariants — a tier may not be
14
+ more visible than the Work, and visibility must narrow as resolution grows
15
+ (`service` ⊆ `large` ⊆ `medium` ⊆ `small`).
16
+
17
+ The effective per-Delegate gate surfaces on `Work.assets` entries as `gated` (must be
18
+ authorized, not linked directly) and `permission` (the effective read-group set;
19
+ `null` for guests). No `assets` change is needed — the new fields flow through the
20
+ existing polymorphic Mash. The gate is advisory: Cerberus and the IIIF auth layer
21
+ enforce it.
22
+
23
+ A `422` rejection (`tier_exceeds_resource` / `tier_ordering_violation` /
24
+ `unknown_tier`) now raises the typed `AtlasRb::DerivativePermissionsError` (with `code`
25
+ / `resource_id`) via `RaiseOnResourceError`, mirroring the re-parent / linked-member /
26
+ Compilation mappings; a `403` raises `AtlasRb::ForbiddenError`; a `409` raises
27
+ `AtlasRb::StaleResourceError`.
28
+
3
29
  ## 1.8.3
4
30
 
5
31
  ### Changed — `find` is status-aware (stops swallowing Atlas error envelopes)
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- atlas_rb (1.8.3)
4
+ atlas_rb (1.8.4)
5
5
  faraday (~> 2.7)
6
6
  faraday-follow_redirects (~> 0.3.0)
7
7
  faraday-multipart (~> 1)
@@ -169,6 +169,38 @@ module AtlasRb
169
169
  end
170
170
  end
171
171
 
172
+ # Raised when Atlas rejects a per-tier derivative-visibility policy
173
+ # (`PATCH /works/:id/derivative_permissions`) with a `422` carrying a
174
+ # machine-readable `error` discriminator — `tier_exceeds_resource` (a tier
175
+ # more visible than its Work), `tier_ordering_violation` (visibility not
176
+ # narrowing as resolution grows), or `unknown_tier`.
177
+ #
178
+ # The derivative-permissions sibling of {ReparentError} / {LinkedMemberError};
179
+ # same shape, same rationale (the binding's `["work"]` unwrap would otherwise
180
+ # discard the envelope on the 422). Atlas rejects before persisting.
181
+ #
182
+ # rescue AtlasRb::DerivativePermissionsError => e
183
+ # flash.now[:alert] = t("derivative_permissions.errors.#{e.code}", default: e.message)
184
+ #
185
+ # @note Authorization failures surface as {ForbiddenError} (HTTP 403).
186
+ class DerivativePermissionsError < Error
187
+ # @return [String, nil] the machine-readable error code from the envelope,
188
+ # suitable for keying an i18n map.
189
+ attr_reader :code
190
+
191
+ # @return [String, nil] the rejected Work's ID, from the envelope.
192
+ attr_reader :resource_id
193
+
194
+ # @param message [String] human-readable rejection description.
195
+ # @param code [String, nil] the envelope's `error` discriminator.
196
+ # @param resource_id [String, nil] the rejected Work's ID.
197
+ def initialize(message, code: nil, resource_id: nil)
198
+ super(message)
199
+ @code = code
200
+ @resource_id = resource_id
201
+ end
202
+ end
203
+
172
204
  # Raised when Atlas refuses a re-parent, linked-member, or Compilation
173
205
  # request with an HTTP `403`, whose envelope is
174
206
  # `{ "error", "action", "subject" }`. Lets callers distinguish "you may
@@ -16,8 +16,9 @@ module AtlasRb
16
16
  #
17
17
  # It is intentionally narrow — it only fires on the re-parent
18
18
  # (`.../parent`) and linked-member (`.../linked_members...`) write paths,
19
- # the Compilation surface (`/compilations...`), and binary uploads
20
- # (`/files...`, `/file_sets...`), and only on `403` / `422` bodies carrying
19
+ # the Compilation surface (`/compilations...`), the derivative-permissions
20
+ # write (`.../derivative_permissions`), and binary uploads (`/files...`,
21
+ # `/file_sets...`), and only on `403` / `422` bodies carrying
21
22
  # an `error` discriminator. The upload branch is further gated on a fixity
22
23
  # discriminator ({FIXITY_CODES}), so a `422` on those paths with any other
23
24
  # `error` (or `403`s on uploads, which stay raw) passes through untouched.
@@ -27,10 +28,11 @@ module AtlasRb
27
28
  # translates only the wire signals callers genuinely need to discriminate.
28
29
  #
29
30
  # Mapping:
30
- # - `403` on a re-parent/linked/Compilation path → {AtlasRb::ForbiddenError}
31
+ # - `403` on a re-parent/linked/Compilation/derivative-permissions path → {AtlasRb::ForbiddenError}
31
32
  # - `422` on `.../parent` → {AtlasRb::ReparentError} (`error`/`resource_id`)
32
33
  # - `422` on `.../linked_members...` → {AtlasRb::LinkedMemberError}
33
34
  # - `422` on `/compilations...` → {AtlasRb::CompilationError}
35
+ # - `422` on `.../derivative_permissions` → {AtlasRb::DerivativePermissionsError}
34
36
  # - `422` + a fixity discriminator on `/files...` / `/file_sets...` →
35
37
  # {AtlasRb::FixityMismatchError}
36
38
  class RaiseOnResourceError < Faraday::Middleware
@@ -43,6 +45,7 @@ module AtlasRb
43
45
  # @raise [AtlasRb::ReparentError] on a 422 to a re-parent path.
44
46
  # @raise [AtlasRb::LinkedMemberError] on a 422 to a linked-member path.
45
47
  # @raise [AtlasRb::CompilationError] on a 422 to a Compilation path.
48
+ # @raise [AtlasRb::DerivativePermissionsError] on a 422 to a derivative-permissions path.
46
49
  # @raise [AtlasRb::FixityMismatchError] on a 422 + fixity discriminator to an upload path.
47
50
  # @return [void]
48
51
  def on_complete(env)
@@ -52,15 +55,16 @@ module AtlasRb
52
55
  reparent = path.end_with?("/parent")
53
56
  linked = path.include?("/linked_members")
54
57
  compilation = path.start_with?("/compilations")
58
+ deriv_perms = path.end_with?("/derivative_permissions")
55
59
  upload = path.start_with?("/files") || path.start_with?("/file_sets")
56
- return unless reparent || linked || compilation || upload
60
+ return unless reparent || linked || compilation || deriv_perms || upload
57
61
 
58
62
  body = parse_json(env.body)
59
63
  return unless body.is_a?(Hash) && body["error"]
60
64
 
61
65
  if env.status == 403
62
66
  # 403s on upload paths stay raw — acting-as/authz isn't an upload concern here.
63
- return unless reparent || linked || compilation
67
+ return unless reparent || linked || compilation || deriv_perms
64
68
 
65
69
  raise AtlasRb::ForbiddenError.new(
66
70
  body["message"] || "Atlas refused the request",
@@ -86,6 +90,12 @@ module AtlasRb
86
90
  code: body["error"],
87
91
  resource_id: body["resource_id"]
88
92
  )
93
+ elsif deriv_perms
94
+ raise AtlasRb::DerivativePermissionsError.new(
95
+ body["message"] || "Atlas rejected the derivative-permissions policy",
96
+ code: body["error"],
97
+ resource_id: body["resource_id"]
98
+ )
89
99
  elsif FIXITY_CODES.include?(body["error"])
90
100
  raise AtlasRb::FixityMismatchError.new(
91
101
  body["message"] || "Atlas rejected the upload (fixity)",
data/lib/atlas_rb/work.rb CHANGED
@@ -345,6 +345,53 @@ module AtlasRb
345
345
  ))
346
346
  end
347
347
 
348
+ # Replace a Work's per-tier derivative-visibility policy.
349
+ #
350
+ # Sets which read groups may fetch the Work's sized image derivatives —
351
+ # the `small` / `medium` / `large` / `service` (deep-zoom) tiers — reusing
352
+ # the resource read-group vocabulary (`"public"`, Grouper group names,
353
+ # `[]` = private). Unlike {.set_image_derivatives} (which upserts URIs) this
354
+ # is a whole-object REPLACE: the map you pass is the complete policy;
355
+ # omitted tiers inherit by cascade (an absent tier inherits the next
356
+ # lower-resolution tier; `small` inherits the Work's own visibility). Pass a
357
+ # tier as `[]` to make it private.
358
+ #
359
+ # Atlas enforces two invariants: a tier may not be more visible than the
360
+ # Work, and visibility must narrow as resolution grows
361
+ # (`service` ⊆ `large` ⊆ `medium` ⊆ `small`). The gate is advisory — it
362
+ # surfaces per Delegate on {.assets} as `gated` / `permission` for the
363
+ # display layer (Cerberus / the IIIF auth service) to enforce.
364
+ #
365
+ # @param id [String] the Work ID.
366
+ # @param policy [Hash] tier => Array(read groups), e.g.
367
+ # `{ large: ["northeastern:drs:repository:archives"], service: [...] }`.
368
+ # Keys may be strings or symbols; only `small` / `medium` / `large` /
369
+ # `service` are recognized.
370
+ # @param nuid [String, nil] optional acting user's NUID. On the relay-signing
371
+ # path it is signed into the assertion `sub`; on the BYO-JWT (`ATLAS_JWT`)
372
+ # path it is ignored (identity lives in the token).
373
+ # @param on_behalf_of [String, nil] optional On-Behalf-Of NUID.
374
+ # @return [AtlasRb::Mash] the updated Work; the stored map echoes back under
375
+ # `derivative_permissions`.
376
+ # @raise [AtlasRb::DerivativePermissionsError] if Atlas rejects the policy
377
+ # (422) — `tier_exceeds_resource` / `tier_ordering_violation` /
378
+ # `unknown_tier` (see {#code}).
379
+ # @raise [AtlasRb::StaleResourceError] on an optimistic-lock conflict (409).
380
+ #
381
+ # @example
382
+ # AtlasRb::Work.set_derivative_permissions(
383
+ # "w-789",
384
+ # policy: { small: ["public"],
385
+ # large: ["northeastern:drs:repository:archives"],
386
+ # service: ["northeastern:drs:repository:archives"] }
387
+ # )
388
+ def self.set_derivative_permissions(id, policy:, nuid: nil, on_behalf_of: nil)
389
+ AtlasRb::Mash.new(JSON.parse(
390
+ connection({}, nuid, on_behalf_of: on_behalf_of)
391
+ .patch(ROUTE + id + '/derivative_permissions', JSON.dump(policy))&.body
392
+ ))
393
+ end
394
+
348
395
  # Store a Work's derived full-document text for search indexing.
349
396
  #
350
397
  # Purpose-specific PATCH in the same "machine-set derived metadata" family
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atlas_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.3
4
+ version: 1.8.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cliff
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-06-27 00:00:00.000000000 Z
11
+ date: 2026-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday