atlas_rb 1.16.1 → 1.18.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: 03b277e8683662db4b0809d548d274bce6e5cd51c64e242f606d0f911237ffe5
4
- data.tar.gz: b010988a48817296d3e2ab24ae3ff4e5dcaa68239159e36d19cecfe826d85b64
3
+ metadata.gz: dfa719c8d880ec4ed326597fe0882537649b69b6e0e52a3df4123353c1019198
4
+ data.tar.gz: 1ffae14221914997c13572495b728dbb93cd02c81144cba4eb5ca33f64bb444a
5
5
  SHA512:
6
- metadata.gz: 6560e0da51abf54fc2f6de456814022573626b2528e0592f1539f23e29c2106c0d98978dc768cae8e5d305caf3401f83853477d75cd6409806549e87aa8b0fa5
7
- data.tar.gz: 3352534d5a2aeb187db42d36c8adf621666612023b36a65fb904b85c0aa9925430f7c897f9b67ce824969c04730b547bfc578ae4c1f3b7da8f064b815e48c4d7
6
+ metadata.gz: b4705dd193fec70bb702846a51aa08a902a772a76964873d89a11ef2963823e7b5217525a3fb2efed339596ce213f04d6aad3cd43bb8b9387c92ea246e1d4740
7
+ data.tar.gz: 3ab173992d0243e249f51dd385cb6b7507bd8478adac2abcb1077e49c04bc0dfcb2d4fc665b9e843e72b17337dd9cdf8e8709008078dc0909befd87ef5472ac1
data/.version CHANGED
@@ -1 +1 @@
1
- 1.16.1
1
+ 1.18.0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,125 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.18.0
4
+
5
+ ### Changed — the write surface is type-agnostic, and the typed writes are gone
6
+
7
+ Atlas moved every write that needs no type onto the `/resources/{id}`
8
+ sub-resource that already served its `GET`, so the gem follows. Seven methods
9
+ replace twenty-one:
10
+
11
+ | Was | Is |
12
+ |---|---|
13
+ | `Work.update` / `Collection.update` / `Community.update` | `Resource.put_mods` |
14
+ | `.metadata` ×3 | `Resource.set_permissions` |
15
+ | `.set_thumbnails` ×3 | `Resource.set_thumbnails` |
16
+ | `.reparent` ×3 | `Resource.reparent` |
17
+ | `.tombstone` ×3 | `Resource.tombstone` |
18
+ | `Admin::{Work,Collection,Community}.restore` | `Admin::Resource.restore` |
19
+ | `Admin::{Work,Collection,Community}.destroy` | `Admin::Resource.destroy` |
20
+
21
+ `AtlasRb::Admin::Work`, `::Collection` and `::Community` are **removed** —
22
+ purge and restore were all they held.
23
+
24
+ **Why not keep the typed names as delegators.** One URL now serves every type,
25
+ so `Work.set_permissions(collection_id)` would succeed: the class would name a
26
+ type it could not enforce. A method that cannot keep its own promise is worse
27
+ than no method. Note that the subclasses still *answer* the generic writes,
28
+ because they inherit them from `Resource` — that was already true of the
29
+ generic reads (`history`, `permissions`, `find_many`), and `Resource.find`
30
+ remains the call that reports a type.
31
+
32
+ **`update` and `metadata` are not carried forward under any name.** Neither
33
+ said which document it wrote: `update` was the MODS upload and `metadata` was
34
+ the ACL. `Resource.mods` and `Resource.permissions` were already taken by the
35
+ reads, so the writes take `put_mods` and `set_permissions` rather than
36
+ overloading a name by arity on the ACL surface.
37
+
38
+ ### Changed — a generic write returns the resource unwrapped
39
+
40
+ Atlas answers a write with the resource under its type key. A caller of a
41
+ type-agnostic write does not know that key, so the gem unwraps it: `put_mods`,
42
+ `set_permissions`, `set_thumbnails` and `reparent` return the resource itself.
43
+
44
+ That also settles an inconsistency the typed methods carried — `reparent`
45
+ unwrapped, `update` and `metadata` did not.
46
+
47
+ `tombstone`, `Admin::Resource.restore` and `Admin::Resource.destroy` still
48
+ return the raw `Faraday::Response`. Atlas answers a refused tombstone with
49
+ `422 has_live_children`, which is a legitimate answer the caller reads rather
50
+ than an error to raise on.
51
+
52
+ ### Changed — `Collection.set_featured` has its own path
53
+
54
+ `PATCH /collections/{id}` had a **third** payload shape beside MODS and the
55
+ ACL: the showcase `featured` flag. It is Collection-only, so it keeps its type
56
+ and moves to `PATCH /collections/{id}/featured`. The binding signature is
57
+ unchanged.
58
+
59
+ ### Kept per-type, on purpose
60
+
61
+ `create` (it must name what to create), the Work-only writes (`complete`,
62
+ `mark_incomplete`, `clear_incomplete`, `set_image_derivatives`,
63
+ `set_derivative_permissions`, `set_full_text`, the linked-member and
64
+ association pairs), `Collection.set_featured`, and every FileSet, Blob and
65
+ Compilation write. Each addresses something only its own type has.
66
+
67
+ ## 1.17.0
68
+
69
+ ### Fixed — `Resource.find` emitted a type string this namespace cannot resolve
70
+
71
+ `find` derived its `"klass"` with `String#capitalize` over Atlas's JSON key,
72
+ and `capitalize` is not the inverse of a Ruby class name once the type has two
73
+ words. Atlas answers `{"file_set": {...}}`, and `"file_set".capitalize` is
74
+ `"File_set"`. There is no `AtlasRb::File_set`.
75
+
76
+ The doc comment stated the convention as a promise — *"the resource type,
77
+ capitalized (e.g. `"Work"`)"* — and `"Work"` is the one shape where
78
+ capitalizing happens to work. Every other consumer read that as "`const_get`
79
+ this", so a FileSet NOID put a `NameError` in the caller's stack:
80
+
81
+ ```
82
+ uninitialized constant AtlasRb::File_set
83
+ ```
84
+
85
+ `find` now reports the class's own name, so a FileSet is `"FileSet"`.
86
+
87
+ **This changes one value on the wire**: `"File_set"` becomes `"FileSet"`. That
88
+ is the spelling Solr already carries as `internal_resource`, so a consumer fed
89
+ by both sources now sees one vocabulary instead of two.
90
+
91
+ ### Added — `Resource.class_for`, the supported type-string → class lookup
92
+
93
+ ```ruby
94
+ AtlasRb::Resource.class_for("file_set") # => AtlasRb::FileSet
95
+ AtlasRb::Resource.class_for("FileSet") # => AtlasRb::FileSet
96
+ AtlasRb::Resource.class_for("File_set") # => AtlasRb::FileSet
97
+ ```
98
+
99
+ Closing the loop on `find` used to mean reaching into this namespace by string
100
+ on a naming convention the gem never promised. `class_for` reads a stated,
101
+ closed set — `Resource::TYPE_MAP`, covering the eight `Resource` subclasses —
102
+ and accepts all three spellings the DRS stack produces for a type: Atlas's
103
+ wire key, Solr's `internal_resource`, and the pre-1.17.0 `"klass"` a caller
104
+ can still be holding.
105
+
106
+ The set is stated rather than derived because there is no rule to derive:
107
+ `Blob`'s `ROUTE` is `/files/`.
108
+
109
+ An unrecognized type raises `ArgumentError` — never `nil`, and never
110
+ `const_get`, which would resolve an arbitrary constant in this namespace. Same
111
+ argument `Middleware::RaiseOnReadError` settled for the read path: keep the
112
+ failure where the cause is.
113
+
114
+ ### Documented — what the generic resolver actually covers
115
+
116
+ Atlas answers `/resources/:id` for its Valkyrie-backed types only: `Work`,
117
+ `Collection`, `Community`, `FileSet`, `Blob`, `Delegate` and `Person`. A
118
+ `Compilation` is an ActiveRecord row in Atlas rather than a Valkyrie resource,
119
+ so the resolver never finds one, though `Compilation.find` does. `nil` from
120
+ `Resource.find` is therefore ambiguous: it means "no such id" **or** "that id
121
+ names a Compilation". `Resource.find`'s YARD and the README both say so now.
122
+
3
123
  ## 1.16.0
4
124
 
5
125
  ### Fixed — every read binding consults the HTTP status before it reads the body
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- atlas_rb (1.16.1)
4
+ atlas_rb (1.18.0)
5
5
  faraday (~> 2.7)
6
6
  faraday-follow_redirects (~> 0.3.0)
7
7
  faraday-multipart (~> 1)
data/README.md CHANGED
@@ -277,18 +277,18 @@ radius and the kind of authentication they need:
277
277
 
278
278
  | Namespace | What it does | Auth | Friction |
279
279
  |----------------------|------------------------------------------------------------------------------------|-----------------------------------------------------|---------------------------------------|
280
- | `AtlasRb::*` | Regular CRUD (find / list / create / update / tombstone / metadata, etc.) | Relay-signing (signed assertion, `sub` = acting NUID) | None — these are the daily-use paths. |
281
- | `AtlasRb::Admin::*` | Hard delete (`destroy`) and un-tombstone (`restore`) for Work / Collection / Community. | Same as regular — a real operator is acting. | `destroy` requires `confirm: :i_understand`. |
280
+ | `AtlasRb::*` | Regular CRUD typed reads and `create`, plus every type-agnostic write on `Resource`. | Relay-signing (signed assertion, `sub` = acting NUID) | None — these are the daily-use paths. |
281
+ | `AtlasRb::Admin::*` | Hard delete (`destroy`) and un-tombstone (`restore`), on `Admin::Resource`. | Same as regular — a real operator is acting. | `destroy` requires `confirm: :i_understand`. |
282
282
  | `AtlasRb::System::*` | System-context provisioning (currently just SSO user find-or-create). | System token (`Rails.application.credentials.atlas_system_token`) + `User: NUID 000000000`. | The namespace itself is the marker — there is no way to call these as a non-system principal. |
283
283
 
284
284
  ```ruby
285
285
  # Regular daily use — picks up Current.nuid via the configured default:
286
- AtlasRb::Work.find("w-789")
287
- AtlasRb::Work.tombstone("w-789") # withdrawal (reversible)
286
+ AtlasRb::Work.find("w-789") # typed read
287
+ AtlasRb::Resource.tombstone("w-789") # withdrawal (reversible), any type
288
288
 
289
289
  # Operator-only, with a friction marker:
290
- AtlasRb::Admin::Work.destroy("w-789", confirm: :i_understand)
291
- AtlasRb::Admin::Work.restore("w-789")
290
+ AtlasRb::Admin::Resource.destroy("w-789", confirm: :i_understand)
291
+ AtlasRb::Admin::Resource.restore("w-789")
292
292
 
293
293
  # System-only — authenticates as Atlas's :system fixture:
294
294
  AtlasRb::System::User.find_or_create(
@@ -531,6 +531,95 @@ The two mutations raise the same way `reparent` does — `LinkedMemberError`
531
531
  on a structural `422` (carrying the envelope's `error` code as `#code`) and
532
532
  `ForbiddenError` on a `403` — instead of swallowing the envelope.
533
533
 
534
+ ### Writing without knowing the type
535
+
536
+ Atlas serves the reads as sub-resources of `/resources/{id}` and serves the
537
+ writes as verbs on those same paths, so a caller holding a NOID and no type can
538
+ write. The whole surface:
539
+
540
+ | Call | Endpoint |
541
+ |---|---|
542
+ | `Resource.put_mods(id, xml_path, origin:)` | `PUT /resources/{id}/mods` |
543
+ | `Resource.set_permissions(id, acl)` | `PATCH /resources/{id}/permissions` |
544
+ | `Resource.set_thumbnails(id, thumbnail:, thumbnail_2x:, preview:)` | `PATCH /resources/{id}/thumbnails` |
545
+ | `Resource.reparent(id, parent_id)` | `PATCH /resources/{id}/parent` |
546
+ | `Resource.tombstone(id)` | `POST /resources/{id}/tombstone` |
547
+ | `Admin::Resource.restore(id)` | `POST /resources/{id}/restore` |
548
+ | `Admin::Resource.destroy(id, confirm: :i_understand)` | `DELETE /resources/{id}` |
549
+
550
+ ```ruby
551
+ AtlasRb::Resource.put_mods("xsj3xmz", "/tmp/work.xml", origin: "xml_editor")
552
+ AtlasRb::Resource.set_permissions("xsj3xmz", { "read" => ["public"] })
553
+ ```
554
+
555
+ **There are no typed counterparts.** One URL serves every type, so a typed
556
+ write would name a type it could not enforce — `Work.set_permissions` given a
557
+ Collection id would succeed. The subclasses still *answer* these methods,
558
+ because they inherit them from `Resource`, but calling one on a subclass is the
559
+ same call and checks nothing. That was already true of the generic reads;
560
+ `Resource.find` is what reports a type.
561
+
562
+ **The ACL merges per key.** A key you omit keeps its stored value, and a key
563
+ sent explicitly empty is cleared. So changing one slot no longer means reading
564
+ the whole envelope and writing it back to avoid erasing a field you never meant
565
+ to touch.
566
+
567
+ ```ruby
568
+ # publishes, and leaves the embargo, edit groups and depositor alone
569
+ AtlasRb::Resource.set_permissions(id, { "read" => ["public"] })
570
+ ```
571
+
572
+ **MODS is a PUT because the caller assembles the whole document** — descriptive
573
+ merge logic lives in the client, not in Atlas. A type that holds no MODS
574
+ answers `404`, exactly as the `GET` on that path does; the gem does not
575
+ pre-check, so Atlas stays the one enforcer.
576
+
577
+ A write returns the resource **unwrapped** from its type key, since the caller
578
+ of a type-agnostic write has no key to index by. `tombstone`, `restore` and
579
+ `destroy` return the raw `Faraday::Response`: Atlas answers a refused tombstone
580
+ with `422 has_live_children`, which is an answer to read rather than an error
581
+ to raise on.
582
+
583
+ Writes that address something only one type has stay typed — `create`, the
584
+ Work-only lifecycle and derivative writes, `Collection.set_featured`, and the
585
+ FileSet, Blob and Compilation writes.
586
+
587
+ ### Resolving one id of unknown type (`Resource.find` and `Resource.class_for`)
588
+
589
+ When a NOID arrives as runtime data and you do not know its type, resolve
590
+ it generically and dispatch on the reported type:
591
+
592
+ ```ruby
593
+ found = AtlasRb::Resource.find("b8gtjvk")
594
+ found["klass"] # => "FileSet"
595
+ klass = AtlasRb::Resource.class_for(found["klass"]) # => AtlasRb::FileSet
596
+ klass.find(found["resource"]["id"])
597
+ ```
598
+
599
+ `class_for` is the supported way to turn a type string into a class. Do not
600
+ `const_get` into the `AtlasRb` namespace: the mapping is a stated, closed
601
+ set (`Resource::TYPE_MAP`), not a naming rule — `Blob`'s route is `/files/`,
602
+ and a wire key like `file_set` is not the class name.
603
+
604
+ It accepts every spelling the DRS stack produces for a type, because a
605
+ caller cannot tell which one it is holding:
606
+
607
+ | Spelling | Where it comes from |
608
+ |---------------|--------------------------------------------|
609
+ | `"file_set"` | Atlas's JSON wire key |
610
+ | `"FileSet"` | Solr's `internal_resource`, and `find`'s `"klass"` |
611
+ | `"File_set"` | a `"klass"` read from a gem before 1.17.0 |
612
+
613
+ An unknown type raises `ArgumentError` rather than returning `nil`, so a
614
+ type this gem does not model fails where the cause is.
615
+
616
+ **What the resolver covers.** Atlas answers `/resources/:id` for its
617
+ Valkyrie-backed types only: `Work`, `Collection`, `Community`, `FileSet`,
618
+ `Blob`, `Delegate` and `Person`. A `Compilation` is an ActiveRecord row in
619
+ Atlas rather than a Valkyrie resource, so the generic resolver never finds
620
+ one — use `AtlasRb::Compilation.find` for those. That makes `nil` ambiguous
621
+ here: it means "no such id" **or** "that id names a Compilation".
622
+
534
623
  ### Batch resolve (`Resource.find_many`)
535
624
 
536
625
  When you have a *set* of NOIDs and only need each one's title / klass /
@@ -601,16 +690,16 @@ written to prevent:
601
690
 
602
691
  ```ruby
603
692
  begin
604
- AtlasRb::Work.update("doesnotexist", "/tmp/mods.xml")
693
+ AtlasRb::Resource.put_mods("doesnotexist", "/tmp/mods.xml")
605
694
  rescue AtlasRb::NotFoundError => e
606
695
  e.status # => 404
607
- e.message # => "PATCH /works/doesnotexist → 404 (no such resource)"
696
+ e.message # => "PUT /resources/doesnotexist/mods → 404 (no such resource)"
608
697
  end
609
698
  ```
610
699
 
611
- This covers every `create` / `update` / `metadata` / `parent` / `rollback` and
612
- their siblings on `Work`, `Collection`, `Community`, `Blob`, `FileSet`,
613
- `Compilation` and `Person`. Any other non-2xx a write gets raises
700
+ This covers every write: `create` and the type-specific writes on `Work`,
701
+ `Collection`, `Blob`, `FileSet`, `Compilation` and `Person`, and the
702
+ type-agnostic ones on `Resource`. Any other non-2xx a write gets raises
614
703
  `AtlasRb::ResourceError`, which `NotFoundError` subclasses — so a caller that
615
704
  only wants "the write failed" rescues the parent.
616
705
 
@@ -632,7 +721,7 @@ Refused writes raise on **every** binding and **every** path:
632
721
 
633
722
  ```ruby
634
723
  begin
635
- AtlasRb::Work.update("w-789", metadata)
724
+ AtlasRb::Resource.set_permissions("w-789", { "read" => ["public"] })
636
725
  rescue AtlasRb::ReadOnlyModeError => e
637
726
  e.retry_after # => 900 (seconds, from Atlas's Retry-After header)
638
727
  e.message # => "Atlas is in maintenance mode; writes are refused"
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AtlasRb
4
+ module Admin
5
+ # Destructive lifecycle operations that need no type, against Atlas's
6
+ # generic `/resources/{id}` surface.
7
+ #
8
+ # The typed {AtlasRb::Admin::Work}, {AtlasRb::Admin::Collection} and
9
+ # {AtlasRb::Admin::Community} delegate here. See {AtlasRb::Admin} for why
10
+ # the namespace exists and what `confirm: :i_understand` is for — both
11
+ # apply unchanged, which is why purge did not move onto
12
+ # {AtlasRb::Resource} beside the other generic writes.
13
+ class Resource
14
+ extend AtlasRb::FaradayHelper
15
+
16
+ # Atlas REST endpoint prefix.
17
+ # @api private
18
+ ROUTE = "/resources/"
19
+
20
+ # Hard-delete a resource — a purge, not a withdrawal.
21
+ #
22
+ # Removes the resource's metadata, cascades into its members, and removes
23
+ # the OCFL objects holding the preserved bytes: every retained revision,
24
+ # not only the current one. Nothing survives but the audit row, which
25
+ # records the NOIDs it removed.
26
+ #
27
+ # Unrecoverable — prefer {AtlasRb::Resource.tombstone} for the
28
+ # user-visible withdrawal path, which keeps everything and can be
29
+ # reversed. Admin-only.
30
+ #
31
+ # @param id [String] the resource's NOID.
32
+ # @param confirm [Symbol] must be `:i_understand`.
33
+ # @param nuid [String, nil] optional acting user's NUID.
34
+ # @param on_behalf_of [String, nil] optional NUID for the `On-Behalf-Of`
35
+ # header.
36
+ # @return [Faraday::Response] the raw delete response.
37
+ # @raise [ArgumentError] if `confirm:` is missing or not the sentinel
38
+ # value. Raised before any request goes out.
39
+ #
40
+ # @example
41
+ # AtlasRb::Admin::Resource.destroy("xsj3xmz", confirm: :i_understand)
42
+ def self.destroy(id, confirm:, nuid: nil, on_behalf_of: nil)
43
+ unless confirm == :i_understand
44
+ raise ArgumentError,
45
+ "AtlasRb::Admin::Resource.destroy requires confirm: :i_understand"
46
+ end
47
+ connection({}, nuid, on_behalf_of: on_behalf_of).delete(ROUTE + id)
48
+ end
49
+
50
+ # Restore a previously-tombstoned resource.
51
+ #
52
+ # Reverses a withdrawal: search and show pages stop returning a withdrawn
53
+ # stub. No `confirm:` marker — restoring is itself reversible, by
54
+ # tombstoning again.
55
+ #
56
+ # @param id [String] the resource's NOID.
57
+ # @param nuid [String, nil] optional acting user's NUID.
58
+ # @param on_behalf_of [String, nil] optional NUID for the `On-Behalf-Of`
59
+ # header.
60
+ # @return [Faraday::Response] the raw response.
61
+ #
62
+ # @example
63
+ # AtlasRb::Admin::Resource.restore("xsj3xmz")
64
+ def self.restore(id, nuid: nil, on_behalf_of: nil)
65
+ connection({}, nuid, on_behalf_of: on_behalf_of).post(ROUTE + id + '/restore')
66
+ end
67
+ end
68
+ end
69
+ end
@@ -10,10 +10,11 @@ module AtlasRb
10
10
  #
11
11
  # ## Why a separate namespace
12
12
  #
13
- # The class itself is the marker: `AtlasRb::Admin::Work.destroy(...)`
14
- # is structurally distinct from `AtlasRb::Work.update(...)`. Mass-edits
15
- # and code-search across a consumer codebase can quickly find every
16
- # destructive call site by grepping `AtlasRb::Admin::`.
13
+ # The namespace itself is the marker: `AtlasRb::Admin::Resource.destroy(...)`
14
+ # is structurally distinct from every other write. Mass-edits and code-search
15
+ # across a consumer codebase can find every destructive call site by grepping
16
+ # `AtlasRb::Admin::`. That is also why purge did not move onto
17
+ # {AtlasRb::Resource} beside the other type-agnostic writes.
17
18
  #
18
19
  # ## `confirm: :i_understand`
19
20
  #
@@ -84,7 +84,9 @@ module AtlasRb
84
84
  ))["collection"]
85
85
  return result if xml_path.to_s.empty?
86
86
 
87
- update(result["id"], xml_path, nuid: nuid, on_behalf_of: on_behalf_of)
87
+ # The MODS seed is a second call: create takes the parent and the
88
+ # provenance slots, and the document goes through the write that owns it.
89
+ AtlasRb::Resource.put_mods(result["id"], xml_path, nuid: nuid, on_behalf_of: on_behalf_of)
88
90
  find(result["id"], nuid: nuid, on_behalf_of: on_behalf_of)
89
91
  end
90
92
 
@@ -109,75 +111,11 @@ module AtlasRb
109
111
  # AtlasRb::Collection.set_featured("col-456", true)
110
112
  def self.set_featured(id, featured, nuid: nil, on_behalf_of: nil)
111
113
  AtlasRb::Mash.new(write_resource(
112
- connection({ featured: featured }, nuid, on_behalf_of: on_behalf_of).patch(ROUTE + id)
114
+ connection({ featured: featured }, nuid, on_behalf_of: on_behalf_of)
115
+ .patch(ROUTE + id + '/featured')
113
116
  ))["collection"]
114
117
  end
115
118
 
116
- # Move a Collection to a different parent (Community or Collection).
117
- #
118
- # Wraps `PATCH /collections/<id>/parent` with a `parent_id` of the new
119
- # parent. Atlas re-parents the Collection and synchronously cascades
120
- # the ancestry index over its Works; the structural rules (type, cycle,
121
- # tombstone guards) are enforced server-side and surface as a `422`.
122
- #
123
- # Mirrors {.create}'s "single parent id" shape — same kwarg threading,
124
- # the only difference is the verb and that the Collection already exists.
125
- #
126
- # @param id [String] the Collection ID to move.
127
- # @param new_parent_id [String] the destination Community or Collection ID.
128
- # @param nuid [String, nil] optional acting user's NUID. On the relay-signing
129
- # path it is signed into the assertion `sub`; on the BYO-JWT (`ATLAS_JWT`)
130
- # path it is ignored (identity lives in the token).
131
- # @param on_behalf_of [String, nil] optional NUID for the `On-Behalf-Of`
132
- # header. Falls through to {AtlasRb.config}.default_on_behalf_of when
133
- # omitted.
134
- # @return [Hash] the updated `"collection"` object, already unwrapped —
135
- # the same shape {.find} returns, reflecting the new `a_member_of`.
136
- # @raise [AtlasRb::StaleResourceError] if Atlas reports an optimistic-lock
137
- # conflict that exhausted its internal retry budget (HTTP 409 with
138
- # `error: "stale_resource"`).
139
- # @raise [AtlasRb::ReparentError] if Atlas rejects the move on structural
140
- # grounds (HTTP 422 — `cycle`, `invalid_parent_type`, `tombstoned_node`,
141
- # `tombstoned_parent`, `parent_required`, `parent_not_found`). The
142
- # envelope's `error` code is exposed as `#code`.
143
- # @raise [AtlasRb::ForbiddenError] if Atlas refuses the move on
144
- # authorization grounds (HTTP 403).
145
- # @raise [AtlasRb::NotFoundError] if Atlas answers `404` — the id names no such
146
- # resource, so the write did not happen.
147
- # @raise [AtlasRb::ResourceError] on any other non-2xx, carrying Atlas's status
148
- # and body.
149
- #
150
- # @example
151
- # AtlasRb::Collection.reparent("col-456", "c-999")
152
- def self.reparent(id, new_parent_id, nuid: nil, on_behalf_of: nil)
153
- AtlasRb::Mash.new(write_resource(
154
- connection({ parent_id: new_parent_id }, nuid, on_behalf_of: on_behalf_of)
155
- .patch(ROUTE + id + '/parent')
156
- ))["collection"]
157
- end
158
-
159
- # Tombstone (withdraw) a Collection.
160
- #
161
- # The Collection remains in Atlas storage but is marked as withdrawn:
162
- # search and show pages return a withdrawn stub for every user. Atlas
163
- # rejects the request with `422 has_live_children` if the Collection
164
- # still has live (non-tombstoned) Works.
165
- #
166
- # @param id [String] the Collection ID.
167
- # @param nuid [String] the acting user's NUID, stamped on the resource
168
- # as `tombstoned_by` for audit purposes.
169
- # @param on_behalf_of [String, nil] optional NUID for the `On-Behalf-Of`
170
- # header. Falls through to {AtlasRb.config}.default_on_behalf_of when
171
- # omitted.
172
- # @return [Faraday::Response] the raw response. `200`/`204` on success;
173
- # `422` with `{"code":"has_live_children"}` if the Collection is not empty.
174
- #
175
- # @example
176
- # AtlasRb::Collection.tombstone("col-456", nuid: "000000002")
177
- def self.tombstone(id, nuid: nil, on_behalf_of: nil)
178
- connection({}, nuid, on_behalf_of: on_behalf_of).post(ROUTE + id + '/tombstone')
179
- end
180
-
181
119
  # List the Works in a Collection.
182
120
  #
183
121
  # The endpoint returns just the noids; resolve each through
@@ -210,104 +148,6 @@ module AtlasRb
210
148
  read_body(connection({}, nuid, on_behalf_of: on_behalf_of).get(ROUTE + id + '/children'))
211
149
  end
212
150
 
213
- # Replace a Collection's metadata by uploading a MODS XML document.
214
- #
215
- # @param id [String] the Collection ID.
216
- # @param xml_path [String] path to a MODS XML file on disk.
217
- # @param nuid [String, nil] optional acting user's NUID. On the relay-signing
218
- # path it is signed into the assertion `sub`; on the BYO-JWT (`ATLAS_JWT`)
219
- # path it is ignored (identity lives in the token).
220
- # @param on_behalf_of [String, nil] optional NUID for the `On-Behalf-Of`
221
- # header. Falls through to {AtlasRb.config}.default_on_behalf_of when
222
- # omitted.
223
- # @param origin [String, nil] free-text tag naming the surface that made this
224
- # edit (e.g. `"metadata_form"`, `"xml_editor"`). Atlas records it verbatim
225
- # on the audit event; omit it and the event carries no origin.
226
- # @return [Hash] the parsed JSON response from the patch.
227
- # @raise [AtlasRb::NotFoundError] if Atlas answers `404` — the id names no such
228
- # resource, so the write did not happen.
229
- # @raise [AtlasRb::ResourceError] on any other non-2xx, carrying Atlas's status
230
- # and body.
231
- #
232
- # @example
233
- # AtlasRb::Collection.update("col-456", "/tmp/collection-mods.xml")
234
- #
235
- # @example Recording which editing surface made the change
236
- # AtlasRb::Collection.update("col-456", "/tmp/collection-mods.xml", origin: "xml_editor")
237
- def self.update(id, xml_path, nuid: nil, on_behalf_of: nil, origin: nil)
238
- AtlasRb::Mash.new(write_resource(
239
- multipart(nuid, on_behalf_of: on_behalf_of)
240
- .patch(ROUTE + id, mods_upload_payload(xml_path, origin))
241
- ))
242
- end
243
-
244
- # Patch individual descriptive-metadata fields without uploading a
245
- # full MODS document.
246
- #
247
- # Scoped to user-authored descriptive metadata only. Programmatic
248
- # writes of machine-set Delegate URIs (thumbnails) have their own
249
- # purpose-specific endpoint — see {.set_thumbnails}.
250
- #
251
- # @param id [String] the Collection ID.
252
- # @param values [Hash] field-level metadata updates.
253
- # @param nuid [String, nil] optional acting user's NUID. On the relay-signing
254
- # path it is signed into the assertion `sub`; on the BYO-JWT (`ATLAS_JWT`)
255
- # path it is ignored (identity lives in the token).
256
- # @param on_behalf_of [String, nil] optional NUID for the `On-Behalf-Of`
257
- # header. Falls through to {AtlasRb.config}.default_on_behalf_of when
258
- # omitted.
259
- # @return [Hash] the parsed JSON response.
260
- # @raise [AtlasRb::NotFoundError] if Atlas answers `404` — the id names no such
261
- # resource, so the write did not happen.
262
- # @raise [AtlasRb::ResourceError] on any other non-2xx, carrying Atlas's status
263
- # and body.
264
- #
265
- # @example
266
- # AtlasRb::Collection.metadata("col-456", title: "Renamed Collection")
267
- def self.metadata(id, values, nuid: nil, on_behalf_of: nil)
268
- AtlasRb::Mash.new(write_resource(
269
- connection({ metadata: values }, nuid, on_behalf_of: on_behalf_of).patch(ROUTE + id)
270
- ))
271
- end
272
-
273
- # Attach the three thumbnail/preview Delegate URIs to a Collection.
274
- #
275
- # Collection-level mirror of {Work.set_thumbnails}. Atlas dispatches
276
- # each non-blank URI to its matching Delegate role
277
- # (`thumbnail_image` / `thumbnail_image_2x` / `preview_image`) via
278
- # `DelegateUpdater`. Missing keys are left untouched.
279
- #
280
- # @param id [String] the Collection ID.
281
- # @param thumbnail [String, nil] IIIF URI for the ~85² thumbnail.
282
- # @param thumbnail_2x [String, nil] IIIF URI for the ~170² 2x thumbnail.
283
- # @param preview [String, nil] IIIF URI for the ~500w preview image.
284
- # @param nuid [String, nil] optional acting user's NUID. On the relay-signing
285
- # path it is signed into the assertion `sub`; on the BYO-JWT (`ATLAS_JWT`)
286
- # path it is ignored (identity lives in the token).
287
- # @return [AtlasRb::Mash] the parsed JSON response.
288
- # @raise [AtlasRb::StaleResourceError] if Atlas reports an optimistic-lock
289
- # conflict that exhausted its internal retry budget (HTTP 409 with
290
- # `error: "stale_resource"`).
291
- # @raise [AtlasRb::NotFoundError] if Atlas answers `404` — the id names no such
292
- # resource, so the write did not happen.
293
- # @raise [AtlasRb::ResourceError] on any other non-2xx, carrying Atlas's status
294
- # and body.
295
- #
296
- # @example
297
- # AtlasRb::Collection.set_thumbnails(
298
- # "col-456",
299
- # thumbnail: "https://iiif.example.edu/iiif/3/c.jp2/full/!85,85/0/default.jpg",
300
- # thumbnail_2x: "https://iiif.example.edu/iiif/3/c.jp2/full/!170,170/0/default.jpg",
301
- # preview: "https://iiif.example.edu/iiif/3/c.jp2/full/500,/0/default.jpg"
302
- # )
303
- def self.set_thumbnails(id, thumbnail: nil, thumbnail_2x: nil, preview: nil, nuid: nil, on_behalf_of: nil)
304
- body = { thumbnail: thumbnail, thumbnail_2x: thumbnail_2x, preview: preview }.compact
305
- AtlasRb::Mash.new(write_resource(
306
- connection({}, nuid, on_behalf_of: on_behalf_of)
307
- .patch(ROUTE + id + '/thumbnails', JSON.dump(body))
308
- ))
309
- end
310
-
311
151
  # Fetch the Collection's MODS representation in the requested format.
312
152
  #
313
153
  # @param id [String] the Collection ID.