atlas_rb 1.17.0 → 1.19.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 +4 -4
- data/.version +1 -1
- data/CHANGELOG.md +88 -0
- data/Gemfile.lock +2 -2
- data/README.md +90 -12
- data/lib/atlas_rb/admin/resource.rb +69 -0
- data/lib/atlas_rb/admin.rb +5 -4
- data/lib/atlas_rb/collection.rb +5 -165
- data/lib/atlas_rb/community.rb +3 -170
- data/lib/atlas_rb/resource.rb +49 -0
- data/lib/atlas_rb/resource_writes.rb +160 -0
- data/lib/atlas_rb/work.rb +3 -171
- data/lib/atlas_rb.rb +3 -3
- metadata +4 -5
- data/lib/atlas_rb/admin/collection.rb +0 -62
- data/lib/atlas_rb/admin/community.rb +0 -62
- data/lib/atlas_rb/admin/work.rb +0 -71
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 528d764830f8e3a3fdaf376983d4ce3babe6ef0a19f5b1e2fe02fbceb0584bd0
|
|
4
|
+
data.tar.gz: 2d80d25327e3e43f389a0f71e84c2a880f5bc89905989ff22c16aabee90261c4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 881ea22bc257423cbbeb748d26bc011371d5d9112be6e72106a60799215d59ce636ef566210a7b5cb93090d075f450f910f15a1040f321910869f358a01bb8cf
|
|
7
|
+
data.tar.gz: 97203339683115160ec8ef78e375f639d76d38716f2d29f190b2c80b01505f8eda85081e6d487510de0fc65308ae00afba7dbc18e956da16476a2bc3b6bc931b
|
data/.version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.
|
|
1
|
+
1.19.0
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,93 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.19.0
|
|
4
|
+
|
|
5
|
+
### Added — `Resource.search`, the catalog keyword search
|
|
6
|
+
|
|
7
|
+
```ruby
|
|
8
|
+
AtlasRb::Resource.search("whaling logbook", type: "Work", page: 1, per_page: 25)
|
|
9
|
+
# => Mash with "results" and "pagination"
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Binds `GET /resources/search`, which needs Atlas 0.6.199 or later. It is
|
|
13
|
+
Cerberus's search bar for a caller without Blacklight: the same field weights,
|
|
14
|
+
because both come from the Solr core's search handler, and the same filters for
|
|
15
|
+
the global catalog. It returns the whole envelope, as `descendant_works` does, so
|
|
16
|
+
a caller pages with `pagination.pages`.
|
|
17
|
+
|
|
18
|
+
Each row is a Solr digest, and `klass` is a name `Resource.class_for` accepts, so
|
|
19
|
+
loading the full resource is `class_for(hit.klass).find(hit.noid)`.
|
|
20
|
+
|
|
21
|
+
One difference from Cerberus is deliberate. Atlas gates the rows as its own
|
|
22
|
+
`Ability` reads a resource, so an edit group and the depositor count as well as a
|
|
23
|
+
read group. Cerberus's search still checks read groups only, so for staff and
|
|
24
|
+
depositors this can return items that Cerberus's search does not. Every such item
|
|
25
|
+
is one the user can already open.
|
|
26
|
+
|
|
27
|
+
## 1.18.0
|
|
28
|
+
|
|
29
|
+
### Changed — the write surface is type-agnostic, and the typed writes are gone
|
|
30
|
+
|
|
31
|
+
Atlas moved every write that needs no type onto the `/resources/{id}`
|
|
32
|
+
sub-resource that already served its `GET`, so the gem follows. Seven methods
|
|
33
|
+
replace twenty-one:
|
|
34
|
+
|
|
35
|
+
| Was | Is |
|
|
36
|
+
|---|---|
|
|
37
|
+
| `Work.update` / `Collection.update` / `Community.update` | `Resource.put_mods` |
|
|
38
|
+
| `.metadata` ×3 | `Resource.set_permissions` |
|
|
39
|
+
| `.set_thumbnails` ×3 | `Resource.set_thumbnails` |
|
|
40
|
+
| `.reparent` ×3 | `Resource.reparent` |
|
|
41
|
+
| `.tombstone` ×3 | `Resource.tombstone` |
|
|
42
|
+
| `Admin::{Work,Collection,Community}.restore` | `Admin::Resource.restore` |
|
|
43
|
+
| `Admin::{Work,Collection,Community}.destroy` | `Admin::Resource.destroy` |
|
|
44
|
+
|
|
45
|
+
`AtlasRb::Admin::Work`, `::Collection` and `::Community` are **removed** —
|
|
46
|
+
purge and restore were all they held.
|
|
47
|
+
|
|
48
|
+
**Why not keep the typed names as delegators.** One URL now serves every type,
|
|
49
|
+
so `Work.set_permissions(collection_id)` would succeed: the class would name a
|
|
50
|
+
type it could not enforce. A method that cannot keep its own promise is worse
|
|
51
|
+
than no method. Note that the subclasses still *answer* the generic writes,
|
|
52
|
+
because they inherit them from `Resource` — that was already true of the
|
|
53
|
+
generic reads (`history`, `permissions`, `find_many`), and `Resource.find`
|
|
54
|
+
remains the call that reports a type.
|
|
55
|
+
|
|
56
|
+
**`update` and `metadata` are not carried forward under any name.** Neither
|
|
57
|
+
said which document it wrote: `update` was the MODS upload and `metadata` was
|
|
58
|
+
the ACL. `Resource.mods` and `Resource.permissions` were already taken by the
|
|
59
|
+
reads, so the writes take `put_mods` and `set_permissions` rather than
|
|
60
|
+
overloading a name by arity on the ACL surface.
|
|
61
|
+
|
|
62
|
+
### Changed — a generic write returns the resource unwrapped
|
|
63
|
+
|
|
64
|
+
Atlas answers a write with the resource under its type key. A caller of a
|
|
65
|
+
type-agnostic write does not know that key, so the gem unwraps it: `put_mods`,
|
|
66
|
+
`set_permissions`, `set_thumbnails` and `reparent` return the resource itself.
|
|
67
|
+
|
|
68
|
+
That also settles an inconsistency the typed methods carried — `reparent`
|
|
69
|
+
unwrapped, `update` and `metadata` did not.
|
|
70
|
+
|
|
71
|
+
`tombstone`, `Admin::Resource.restore` and `Admin::Resource.destroy` still
|
|
72
|
+
return the raw `Faraday::Response`. Atlas answers a refused tombstone with
|
|
73
|
+
`422 has_live_children`, which is a legitimate answer the caller reads rather
|
|
74
|
+
than an error to raise on.
|
|
75
|
+
|
|
76
|
+
### Changed — `Collection.set_featured` has its own path
|
|
77
|
+
|
|
78
|
+
`PATCH /collections/{id}` had a **third** payload shape beside MODS and the
|
|
79
|
+
ACL: the showcase `featured` flag. It is Collection-only, so it keeps its type
|
|
80
|
+
and moves to `PATCH /collections/{id}/featured`. The binding signature is
|
|
81
|
+
unchanged.
|
|
82
|
+
|
|
83
|
+
### Kept per-type, on purpose
|
|
84
|
+
|
|
85
|
+
`create` (it must name what to create), the Work-only writes (`complete`,
|
|
86
|
+
`mark_incomplete`, `clear_incomplete`, `set_image_derivatives`,
|
|
87
|
+
`set_derivative_permissions`, `set_full_text`, the linked-member and
|
|
88
|
+
association pairs), `Collection.set_featured`, and every FileSet, Blob and
|
|
89
|
+
Compilation write. Each addresses something only its own type has.
|
|
90
|
+
|
|
3
91
|
## 1.17.0
|
|
4
92
|
|
|
5
93
|
### Fixed — `Resource.find` emitted a type string this namespace cannot resolve
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
atlas_rb (1.
|
|
4
|
+
atlas_rb (1.19.0)
|
|
5
5
|
faraday (~> 2.7)
|
|
6
6
|
faraday-follow_redirects (~> 0.3.0)
|
|
7
7
|
faraday-multipart (~> 1)
|
|
@@ -16,7 +16,7 @@ GEM
|
|
|
16
16
|
base64 (0.3.0)
|
|
17
17
|
connection_pool (2.5.5)
|
|
18
18
|
diff-lcs (1.6.1)
|
|
19
|
-
faraday (2.14.
|
|
19
|
+
faraday (2.14.4)
|
|
20
20
|
faraday-net_http (>= 2.0, < 3.5)
|
|
21
21
|
json
|
|
22
22
|
logger
|
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
|
|
281
|
-
| `AtlasRb::Admin::*` | Hard delete (`destroy`) and un-tombstone (`restore`)
|
|
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::
|
|
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::
|
|
291
|
-
AtlasRb::Admin::
|
|
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,59 @@ 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
|
+
|
|
534
587
|
### Resolving one id of unknown type (`Resource.find` and `Resource.class_for`)
|
|
535
588
|
|
|
536
589
|
When a NOID arrives as runtime data and you do not know its type, resolve
|
|
@@ -588,6 +641,31 @@ tombstoned resources come back flagged (`"tombstoned" => true`), so index
|
|
|
588
641
|
by `"noid"` rather than assuming positional correspondence. NOIDs only —
|
|
589
642
|
raw Valkyrie ids are not a supported input.
|
|
590
643
|
|
|
644
|
+
### Searching the catalog (`Resource.search`)
|
|
645
|
+
|
|
646
|
+
A keyword search, as Cerberus's search bar runs it, for a caller that has words
|
|
647
|
+
rather than a NOID:
|
|
648
|
+
|
|
649
|
+
```ruby
|
|
650
|
+
result = AtlasRb::Resource.search("whaling logbook", type: "Work", per_page: 50)
|
|
651
|
+
result.pagination.total # => 12
|
|
652
|
+
hit = result.results.first
|
|
653
|
+
hit.title # => "Whaling logbook, 1851"
|
|
654
|
+
AtlasRb::Resource.class_for(hit.klass).find(hit.noid)
|
|
655
|
+
```
|
|
656
|
+
|
|
657
|
+
It searches Works, Collections, Communities and People, most relevant first.
|
|
658
|
+
`type` narrows to one of those four; any other value is a `400`, raised as
|
|
659
|
+
`AtlasRb::ResourceError`. Leave out the text to browse everything the user may
|
|
660
|
+
read, newest first.
|
|
661
|
+
|
|
662
|
+
Each row is a digest read off Solr — `{ "id", "noid", "klass", "title",
|
|
663
|
+
"creators", "year", "thumbnail", "in_progress", "embargoed", "incomplete" }` —
|
|
664
|
+
not the full typed payload. Rows are **gated to the acting user**: public, one of
|
|
665
|
+
their read or edit groups, or a resource they deposited. So the same text can
|
|
666
|
+
return different results for different users. There are no facets and no sort
|
|
667
|
+
option.
|
|
668
|
+
|
|
591
669
|
### Missing resources: `nil` on a read, a raise on a write
|
|
592
670
|
|
|
593
671
|
The two halves of the API answer an absent resource differently, on purpose.
|
|
@@ -637,16 +715,16 @@ written to prevent:
|
|
|
637
715
|
|
|
638
716
|
```ruby
|
|
639
717
|
begin
|
|
640
|
-
AtlasRb::
|
|
718
|
+
AtlasRb::Resource.put_mods("doesnotexist", "/tmp/mods.xml")
|
|
641
719
|
rescue AtlasRb::NotFoundError => e
|
|
642
720
|
e.status # => 404
|
|
643
|
-
e.message # => "
|
|
721
|
+
e.message # => "PUT /resources/doesnotexist/mods → 404 (no such resource)"
|
|
644
722
|
end
|
|
645
723
|
```
|
|
646
724
|
|
|
647
|
-
This covers every `create`
|
|
648
|
-
|
|
649
|
-
|
|
725
|
+
This covers every write: `create` and the type-specific writes on `Work`,
|
|
726
|
+
`Collection`, `Blob`, `FileSet`, `Compilation` and `Person`, and the
|
|
727
|
+
type-agnostic ones on `Resource`. Any other non-2xx a write gets raises
|
|
650
728
|
`AtlasRb::ResourceError`, which `NotFoundError` subclasses — so a caller that
|
|
651
729
|
only wants "the write failed" rescues the parent.
|
|
652
730
|
|
|
@@ -668,7 +746,7 @@ Refused writes raise on **every** binding and **every** path:
|
|
|
668
746
|
|
|
669
747
|
```ruby
|
|
670
748
|
begin
|
|
671
|
-
AtlasRb::
|
|
749
|
+
AtlasRb::Resource.set_permissions("w-789", { "read" => ["public"] })
|
|
672
750
|
rescue AtlasRb::ReadOnlyModeError => e
|
|
673
751
|
e.retry_after # => 900 (seconds, from Atlas's Retry-After header)
|
|
674
752
|
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
|
data/lib/atlas_rb/admin.rb
CHANGED
|
@@ -10,10 +10,11 @@ module AtlasRb
|
|
|
10
10
|
#
|
|
11
11
|
# ## Why a separate namespace
|
|
12
12
|
#
|
|
13
|
-
# The
|
|
14
|
-
# is structurally distinct from
|
|
15
|
-
#
|
|
16
|
-
#
|
|
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
|
#
|
data/lib/atlas_rb/collection.rb
CHANGED
|
@@ -84,7 +84,9 @@ module AtlasRb
|
|
|
84
84
|
))["collection"]
|
|
85
85
|
return result if xml_path.to_s.empty?
|
|
86
86
|
|
|
87
|
-
|
|
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)
|
|
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.
|