atlas_rb 1.29.9 → 1.29.11

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: 70d17a2c1a008d2472921d83a239c583c954adf6170747cb20c35411245c3230
4
- data.tar.gz: 38c3b7541876a8a45288fa3f751c42a5716bad78d76b6374acc868ed7aeae298
3
+ metadata.gz: f9830ee62fc5d43c43c2a47ddb42354199f944a9a4d2fe559406d5e5df607257
4
+ data.tar.gz: c3a1b2034baeafdc89ea33a83050e47acbd1bcb79d0fbb74ddf49846de95021f
5
5
  SHA512:
6
- metadata.gz: 0cca6024196cfba27a06712b51c39b0475e4f6622afeff68defa5173e3ee7a179716e9b058050c4705c9df0b0a363be78c03861dfc28e9b5b9d9b4e3100ae5ba
7
- data.tar.gz: d239bd7d76883f3c23135a1f63d8bc3b21b94cc5c24e96f584c974f6270036e8169c6e06df0a1a941e891126f3eafac7fa67cd0a7506ffa9f9fbe655afc55bfe
6
+ metadata.gz: 4388c5b2e0d815080ccc87bac6f1549dd11eddfd83a5c470184c06822b1160d008f73827c948049dbd149ae0a6961d1c1f29b39c7140f91f959426b26eb4b9ff
7
+ data.tar.gz: 9c374d0c7841d4e28be2c30fc6c6bc9e23d82b240ed986239e33162281317e8eec8f5aefd0f7ad72208883782bef3db743259c859f2050b5fee5b14ed7ee595d
data/.version CHANGED
@@ -1 +1 @@
1
- 1.29.9
1
+ 1.29.11
data/CHANGELOG.md CHANGED
@@ -1,5 +1,40 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.29.11
4
+
5
+ ### Added — previews in any metadata format, and the format list
6
+
7
+ - `Resource.preview` takes `metadata_format:`, such as `"dwc"`. It defaults
8
+ to `"mods"`, so existing calls render as before.
9
+ - `Resource.metadata_formats` lists the formats `preview` renders, from
10
+ `GET /metadata_formats`, as `id`, `label` and `media_type`. The `id` is
11
+ the token `preview` takes.
12
+
13
+ Needs Atlas 0.7.12 or later. An older Atlas ignores `metadata_format` and
14
+ treats every draft as MODS, and answers `404` for the format list.
15
+
16
+ ### Changed — `Resource.preview` raises on an error status
17
+
18
+ `preview` raises `AtlasRb::ResourceError` on a non-2xx. It used to return
19
+ the error body as if it were the HTML, so a caller that marked the result
20
+ HTML-safe would write Atlas's error JSON into its page. A refused draft
21
+ answers `422`, and the error's `body` is the JSON envelope.
22
+
23
+ ## 1.29.10
24
+
25
+ ### Fixed — documentation that the code contradicts
26
+
27
+ No code changed. The README and YARD now describe what the bindings do:
28
+
29
+ - `Resource.history` and `Resource.mods_versions` raise
30
+ `AtlasRb::ResourceError` on a `401` or `403`. They do not return a raw
31
+ Faraday response.
32
+ - `AuditEvent.emit` authenticates as the actor through a signed assertion,
33
+ not with the system token. A `401` or `403` comes back parsed, unraised.
34
+ - `Resource.dwc_versions` returns `nil` for an id that is not a Work.
35
+ - `Resource.set_permissions` gets no error when the caller removes a grant
36
+ for a group it is not in. Atlas keeps that grant and saves the rest.
37
+
3
38
  ## 1.29.9
4
39
 
5
40
  ### Added — `config.request_id`, sent as `X-Request-Id`
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- atlas_rb (1.29.9)
4
+ atlas_rb (1.29.11)
5
5
  faraday (~> 2.7)
6
6
  faraday-follow_redirects (~> 0.5)
7
7
  faraday-multipart (~> 1)
data/README.md CHANGED
@@ -405,8 +405,8 @@ result["resource_id"] # => "w-789"
405
405
  result["events"].first["action"] # => "update"
406
406
  ```
407
407
 
408
- Authorization errors (`401` / `403`) are not caught here — they surface as
409
- raw Faraday responses for the calling application's rescue layer.
408
+ A `401` or `403` raises `AtlasRb::ResourceError`, carrying Atlas's status and
409
+ body. A `404` returns `nil`.
410
410
 
411
411
  ### Session-scoped audit events
412
412
 
@@ -444,8 +444,8 @@ AtlasRb::AuditEvent.emit(
444
444
  `on_behalf_of_nuid`, `mode`, and `payload:` (free-form metadata) are
445
445
  omitted from the body when blank, so `emit` can also carry future,
446
446
  mode-less session events. Atlas stamps `occurred_at` server-side.
447
- Authorization errors (`401` / `403`) surface as raw Faraday responses,
448
- matching `Resource.history`.
447
+ `emit` is a POST, so the read guard does not apply: a `401` or `403` is not
448
+ raised, and Atlas's error envelope comes back parsed into a Mash.
449
449
 
450
450
  ### MODS version history
451
451
 
@@ -482,8 +482,9 @@ with `Work.mods` but XML is the only retained format.
482
482
  Version labels are **opaque, sortable OCFL `vN` strings**, not a 1-based
483
483
  counter — a Blob's preservation envelope occupies earlier versions, so the
484
484
  first MODS version is typically `v3`. Treat them as identifiers to feed back
485
- into `mods_version`. A resource with no MODS returns `{ "versions" => [] }`;
486
- `401` / `403` surface as raw Faraday responses, matching `Resource.history`.
485
+ into `mods_version`. A resource with no MODS returns `{ "versions" => [] }`.
486
+ A `401` or `403` raises `AtlasRb::ResourceError`, carrying Atlas's status and
487
+ body. A `404` returns `nil`.
487
488
 
488
489
  ### Re-parenting
489
490
 
@@ -577,6 +578,25 @@ checks shape only, so validate against `tdwg_dwc_simple.xsd` before you call.
577
578
  The two version calls behave as `mods_versions` and `mods_version` do, under
578
579
  the same admin gate.
579
580
 
581
+ ### Previewing a draft
582
+
583
+ `Resource.preview` renders a draft as HTML and saves nothing. The HTML is what
584
+ the format's display endpoint gives for a stored record. `Resource.metadata_formats`
585
+ lists the formats it takes, MODS first, so a format picker needs no
586
+ hard-coded list:
587
+
588
+ ```ruby
589
+ AtlasRb::Resource.metadata_formats.map { |f| [f["label"], f["id"]] }
590
+ # => [["MODS", "mods"], ["Darwin Core", "dwc"]]
591
+
592
+ AtlasRb::Resource.preview("/tmp/draft-mods.xml") # MODS
593
+ AtlasRb::Resource.preview("/tmp/draft-dwc.xml", metadata_format: "dwc") # Darwin Core
594
+ ```
595
+
596
+ `preview` raises `ResourceError` on a refused draft. Its body's `error` names
597
+ the rule: a Darwin Core shape rule, as `put_dwc` reports, or
598
+ `unknown_metadata_format` for a token Atlas does not preview.
599
+
580
600
  The two mutations raise the same way `reparent` does — `LinkedMemberError`
581
601
  on a structural `422` (carrying the envelope's `error` code as `#code`) and
582
602
  `ForbiddenError` on a `403` — instead of swallowing the envelope.
@@ -60,16 +60,15 @@ module AtlasRb
60
60
  #
61
61
  # Wraps `POST /audit_events`. The principals and metadata travel in the
62
62
  # JSON body — not in request headers — so the recorded event does not
63
- # depend on the ambient {AtlasRb.config} identity. The request still
64
- # authenticates as the configured caller (system token + the admin
65
- # `User:` header); Atlas admin-gates the endpoint server-side.
63
+ # depend on the ambient {AtlasRb.config} identity. The request
64
+ # authenticates as the actor: atlas_rb signs an assertion for
65
+ # `actor_nuid`. Atlas lets admins and devolved admins create the event,
66
+ # and refuses `:system`.
66
67
  #
67
68
  # Atlas stamps `occurred_at` server-side, so it is not part of the body.
68
69
  #
69
- # Authorization errors (`401` / `403`) are intentionally **not** caught
70
- # here — they surface as raw Faraday responses for the calling
71
- # application's rescue layer to translate, matching
72
- # {AtlasRb::Resource.history}.
70
+ # `emit` is a POST, so the read guard does not apply: a `401` or `403` is
71
+ # not raised, and Atlas's error envelope comes back parsed into a Mash.
73
72
  #
74
73
  # @param action [String] the audit action, e.g. `"impersonation_started"`
75
74
  # or `"impersonation_ended"`.
@@ -303,27 +303,55 @@ module AtlasRb
303
303
  .get("/resources/search")) { |body| AtlasRb::Mash.new(body) }
304
304
  end
305
305
 
306
- # Validate a MODS XML document against Atlas's schema *without* persisting it.
306
+ # Render an unsaved metadata draft as HTML, without persisting anything.
307
307
  #
308
- # Useful for surfacing validation errors in UIs before the user commits.
308
+ # The HTML is what the format's display endpoint gives for a stored record:
309
+ # a MODS draft renders as `/works/{id}/mods.html` does, a Darwin Core draft
310
+ # as `/works/{id}/dwc.html` does. {metadata_formats} lists the formats.
309
311
  #
310
- # @param xml_path [String] path to a MODS XML file on disk.
312
+ # @param xml_path [String] path to the draft XML file on disk.
313
+ # @param metadata_format [String] the draft's format token, such as
314
+ # `"mods"` or `"dwc"`. Defaults to `"mods"`.
311
315
  # @param nuid [String, nil] optional acting user's NUID. On the relay-signing
312
316
  # path it is signed into the assertion `sub`; on the BYO-JWT (`ATLAS_JWT`)
313
317
  # path it is ignored (identity lives in the token).
314
318
  # @param on_behalf_of [String, nil] optional NUID for the `On-Behalf-Of`
315
319
  # header. Falls through to {AtlasRb.config}.default_on_behalf_of when
316
320
  # omitted.
317
- # @return [String] the raw response body from `POST /resources/preview`
318
- # — typically a JSON or XML error report.
321
+ # @return [String] the rendered HTML.
322
+ # @raise [AtlasRb::ResourceError] on a non-2xx. A draft Atlas refuses
323
+ # answers `422`; the error's `body` is the JSON envelope, whose `"error"`
324
+ # names the rule, such as `"record_count"` or `"unknown_metadata_format"`.
319
325
  #
320
326
  # @example
321
- # AtlasRb::Resource.preview("/tmp/draft-mods.xml")
322
- def self.preview(xml_path, nuid: nil, on_behalf_of: nil)
327
+ # AtlasRb::Resource.preview("/tmp/draft-dwc.xml", metadata_format: "dwc")
328
+ def self.preview(xml_path, metadata_format: "mods", nuid: nil, on_behalf_of: nil)
323
329
  payload = { binary: Faraday::Multipart::FilePart.new(File.open(xml_path),
324
330
  "application/xml",
325
- File.basename(xml_path)) }
326
- multipart(nuid, on_behalf_of: on_behalf_of).post('/resources/preview', payload)&.body
331
+ File.basename(xml_path)),
332
+ metadata_format: metadata_format }
333
+ read_raw(multipart(nuid, on_behalf_of: on_behalf_of).post('/resources/preview', payload))
334
+ end
335
+
336
+ # List the metadata formats {preview} renders, MODS first.
337
+ #
338
+ # Build a format picker from this rather than a hard-coded list. A Work's
339
+ # own `"metadata_formats"` lists the additional records it holds, by the
340
+ # same tokens; it leaves out MODS, which every Work holds.
341
+ #
342
+ # @param nuid [String, nil] optional acting user's NUID.
343
+ # @param on_behalf_of [String, nil] optional NUID for the `On-Behalf-Of`
344
+ # header.
345
+ # @return [Array<AtlasRb::Mash>] one entry per format, with `"id"` (the token),
346
+ # `"label"` and `"media_type"`.
347
+ # @raise [AtlasRb::ResourceError] on a non-2xx other than `404` / `410`.
348
+ #
349
+ # @example
350
+ # AtlasRb::Resource.metadata_formats.map { |f| [f["label"], f["id"]] }
351
+ # # => [["MODS", "mods"], ["Darwin Core", "dwc"]]
352
+ def self.metadata_formats(nuid: nil, on_behalf_of: nil)
353
+ read_body(connection({}, nuid, on_behalf_of: on_behalf_of)
354
+ .get("/metadata_formats")) { |body| body.map { |entry| AtlasRb::Mash.new(entry) } }
327
355
  end
328
356
 
329
357
  # Fetch the access-control entries for a resource.
@@ -366,9 +394,8 @@ module AtlasRb
366
394
  # The whole envelope is preserved so callers can confirm the events
367
395
  # belong to the requested resource; access events as `result["events"]`.
368
396
  #
369
- # Authorization errors (`401` / `403`) are intentionally **not** caught
370
- # here — they surface as raw Faraday responses for the calling
371
- # application's rescue layer to translate.
397
+ # A `401` or `403` raises {AtlasRb::ResourceError}, carrying Atlas's
398
+ # status and body. A `404` returns `nil`.
372
399
  #
373
400
  # @todo Add pagination support once Atlas's history endpoint exposes
374
401
  # page / per_page query params. Today the endpoint returns the full
@@ -521,8 +548,9 @@ module AtlasRb
521
548
  # List the retained versions of a Work's Darwin Core record.
522
549
  #
523
550
  # The same envelope as {mods_versions}, under the same admin gate, with
524
- # attribution drawn from the Darwin Core edits only. A Work with no record,
525
- # or an id that is not a Work, comes back as `{ "versions" => [] }`.
551
+ # attribution drawn from the Darwin Core edits only. A Work with no record
552
+ # comes back as `{ "versions" => [] }`. An id that is not a Work returns
553
+ # `nil`, as Atlas answers `404`.
526
554
  #
527
555
  # @param id [String] the Work's NOID.
528
556
  # @param nuid [String, nil] optional acting user's NUID.
@@ -119,9 +119,10 @@ module AtlasRb
119
119
  # header.
120
120
  # @return [AtlasRb::Mash] the resource, unwrapped from its type key.
121
121
  # @raise [AtlasRb::NotFoundError] on `404` — the write did not happen.
122
- # @raise [AtlasRb::ResourceError] on any other non-2xx, including the `403`
123
- # Atlas answers when a caller tries to remove a grant for a group it does
124
- # not belong to.
122
+ # @raise [AtlasRb::ResourceError] on any other non-2xx. A caller who removes
123
+ # a read or edit grant for a group it does not belong to gets no error:
124
+ # Atlas keeps that grant and saves the rest, so check the returned
125
+ # resource. Admins and devolved admins may remove any group.
125
126
  #
126
127
  # @example Publish, leaving every other key alone
127
128
  # AtlasRb::Resource.set_permissions("xsj3xmz", { "read" => ["public"] })
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atlas_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.29.9
4
+ version: 1.29.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cliff