From 80aa44dbea3e82ea14d001f9c87c6f3f41885ac2 Mon Sep 17 00:00:00 2001 From: fstwn Date: Wed, 4 Nov 2026 15:48:04 +0100 Subject: [PATCH 1/9] fix(backup): pull_production passes SSH keepalive options --- scripts/backup/pull_production.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/backup/pull_production.ps1 b/scripts/backup/pull_production.ps1 index 97975c67..07e2736b 100644 --- a/scripts/backup/pull_production.ps1 +++ b/scripts/backup/pull_production.ps1 @@ -21,7 +21,8 @@ $day = Get-Date -Format yyMMdd $repo = Resolve-Path (Join-Path $PSScriptRoot '..\..') function Pull([string]$remote, [string]$file) { - cmd /c "ssh $Server $remote > `"$file`"" + # keepalives: the long asset pull broke with a connection reset without them + cmd /c "ssh -o ServerAliveInterval=15 -o ServerAliveCountMax=8 $Server $remote > `"$file`"" if ($LASTEXITCODE -ne 0) { throw "ssh failed ($LASTEXITCODE): $remote" } $size = (Get-Item $file).Length if ($size -eq 0) { throw "empty download: $file" } From cbafc59868593b8bf53bb18e3b7e639100058b2a Mon Sep 17 00:00:00 2001 From: fstwn Date: Wed, 4 Nov 2026 15:48:09 +0100 Subject: [PATCH 2/9] docs: scope and rules of 0.6.4.5, decisions 8.189 to 8.194, the spec follows --- docs/adr/DATA_MODEL_SPEC.md | 10 ++++++---- docs/adr/DESIGN_DECISIONS.md | 8 +++++++- docs/adr/IMPLEMENTATION_PLAN_0.6.md | 10 +++++++--- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/docs/adr/DATA_MODEL_SPEC.md b/docs/adr/DATA_MODEL_SPEC.md index 21637460..efb1dd25 100644 --- a/docs/adr/DATA_MODEL_SPEC.md +++ b/docs/adr/DATA_MODEL_SPEC.md @@ -1600,14 +1600,15 @@ role)`; the frontend merely hides controls. `admin` passes every check. D = the | submit `draft --> pending`; recall `pending --> draft` (8.18); resubmit `rejected --> draft` | author | | edit an unpublished record (fields, files, photos, attachments) | draft: author or `moderator(D)`; pending: `moderator(D)`; rejected: nobody (8.18) | | upload / replace / delete geometry files and photos | as "edit an unpublished record", **only while the snapshot is not `published`** (freeze rules: decision 6.6) | -| evidence attachments | unpublished record: as "edit an unpublished record"; published: `contributor(D)` adds, `moderator(D)` removes with reason, tombstone entry kept (decision 7.3) | +| evidence attachments | unpublished record: as "edit an unpublished record"; published: `contributor(D)` or `moderator(D)` adds, `moderator(D)` removes with reason, tombstone entry kept (decision 7.3) | | publish / reject / withdraw / reinstate (snapshot, evidence) | `moderator(D)`; publishing a child's **first** snapshot also ends its parents (split / merge, 8.8), so it needs `moderator` of every parent's dataset as well --- otherwise it waits in that dataset's queue | | promote `current_snapshot_id`; `effective_from`, `shape_class` overrides; recompute a snapshot's derived fields | `moderator(D)` | | PATCH identity metadata (`origin`, `material`, `original_function`, `is_public`, ...) | `moderator(D)`; while the identity is unpublished also its creator (8.9) | | `exit`, `reenter`, `withdraw` identity | `moderator(D)` | | `deinstall`, `undo-deinstall` (8.104) | `moderator(D)` | | draw from a batch (8.105) | as "create identity"; while the batch is reserved only the reserving user or `moderator(D)` (8.110) | -| move identity D1 --> D2 | `moderator(D1) and moderator(D2)` | +| move identity D1 --> D2 (8.191) | `moderator(D1) and moderator(D2)`; refused while a version or record of it is draft or pending; a public identity into an unreviewed dataset only as `admin` | +| reserve, `reenter`, undo `exit`, `deinstall`, `undo-deinstall`, add a photo or an attachment on a withdrawn identity, version or record (8.190) | nobody: 409 "The component is withdrawn."; a moderator reinstates first | | set evidence `verification` | `self_attested` / back to `unverified`: the recorder, unless a reviewer set the state; `reviewed` / `accredited` / any downgrade: `reviewer(D)` or `admin`, never the recorder or a `performed_by` user (8.12, I27) | | supersede published evidence | `contributor(D)` (new record enters `pending`) | | reserve | any authenticated user who can read the element, while it is not reserved | @@ -1615,7 +1616,7 @@ role)`; the frontend merely hides controls. `admin` passes every check. D = the | manage D's members, D's `visibility` / `name` / `description` | `moderator(D)` | | invite a user (8.14); add a member by exact email (8.20) | `admin` (any dataset, or none); `moderator(D)` (into D only) | | search users (8.20) | `admin` | -| revoke an unused invitation | its creator, `moderator(D)` of its dataset, `admin` | +| revoke an unused invitation | `moderator(D)` of its dataset, `admin`; its creator loses the right with the role (8.193) | | create dataset (8.139) | any signed-in account with a verified e-mail address, up to `CSC_MAX_DATASETS_PER_USER` (admins: unlimited); the creator becomes `moderator` and `contributor` | | delete a dataset (8.139) | `moderator(D)` or `admin`, only while D holds no identity | | set `reviewed` on a dataset (8.139) | `admin` | @@ -1666,6 +1667,7 @@ DELETE /identities/{id}/exit moderator(D); undo a mistaken POST /identities/{id}/reenter moderator(D); body = new origin; archives {origin, exit} to past_cycles (section 3.1.3) POST /identities/{id}/withdraw moderator(D); body = {reason, duplicate_of?} (section 3.1.4) POST /identities/{id}/reinstate moderator(D); clears `withdrawn` +POST /identities/{id}/move moderator of source and destination; body = the destination dataset; change-logged (8.191) DELETE /identities/{id} author or moderator(D) while nothing was ever published (I19); ?purge=1 admin only (body {confirm_id, reason}) DELETE /snapshots/{sid}?purge=1 admin: any status (body {confirm_id, reason}); not the current snapshot ``` @@ -1824,7 +1826,7 @@ POST /datasets/{did}/public moderator(D): body = {is_publ POST /datasets/{did}/members moderator(D): body = {email, roles}; exact match --> added + notified, no account --> invitation (8.20) GET /users/search?q= admin: prefix search over username, name, email (member editor lookup, 8.20) GET /users admin: + memberships per user; ?q= ?dataset= ?dataset_role= ?no_dataset=1 ?role= ?state=enabled|disabled|unverified ?invited=1 (8.21) -PATCH /identities/{id} moderator(D) for metadata; changing `dataset` needs moderator of both (section 7.0) +PATCH /identities/{id} moderator(D) for metadata; `dataset` changes only through POST /identities/{id}/move (8.191) GET /materials public: the controlled list (section 2.10) POST /materials admin; `default_class` required (I25) PATCH /materials/{mid} admin; label, group, default_class, uniclass, notes, retired (_id immutable); re-derives material_class diff --git a/docs/adr/DESIGN_DECISIONS.md b/docs/adr/DESIGN_DECISIONS.md index d466b7d6..07d29afd 100644 --- a/docs/adr/DESIGN_DECISIONS.md +++ b/docs/adr/DESIGN_DECISIONS.md @@ -148,7 +148,7 @@ into one **metadata object**. | 8.11 | **The client header is required for writes and every logged-in request; anonymous GETs may omit it; a scanned non-public piece shows a "not public" page** (review item 5, user 2026-09-29). Writes and requests with a login token: header required, known client, version >= minimum, else 426. Anonymous GET / HEAD: header optional (the `/id/{uuid}` resolver for any scanner, curl / Python readers of public pieces --- CPR Art 76(2)(e) free access). A known client below its minimum: 426 always. User: an anonymous scan of a non-public piece shows a page saying the component is not public, with a sign-in link. | Every GH UserObject logs in (`CSC_Session` sends the token), so old ones --- also those before 0.5.1.0 without any header --- can neither write nor misread 0.6 data. Enforcement is on iff `CSC_MIN_CLIENT_VERSIONS` is set (production sets it in the cutover deploy; dev and tests stay log-only). Exempt: CORS preflight (`OPTIONS`), all of `/ghinterface/` (the updater also calls version / download / name lists), `/docs`, `/redoc`, `/openapi.json`, `/health`, `/version`. `/id/{uuid}` no longer hides existence behind a 404-equivalent: whoever scans a tag holds the piece. Anonymous --> "not public" + sign-in (callback to the piece); logged in without access --> "no access" page, no dataset details. Spec section 7.4, section 7.5. | | 8.12 | **Verification has owners: `self_attested` is the recorder's own claim, `reviewed` and `accredited` need a second person** (review item 6, user 2026-09-30). (1) `self_attested`: set by the recorder (evidence form checkbox "I performed this and stand by the result"), only when `performed_by` contains an actor with `user_id == recorded_by_user_id`; an outside lab's result stays `unverified` until reviewed. The recorder toggles `unverified` <--> `self_attested` and never overrides a reviewer's state. (2) `reviewed` / `accredited`: `reviewer(D)` or admin who is neither the recorder nor a `performed_by` user --- **no admin exception**; server sets `verification.by` (the reviewer as a user actor) and `at`. (3) The accreditation block stays typed in; `accredited` is a reviewer's act with I22 as precondition and a **required `verification.note`** saying what was checked (the reviewer view links the body's public register, e.g. DAkkS). No curated organisation registry in 0.6. (4) Changing a result field (`summary`, `payload`, `derived`, `performed_by`, `standard`, `method*`, `observed_at*`, `sampled_at*`, `position.snapshot_id` / `point`) while draft / pending resets `reviewed` / `accredited` to `unverified`. | Closes: a reviewer could mark their own record `reviewed` (factor 1.00); anyone could type an ISO 17025 block and satisfy I22; nobody could set `self_attested`. New **I27** (document check). A one-person dataset cannot reach `reviewed` without a second person. Spec section 3.3.3, section 5, section 7.0, section 7.2. | | 8.13 | **Attachment files are downloaded only by signed-in users** (review item 7, user 2026-09-30: "to reduce moderation overhead"). Anonymous readers of an `is_public` piece see the attachment list (`media_type`, `size`, `sha256`, `uploaded_at`) and "sign in to download"; signed-in users who can see the record download as before. Snapshot photos stay public (general impression, EXIF-stripped, 7.13). The upload control carries a "?" notice: professional roles are fine; private persons, faces, number plates are not --- redact before upload. `POST /actors/redact` also returns a worklist of attachments on records naming the person (`performed_by`, `recorded_by`, `uploaded_by`); a moderator adds a redacted copy and removes the original with reason `gdpr`, which also blanks the tombstone's `name` (`sha256` kept). No content scanning. | Actor redaction and the organisation-only projection could not reach inside files (lab reports name technicians, photos show people); a per-attachment public flag was rejected (a review step per file). Spec section 3.1.4, section 3.3, section 7.2, section 7.3. | -| 8.14 | **Registration without an open-domain address is by email-bound invitation only** (user 2026-09-30: 0.6 needs non-TU registration; "only email bound invitations, no open codes"). `admin` invites anyone; `moderator(D)` invites into its own dataset. An invitation names one email address, holds a single-use code (16-char base32, 80 bit; only `code_sha256` stored), expires after 14 days by default, is sent by mail as `/auth/register?code=...` and can be revoked while unused. Registration with a code must use the invited address; the address then counts as verified (the code proves receipt). Optional dataset + roles are granted on redemption (a moderator only in its own dataset). Batches = a list of addresses, one invitation each. Self-registration stays open for `CSC_OPEN_REGISTRATION_DOMAINS` (env, default `tu-darmstadt.de`, subdomains included). Amended by 8.172: no open domain set means invite only, and the web names the open domains instead of TU Darmstadt. | New collection `invitations` (spec section 3.7), routes in section 7.7, permission rows in section 7.0, `/admin` + dataset member editor gain "invite" (plan P3). Rejected: open codes handed over in person (a leaked code admits anyone). | +| 8.14 | **Registration without an open-domain address is by email-bound invitation only** (user 2026-09-30: 0.6 needs non-TU registration; "only email bound invitations, no open codes"). `admin` invites anyone; `moderator(D)` invites into its own dataset. An invitation names one email address, holds a single-use code (16-char base32, 80 bit; only `code_sha256` stored), expires after 14 days by default, is sent by mail as `/auth/register?code=...` and can be revoked while unused. Registration with a code must use the invited address; the address then counts as verified (the code proves receipt). Optional dataset + roles are granted on redemption (a moderator only in its own dataset). Batches = a list of addresses, one invitation each. Self-registration stays open for `CSC_OPEN_REGISTRATION_DOMAINS` (env, default `tu-darmstadt.de`, subdomains included). Amended by 8.172: no open domain set means invite only, and the web names the open domains instead of TU Darmstadt. Amended by 8.193: only a moderator of the dataset or an admin revokes an invitation; its creator loses the right with the role. | New collection `invitations` (spec section 3.7), routes in section 7.7, permission rows in section 7.0, `/admin` + dataset member editor gain "invite" (plan P3). Rejected: open codes handed over in person (a leaked code admits anyone). | | 8.15 | **The frame is the valid frame closest to the stored coordinates** (review item 8, user 2026-09-30). Candidates: the OBB axes assigned to x / y / z in extent order (7.10, columns standing), extents within `max(2 %, 3 mm)` of each other count as tied and may swap, either sign per axis, right-handed only; the candidate with the smallest rotation from the stored axes (max `trace(R)`) wins, exact ties by a fixed candidate order. Round sections: trimesh's angle about the long axis is accepted (deterministic on the same input; `bbx` unaffected). | One rule gives both the sign rule and the tie-break; re-runs are stable; a beam uploaded along world X keeps +X and DDU stones stay near their gripper-plane pose. Signs are not intrinsic: rescans in other poses may differ by a 180 degree flip (`bbx`, filters, shape class unaffected; snapshot comparison needs registration, not in 0.6). Rejected: third-moment (skew) signs --- flip on near-symmetric pieces. Spec section 4.3. | | 8.16 | **Minor review items b--d** (user 2026-09-30). (b) At most one open correction per record: at most one `draft` / `pending` record with `supersedes == X` (I14 extended; a second --> 409 naming the open one). (c) Evidence on a withdrawn identity --> 409 (with `duplicate_of`, the 409 names the canonical identity); on a terminal exit (`split`, `merged`, `recycled`, `disposed`) only with `observed_at <= exit.at`; on a non-terminal exit (`installed`, `returned`, `lost`) allowed (resolves `after_exit`, 8.10). (d) Positioned evidence keeps its `position.snapshot_id` and stored-coordinate point when that snapshot is corrected in new coordinates; the viewer draws it only on that snapshot; the correction dialog warns "N evidence records are positioned on the previous version" and offers to supersede each (re-placed point / re-imported bars). No stored transform between versions in 0.6. | New I28 (evidence vs. withdrawn identity / terminal exit; corpus check). Spec section 3.3.2, section 5, section 7.2. | | 8.17 | **"Withdrawn" means one thing at every level: the full record for the dataset, a tombstone for everyone else** (minor review item a, user's proposal refined, 2026-09-30). Identity, snapshot and evidence alike: members of D and admin see content, files and the reason; everyone else who can see the component (anonymous on `is_public`, logged-in non-members of a `catalog` dataset) gets **200 with a tombstone** --- id, kind, `version`, `status: withdrawn`, withdrawal date, link to the identity's current snapshot (or `duplicate_of`). The reason is never public; files of withdrawn records are members only; the public timeline shows "v2 --- withdrawn (date)". 410 stays for purged records. Withdrawing the current snapshot falls back automatically to the latest remaining published, non-superseded snapshot (naming a replacement is optional); none left --> `current_snapshot_id = null`, identity out of default lists, `/id` shows "no current state". Reinstate restores. | Before, withdrawn records followed the component's visibility, so a public piece kept showing exactly what a moderator had withdrawn (wrong piece, bad scan, person in a photo). I3b: "if not null, references a published snapshot". `can_see_record` returns a projection `full | tombstone | none`. Content that must vanish for members too: photo / attachment removal (tombstone entry) or purge. Spec section 3.1.4, section 5, section 7.0, section 7.1, section 7.5. | @@ -323,6 +323,12 @@ into one **metadata object**. | 8.186 | **A failed item keeps its slot** (user 2026-11-02; 0.6.4.4, from the review of #40 at stop point 1; refines 8.180). Grasshopper runs an item-access component once per item. (a) An input with no data at all (nothing connected, or `VolatileDataCount` 0) is a warning and gives empty trees on every output, as #40 says. (b) When one item of a list is missing, empty or fails, that iteration gives a null in its slot (with the warning or error of the item), so the outputs stay one to one with the input list, as native Grasshopper components do; an empty tree there would shift every later result. (c) Components with list or tree access, and the early stop (`empty_outputs()`), give empty trees. (d) Live check in Rhino 8 by the maintainer: `ApplyFrame` with `Input = [passport, '', passport]` gives three slots on `Output` and `Frame`, the middle one null; and with nothing connected, empty outputs. | | 8.187 | **`ReinforcementLayout`: the steel grade is optional** (user 2026-11-02; 0.6.4.4, from the review of #40 at stop point 1). The `Spec` input may stay empty: no warning, and the bars are stored without a grade, as the backend allows (`LayoutBar.spec` is optional). A covermeter scan rarely knows the grade. A `Spec` that is given follows the existing count rule. | | 8.188 | **After a source swap: save, close and reopen the definition** (user 2026-11-03; 0.6.4.4, from the first local update of 0.6.4.4; amends the wording of 8.155 b). A component whose source `CSC_Update` replaced with `SetSource` has no compiled code in Rhino 8 (8.35): it shows "Object reference not set to an instance of an object", and its script editor opens the source as plain text with Run, Save and Apply disabled (`ScriptEditor.BeginEdit` falls back to "as text" when `Script.GetCode` has no cached code). The Apply that 8.155 names is therefore not reachable. Saving the definition, closing it and opening it again builds the code from the stored source; then the editor opens normally (checked by the maintainer in Rhino 8). (a) The remark under a replaced component and the end-of-run line of `CSC_Update` say so: save, close and reopen the definition, then open the script editor and click Apply. (b) Unchanged: `CSC_Update` still only calls `SetSource` (no self-healing, 8.155 b). | +| 8.189 | **Scope of 0.6.4.5: the permission mismatches and the leftovers** (user 2026-11-04; after 0.6.4.4, before 0.6.5). In: the permission mismatches of the audit of 2026-10-29, issues #46 to #50, and the leftovers of the earlier reviews. Out: `CSC_Update` stays as it is, without self-healing after a source swap (8.155 b, 8.188); so also no warning in its local mode about older user objects. A web and backend release: `bump-version` without `--gh`, no Rhino export. The two Grasshopper leftovers of the review of 0.6.4.4 (`Actor` can still shift slots when a needed input depends on another item's value; the unreachable return of `ApplyFrame`) move to 0.6.5. The open rules are grilled before the brief and logged here or in their own rows. | +| 8.190 | **A withdrawn element stays out of circulation: the backend refuses** (user 2026-11-04; 0.6.4.5, #49). Reserve, re-enter, undo exit and undo deinstall answer 409 "The component is withdrawn." on a withdrawn element, as deinstall already does. Adding a photo to a withdrawn version, or to any version of a withdrawn element, and adding an attachment to a withdrawn record are refused too. To act on it, a moderator reinstates first. The web keeps hiding these controls. | A withdrawn element is a tombstone (6.4); withdrawing already clears the reservation. | +| 8.191 | **Moving an element to another dataset** (user 2026-11-04; 0.6.4.5, #50). `POST /identities/{id}/move` with the destination dataset, and a control in the actions menu of the element; one element at a time, no "move all". The rule is `move_identity`: a moderator of the source and of the destination dataset. `dataset` is stored only on the identity and catalog numbers are global, so the move changes that field and writes a change log entry. A withdrawn element can move, so that a dataset can be emptied and deleted. Refused (409) while a version or record of the element is draft or pending, since the rights of its author hang on the dataset. A public element cannot move into an unreviewed dataset unless the caller is an admin (8.139 c). An element in several datasets, or a separate collection system, is not part of this: issue #54, for later. | Deleting a dataset refuses while it holds any element, and no route could empty it. | +| 8.192 | **#50: a delete control for a never-published element; the other actions without a web control stay API-only** (user 2026-11-04; 0.6.4.5). The web gains a control to delete an element nothing of which was ever published, with a confirm dialog, for its creator or a moderator (`delete_identity`). No web control in this release, each logged for later: editing the notes of published evidence (#55), the moderators' recompute and overrides (#56), uploading and deleting meshes and point clouds (#57), the "as of a date" views of the history (#58). `purge` and `redact_actor` stay admin-only over the API. | A missing control fails for nobody, so these are no mismatches; the delete control is one, since the web offers no way to remove such an element. | +| 8.193 | **#48: what the web hides although the backend allows it** (user 2026-11-04; 0.6.4.5). (a) The web shows the control, the backend rule stays: a moderator without the contributor role adds an attachment to a published record; a contributor reaches the edit form of their own draft version through a link in the version dialog; a new state or evidence can be added when every version is withdrawn, and an element published once with no current version can be taken out of circulation, both through one shared "ever published" helper that replaces `current_snapshot_id` as the test; a site admin submits, recalls or returns to draft another person's record (6.5); an author edits their evidence draft after losing the contributor role, the form no longer blocks. (b) The same for two rules the user kept: a moderator edits the name, notes and date of a withdrawn version or of any version of a withdrawn element, and fills the layout document of a superseded record. Neither needs a reinstatement or a correction first. (c) The backend tightens one rule: only a moderator of the dataset, or an admin, revokes an invitation; the creator loses the right with the role. (d) Stays as it is: on an unreviewed dataset the visibility and public switches stay disabled for a site admin too, who ticks "Reviewed" first; the API override of `refuse_unreviewed` stays (8.139 c). | Correcting a text or adding a drawing reference changes no state and adds no version, so it differs from the actions 8.190 refuses, and a tombstone may still need a typo fixed. Rights that came with a role end with the role. The review of a dataset stays a visible step. | +| 8.194 | **The leftovers of 0.6.4.5** (user 2026-11-04; amends nothing, settles 8.189). In: the check of `tests/grasshopper/test_signin.py` that needs `sys.stdlib_module_names` runs only on Python 3.10 or newer, so the file passes in a 3.9 environment; "version" replaces "snapshot" in the user text of `SnapshotPhotoCapture`. Later: "Show in viewer" for other positioned records (8.178), and an actor role for "retrieved the source" or "modeller", which is grilled with other data-model work. No change: the photo hint line stays hidden in the compact card; `GetDescriptor` and `AddEvidence` keep reporting the first failure of a list in their own way. No repository change for the crontab: `crontab.example` is the tracked one and `uberspaceconfig/crontab/crontab` a gitignored local copy; the maintainer compares the crontab on the server with the example. | The hint would not fit the low row, and the Add button is disabled at the limit. The 14 days of the privacy page hold for the request log without cron, since `DailyFileHandler` deletes its older files; the crontab line covers the cron and deploy logs. | **Facts confirmed (user, 2026-09-28):** the 35 ZirKuS reinforcement bars were modelled after the original drawing --> `basis: drawing` (step 6d). The 2024-07-24 deinstallation applies to all 16 diff --git a/docs/adr/IMPLEMENTATION_PLAN_0.6.md b/docs/adr/IMPLEMENTATION_PLAN_0.6.md index 4b69018e..72a213b3 100644 --- a/docs/adr/IMPLEMENTATION_PLAN_0.6.md +++ b/docs/adr/IMPLEMENTATION_PLAN_0.6.md @@ -988,6 +988,8 @@ fold (once it is clear which quantities are searched); Atlas Search for typo-tol **0.6.4.4 --- Grasshopper hardening (user 2026-10-28, after 0.6.4.2; 8.180; moved from 0.6.4.3 by 8.184; scope amended by 8.185):** the Grasshopper side and one web item, (g) (`bump-version --gh` first, then the export in Rhino 8). (a) #40, with #32 and #33 as its first cases: the scan of 2026-10-28 found eleven components that report a missing input with `_addError` through `BuildError` (`Actor`, `ApplyFrame`, `Capture`, `ComputeFrame`, `CreateComponentIdentity`, `CreateComponentSnapshot`, `FetchReinforcementLayout`, `IdentityMetadata`, `Origin`, `ReinforcementLayout`, `SnapshotMetadata`; `AddEvidence` already warns), fourteen outputs started as `''` or `None`, and an `empty_outputs()` that returns `None` in 47 components. The fix belongs in the shared library (a missing-input error reported as a warning, an empty tree helper) and then in every component; the implementer lists each component and what changed. A failed item of an item-access component keeps its slot with a null; an input with no data and the early stop give empty trees (8.186). The `Spec` input of `ReinforcementLayout` is optional (8.187). (b) #36: `ReadFromD2P` finds the D2P component, but its `Component` output does not carry a D2P component instance (the maintainer, live in Rhino; 8.185 b). Cause open (8.185 b, amended): `instance_from_object` already returns the .NET object, declared as `IComponentBase`; the leading hypothesis is the pythonnet 3 interface proxy. Unwrap to the concrete object, fix the output, report a failed resolution as a warning naming the element, check `SyncWithRhinoDoc` for the same fault; live check in Rhino by the maintainer. (c) The descriptions of `ApplyFrame`, moved from 0.6.5 (e); with them the `Frame` and `BoundingBox` descriptions of `DisassembleComponent` say "where the element sits" instead of "stored coordinates", since both apply `csc_placement` (found in the review, kept by the user 2026-11-02). (d) The 8 `PytestUnhandledThreadExceptionWarning` of the Grasshopper tests: cause found, fixed or explained. (e) "Element" instead of "piece" in the Grasshopper descriptions (8.183 b). (f) `requirements-dev.txt` takes `pytest>=8` without an upper bound, so CI gets each new pytest the day it is out (pytest 9.2.0 broke a test on the tag of 0.6.4.2, fixed in #44): every dev requirement pinned exactly (`==`) at a version about two weeks old (8.185 c). (g) #52: the beta banner and the login notice take the version from `package.json`, the `.env` keeps the wording with a `{version}` placeholder (8.185 a); server note at the release. (h) CHANGELOG only: the component map's UMAP starts from `init='pca'` (commit `d2b39012`, made outside a release); all map positions shift once. +**0.6.4.5 --- permission mismatches and leftovers (user 2026-11-04, after 0.6.4.4; 8.189):** (a) #46 controls the backend refuses (403), (b) #47 controls the state refuses (409), (c) #48 controls the web hides although the backend allows them: six plus the two rules kept for a withdrawn version and a superseded layout get a control, revoking an invitation becomes moderator-only, the switches of an unreviewed dataset stay disabled (8.193), (d) #49 the backend refuses the circulation actions and added files on a withdrawn element (8.190), (e) #50 a route and a web control to move one element to another dataset (8.191), and a web control to delete a never-published one; the other actions without a web control stay API-only, #55 to #58 (8.192), (f) the leftovers (8.194): the 3.10-only check of `test_signin.py` is limited to 3.10 or newer, and "version" replaces "snapshot" in the user text of `SnapshotPhotoCapture`, (g) the backup script passes SSH keepalive options (user 2026-11-04; the pull of the assets broke at 1.56 GB on 2026-10-29). Web and backend only: `bump-version` without `--gh`, no Rhino export; `CSC_Update` is not touched (8.189). Each case is read again before it is fixed. The rules are grilled before the brief. + **0.6.5 --- reinforcement from Grasshopper (about 6--8 days; moved from 0.6.4 by the user 2026-10-21):** (a) units in GH: every component scales by the document unit (a prerequisite for placing scans); (b) RL8, a GH builder for the `rebar_spec` claim and its display, grilled together with (c); (c) Ferroscan to reinforcement layout, @@ -996,7 +998,9 @@ as attachments, (d) several scans of one face; (c) "the image in 3D" later. (e) is (user 2026-10-27): its `Frame` output is the frame used, in the stored coordinates (where the piece sat before the move), not the frame of the moved piece. The descriptions of the component and of the output say so plainly and point to `DisassembleComponent`, whose `Frame` applies `csc_placement` and so -gives the frame where the moved piece sits; moved to 0.6.4.3 (8.180), then to 0.6.4.4 (8.184). +gives the frame where the moved piece sits; moved to 0.6.4.3 (8.180), then to 0.6.4.4 (8.184). (f) From the review +of 0.6.4.4 (8.189): `Actor` can still shift slots when a needed input depends on another item's value; the +unreachable return of `ApplyFrame`. **0.6.6 --- interoperability (about 5--7 days):** the IFC export (`compose?format=ifc`; first the `ifcopenshell` wheel check for the server, then IFC4 vs IFC4x3 and single piece vs selection); the timeline as PROV-O / @@ -1029,13 +1033,13 @@ passport) in `CONTEXT.md` first; whether the backend errors become codes, the ma and the privacy page a German text (the maintainer's own); a rule for the implementer that every new string is written in both languages. Grasshopper and MCP texts stay English. -**Later, not yet scheduled --- permission mismatches between the web app and the backend (user 2026-10-29):** an audit of every action in `permissions.py` against the web app, after #45, found more cases, logged as issues and kept in the backlog for now: #46 controls the backend refuses (403); #47 controls the record's state refuses (409), often only after a whole form is filled in; #48 controls the web hides although the backend allows them (several from reading "published" as `current_snapshot_id` instead of `identity_ever_published`); #49 the backend allows reserve, re-enter and the undo actions on a withdrawn element, which the web hides (a rule to decide); #50 no route to move an element to another dataset (`move_identity` is a rule only, so a dataset that ever held an element cannot be deleted) and no web control to delete a never-published element. Each case is read again before it is fixed. Found in the review of 0.6.4.3 (#45): "snapshot" in user-facing text of `SnapshotPhotoCapture` (the web says "version"); the photo hint line never shows in the compact card. +**Later, not yet scheduled --- permission mismatches between the web app and the backend (user 2026-10-29):** an audit of every action in `permissions.py` against the web app, after #45, found more cases, logged as issues and kept in the backlog for now: #46 controls the backend refuses (403); #47 controls the record's state refuses (409), often only after a whole form is filled in; #48 controls the web hides although the backend allows them (several from reading "published" as `current_snapshot_id` instead of `identity_ever_published`); #49 the backend allows reserve, re-enter and the undo actions on a withdrawn element, which the web hides (a rule to decide); #50 no route to move an element to another dataset (`move_identity` is a rule only, so a dataset that ever held an element cannot be deleted) and no web control to delete a never-published element. Each case is read again before it is fixed. Found in the review of 0.6.4.3 (#45): "snapshot" in user-facing text of `SnapshotPhotoCapture` (the web says "version"); the photo hint line never shows in the compact card. Moved to 0.6.4.5 (8.189). **Outside a release (the maintainer):** the Atlas traffic measurement of 0.6.1.0 (c); the backend CI job back to `ubuntu-latest` once MongoDB 8.0 starts on the runner's kernel (SERVER-121912); the two open dev findings of `npm audit` (`body-parser`, `deepmerge`, both through `shadcn`) once fixed versions exist and are about two weeks old (0.6.4.2 (g)). -**Later or ideas:** the GH sign-in on macOS (Keychain); Ferroscan "the image in 3D"; MCP opened to members +**Later or ideas:** "Show in viewer" for other positioned records (8.178, 8.194); an actor role for "retrieved the source" or "modeller" (a data-model grill, 8.194); the GH sign-in on macOS (Keychain); Ferroscan "the image in 3D"; MCP opened to members (after 0.6.3.1); the CSC logo and brand, then the logo in mails, Open Graph and the favicon; the partners on the credits page (their consent); usage statistics without cookies; timber evidence methods; the analytics page; transactions for record plus change log; xeokit (for later, see `FUTURE.md`); a similarity-search From ea361818b8c337b561cc3996ab3236d412d21ca0 Mon Sep 17 00:00:00 2001 From: fstwn Date: Wed, 4 Nov 2026 15:49:30 +0100 Subject: [PATCH 3/9] docs: 8.193 (c) confirmed knowing the old revoke rule was tested --- docs/adr/DESIGN_DECISIONS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/adr/DESIGN_DECISIONS.md b/docs/adr/DESIGN_DECISIONS.md index 07d29afd..2bdfcb46 100644 --- a/docs/adr/DESIGN_DECISIONS.md +++ b/docs/adr/DESIGN_DECISIONS.md @@ -327,7 +327,7 @@ into one **metadata object**. | 8.190 | **A withdrawn element stays out of circulation: the backend refuses** (user 2026-11-04; 0.6.4.5, #49). Reserve, re-enter, undo exit and undo deinstall answer 409 "The component is withdrawn." on a withdrawn element, as deinstall already does. Adding a photo to a withdrawn version, or to any version of a withdrawn element, and adding an attachment to a withdrawn record are refused too. To act on it, a moderator reinstates first. The web keeps hiding these controls. | A withdrawn element is a tombstone (6.4); withdrawing already clears the reservation. | | 8.191 | **Moving an element to another dataset** (user 2026-11-04; 0.6.4.5, #50). `POST /identities/{id}/move` with the destination dataset, and a control in the actions menu of the element; one element at a time, no "move all". The rule is `move_identity`: a moderator of the source and of the destination dataset. `dataset` is stored only on the identity and catalog numbers are global, so the move changes that field and writes a change log entry. A withdrawn element can move, so that a dataset can be emptied and deleted. Refused (409) while a version or record of the element is draft or pending, since the rights of its author hang on the dataset. A public element cannot move into an unreviewed dataset unless the caller is an admin (8.139 c). An element in several datasets, or a separate collection system, is not part of this: issue #54, for later. | Deleting a dataset refuses while it holds any element, and no route could empty it. | | 8.192 | **#50: a delete control for a never-published element; the other actions without a web control stay API-only** (user 2026-11-04; 0.6.4.5). The web gains a control to delete an element nothing of which was ever published, with a confirm dialog, for its creator or a moderator (`delete_identity`). No web control in this release, each logged for later: editing the notes of published evidence (#55), the moderators' recompute and overrides (#56), uploading and deleting meshes and point clouds (#57), the "as of a date" views of the history (#58). `purge` and `redact_actor` stay admin-only over the API. | A missing control fails for nobody, so these are no mismatches; the delete control is one, since the web offers no way to remove such an element. | -| 8.193 | **#48: what the web hides although the backend allows it** (user 2026-11-04; 0.6.4.5). (a) The web shows the control, the backend rule stays: a moderator without the contributor role adds an attachment to a published record; a contributor reaches the edit form of their own draft version through a link in the version dialog; a new state or evidence can be added when every version is withdrawn, and an element published once with no current version can be taken out of circulation, both through one shared "ever published" helper that replaces `current_snapshot_id` as the test; a site admin submits, recalls or returns to draft another person's record (6.5); an author edits their evidence draft after losing the contributor role, the form no longer blocks. (b) The same for two rules the user kept: a moderator edits the name, notes and date of a withdrawn version or of any version of a withdrawn element, and fills the layout document of a superseded record. Neither needs a reinstatement or a correction first. (c) The backend tightens one rule: only a moderator of the dataset, or an admin, revokes an invitation; the creator loses the right with the role. (d) Stays as it is: on an unreviewed dataset the visibility and public switches stay disabled for a site admin too, who ticks "Reviewed" first; the API override of `refuse_unreviewed` stays (8.139 c). | Correcting a text or adding a drawing reference changes no state and adds no version, so it differs from the actions 8.190 refuses, and a tombstone may still need a typo fixed. Rights that came with a role end with the role. The review of a dataset stays a visible step. | +| 8.193 | **#48: what the web hides although the backend allows it** (user 2026-11-04; 0.6.4.5). (a) The web shows the control, the backend rule stays: a moderator without the contributor role adds an attachment to a published record; a contributor reaches the edit form of their own draft version through a link in the version dialog; a new state or evidence can be added when every version is withdrawn, and an element published once with no current version can be taken out of circulation, both through one shared "ever published" helper that replaces `current_snapshot_id` as the test; a site admin submits, recalls or returns to draft another person's record (6.5); an author edits their evidence draft after losing the contributor role, the form no longer blocks. (b) The same for two rules the user kept: a moderator edits the name, notes and date of a withdrawn version or of any version of a withdrawn element, and fills the layout document of a superseded record. Neither needs a reinstatement or a correction first. (c) The backend tightens one rule: only a moderator of the dataset, or an admin, revokes an invitation; the creator loses the right with the role. The old rule was deliberate and tested; the user confirmed the change knowing that, so `test_a_demoted_moderator_cannot_resend_but_can_still_revoke` changes with it. (d) Stays as it is: on an unreviewed dataset the visibility and public switches stay disabled for a site admin too, who ticks "Reviewed" first; the API override of `refuse_unreviewed` stays (8.139 c). | Correcting a text or adding a drawing reference changes no state and adds no version, so it differs from the actions 8.190 refuses, and a tombstone may still need a typo fixed. Rights that came with a role end with the role. The review of a dataset stays a visible step. | | 8.194 | **The leftovers of 0.6.4.5** (user 2026-11-04; amends nothing, settles 8.189). In: the check of `tests/grasshopper/test_signin.py` that needs `sys.stdlib_module_names` runs only on Python 3.10 or newer, so the file passes in a 3.9 environment; "version" replaces "snapshot" in the user text of `SnapshotPhotoCapture`. Later: "Show in viewer" for other positioned records (8.178), and an actor role for "retrieved the source" or "modeller", which is grilled with other data-model work. No change: the photo hint line stays hidden in the compact card; `GetDescriptor` and `AddEvidence` keep reporting the first failure of a list in their own way. No repository change for the crontab: `crontab.example` is the tracked one and `uberspaceconfig/crontab/crontab` a gitignored local copy; the maintainer compares the crontab on the server with the example. | The hint would not fit the low row, and the Add button is disabled at the limit. The 14 days of the privacy page hold for the request log without cron, since `DailyFileHandler` deletes its older files; the crontab line covers the cron and deploy logs. | **Facts confirmed (user, 2026-09-28):** the 35 ZirKuS reinforcement bars were modelled after the From 19881cdb2a1f4a5243c9284649e54d85e236499b Mon Sep 17 00:00:00 2001 From: fstwn Date: Wed, 4 Nov 2026 16:13:32 +0100 Subject: [PATCH 4/9] docs: standing rules in AGENTS.md, CLAUDE.md imports it --- AGENTS.md | 13 +++++++++++++ CLAUDE.md | 1 + 2 files changed, 14 insertions(+) create mode 100644 CLAUDE.md diff --git a/AGENTS.md b/AGENTS.md index c7211f44..9e9f9228 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -2,6 +2,19 @@ Guidance for coding agents working in this repository. +## Standing rules + +- The maintainer makes every commit, push and production step. Do not stage, commit, push or run anything against + production; leave changes in the working tree and give the commands. Commit messages stay inline in the command. +- ASCII only in code and scripts, no emoji. In docs, write dashes as `--` and `---`. Icons come from `lucide-react`. +- No names of people or accounts in committed files; refer to roles. The legal pages and the author line of the + Grasshopper user objects are the exceptions. +- Packages must be about two weeks old: no dependency, action or lockfile entry younger than about 14 days. +- In user-facing text a single building component is an "element", and a recorded state is a "version".,e . +- Several docs and sources use CRLF. Keep the line ending of the file you edit. +- The root `README.md` states rules plainly, without decision references. Those belong in `docs/adr/`. +- The decision log `docs/adr/DESIGN_DECISIONS.md` is append-only: amend a row with an "Amended ..." sentence. + ## Agent skills ### Issue tracker diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 00000000..43c994c2 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1 @@ +@AGENTS.md From 0fc9061f6ced9a86180e9cd08facac45131a32e7 Mon Sep 17 00:00:00 2001 From: fstwn Date: Sun, 8 Nov 2026 19:44:28 +0100 Subject: [PATCH 5/9] chore(release): bump version to 0.6.4.5 (web and backend only) --- VERSION | 2 +- src/backend/csc_version.py | 2 +- src/frontend/package-lock.json | 4 ++-- src/frontend/package.json | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/VERSION b/VERSION index 472f35f1..db8fc124 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.6.4.4 +0.6.4.5 diff --git a/src/backend/csc_version.py b/src/backend/csc_version.py index 16ea2ebb..dc603e07 100644 --- a/src/backend/csc_version.py +++ b/src/backend/csc_version.py @@ -6,7 +6,7 @@ against VERSION, package.json and the release tag by scripts/ci/check_version.py. """ -CSC_VERSION = '0.6.4.4' +CSC_VERSION = '0.6.4.5' def release_tag(version: str = CSC_VERSION) -> str: diff --git a/src/frontend/package-lock.json b/src/frontend/package-lock.json index 2b9615ce..836a7996 100644 --- a/src/frontend/package-lock.json +++ b/src/frontend/package-lock.json @@ -1,12 +1,12 @@ { "name": "csc-frontend", - "version": "0.6.4.4", + "version": "0.6.4.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "csc-frontend", - "version": "0.6.4.4", + "version": "0.6.4.5", "dependencies": { "@radix-ui/react-accordion": "^1.2.12", "@radix-ui/react-checkbox": "^1.3.3", diff --git a/src/frontend/package.json b/src/frontend/package.json index 51af5ad6..d56f7ac6 100644 --- a/src/frontend/package.json +++ b/src/frontend/package.json @@ -1,6 +1,6 @@ { "name": "csc-frontend", - "version": "0.6.4.4", + "version": "0.6.4.5", "private": true, "scripts": { "dev": "next dev", From 8c201653d4b084adb4f7683c9a85c5fd552bef52 Mon Sep 17 00:00:00 2001 From: fstwn Date: Sun, 8 Nov 2026 19:44:36 +0100 Subject: [PATCH 6/9] fix(backend): a withdrawn component stays out of circulation, open-snapshot flags, move and delete, revoke by moderators (#46, #47, #48, #49, #50) User text follows the data model: component, snapshot, component id. New API fields has_open_snapshot and identity_withdrawn; MCP tools list_snapshots and get_snapshot. Index on component_snapshots identity_id and status. --- scripts/import/recreate/recreate_common.py | 2 +- src/backend/apps/catalog/api/access.py | 43 +- src/backend/apps/catalog/api/actors.py | 2 +- .../apps/catalog/api/catalog_common.py | 6 +- src/backend/apps/catalog/api/catalog_list.py | 28 +- src/backend/apps/catalog/api/change_log.py | 2 +- src/backend/apps/catalog/api/datasets.py | 20 +- src/backend/apps/catalog/api/evidence.py | 28 +- .../apps/catalog/api/evidence_attachments.py | 11 +- .../apps/catalog/api/evidence_lifecycle.py | 1 + .../apps/catalog/api/evidence_service.py | 40 +- src/backend/apps/catalog/api/history.py | 4 +- src/backend/apps/catalog/api/identities.py | 61 ++- src/backend/apps/catalog/api/identity_edit.py | 127 ++++-- .../apps/catalog/api/identity_filters.py | 12 +- .../apps/catalog/api/identity_lifecycle.py | 18 +- .../apps/catalog/api/identity_query.py | 2 +- .../apps/catalog/api/identity_workflows.py | 16 +- .../apps/catalog/api/idtransmission.py | 22 +- src/backend/apps/catalog/api/invitations.py | 4 +- src/backend/apps/catalog/api/materials.py | 4 +- src/backend/apps/catalog/api/schema_routes.py | 2 +- .../apps/catalog/api/snapshot_lifecycle.py | 42 +- .../apps/catalog/api/snapshot_media.py | 10 +- src/backend/apps/catalog/api/snapshots.py | 10 +- src/backend/apps/catalog/documents.py | 24 +- src/backend/apps/catalog/evidence/payloads.py | 6 +- src/backend/apps/catalog/evidence/registry.py | 2 +- src/backend/apps/catalog/evidence/specs.py | 12 +- src/backend/apps/catalog/exports/cero.py | 2 +- src/backend/apps/catalog/exports/pdf.py | 6 +- src/backend/apps/catalog/lineage.py | 2 +- src/backend/apps/catalog/mcp_server.py | 86 ++-- src/backend/apps/catalog/models.py | 40 +- src/backend/apps/catalog/permissions.py | 5 +- src/backend/apps/catalog/proxies/fit.py | 2 +- src/backend/apps/catalog/read_models.py | 49 ++- src/backend/apps/catalog/vocab.py | 32 +- src/backend/main_fastapi.py | 4 + .../templates/mail/dataset_created.html.j2 | 2 +- .../templates/mail/dataset_created.txt.j2 | 2 +- tests/api/test_exports_routes.py | 2 +- tests/api/test_invitation_accept.py | 11 +- tests/api/test_loaders.py | 4 +- tests/api/test_mcp_endpoint.py | 56 +-- tests/api/test_move_identity.py | 257 ++++++++++++ tests/api/test_my_snapshots.py | 37 ++ tests/api/test_no_piece_in_user_text.py | 4 +- tests/api/test_open_flags.py | 328 +++++++++++++++ tests/api/test_withdrawn_refusals.py | 390 ++++++++++++++++++ tests/catalog/test_evidence_registry.py | 23 ++ tests/catalog/test_exports.py | 2 +- tests/catalog/test_permissions.py | 3 +- tests/fixtures/data_model_examples.json | 2 +- tests/grasshopper/test_signin.py | 5 +- 55 files changed, 1594 insertions(+), 323 deletions(-) create mode 100644 tests/api/test_move_identity.py create mode 100644 tests/api/test_open_flags.py create mode 100644 tests/api/test_withdrawn_refusals.py diff --git a/scripts/import/recreate/recreate_common.py b/scripts/import/recreate/recreate_common.py index 44fa60b6..f377226b 100644 --- a/scripts/import/recreate/recreate_common.py +++ b/scripts/import/recreate/recreate_common.py @@ -28,7 +28,7 @@ # the places of the local rehearsal (arguments of every script) DEFAULT_DATA = DOT_DEV / 'open_datasets' / 'recreate' / 'zenodo-16809738' DEFAULT_OUT = DOT_DEV / 'import_open' / 'recreate' / 'out' -DEFAULT_ASSETS = DOT_DEV / 'assets-261012' +DEFAULT_ASSETS = DOT_DEV / 'assets' DEFAULT_MONGO_URI = 'mongodb://127.0.0.1:27791' DEFAULT_SERVER = 'http://127.0.0.1:8791' diff --git a/src/backend/apps/catalog/api/access.py b/src/backend/apps/catalog/api/access.py index 2c8c00a9..18febf96 100644 --- a/src/backend/apps/catalog/api/access.py +++ b/src/backend/apps/catalog/api/access.py @@ -34,6 +34,7 @@ record_projection, withdrawn_projection, ) +from apps.catalog.vocab import OPEN_STATUSES NOT_PUBLIC = 'This component is not public. Sign in to view it.' NO_ACCESS = 'You have no access to this component.' @@ -116,7 +117,7 @@ async def identity_ever_published(request: Request, UNREVIEWED = ('This dataset has not been reviewed by an admin yet: it stays ' - 'visible to its members only, and its elements cannot be made ' + 'visible to its members only, and its components cannot be made ' 'public until it is reviewed.') @@ -128,6 +129,32 @@ def refuse_unreviewed(dataset: Dataset, viewer: Viewer) -> None: raise HTTPException(status_code=409, detail=UNREVIEWED) +def may_know_open(viewer: Viewer, dataset: Dataset) -> bool: + """Who is told that a version or a correction is open (8.195): a + contributor or a moderator of the dataset, and the admins (``dataset_roles`` + gives an admin every role). A member who only reviews, and everyone else, + gets a constant False for ``has_open_snapshot`` and ``has_open_correction`` + and costs no query. The one place the audience is decided.""" + return bool(dataset_roles(viewer, dataset) & {'contributor', 'moderator'}) + + +async def has_open_snapshot(request: Request, viewer: Viewer, + identity: Dict[str, Any]) -> bool: + """``has_open_snapshot`` (8.195): a draft or pending version of the element + exists (I3b, the one open version). Only the fact, for whoever + ``may_know_open``; a draft is otherwise invisible to a contributor who is + not its author.""" + if not viewer.logged_in: + return False + dataset = await dataset_of(request, identity.get('dataset')) + if not may_know_open(viewer, dataset): + return False + found = await request.app.mongodb_component_snapshots.find_one( + {'identity_id': identity['_id'], + 'status': {'$in': list(OPEN_STATUSES)}}, {'_id': 1}) + return found is not None + + def deny_read(viewer: Viewer) -> HTTPException: if not viewer.logged_in: return HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, @@ -185,7 +212,7 @@ async def raise_if_purged(request: Request, record_id: str, async def find_identity(request: Request, identity_id: str, projection: Optional[Dict[str, int]] = None, - what: str = 'Identity') -> Dict[str, Any]: + what: str = 'Component') -> Dict[str, Any]: """The identity document; 404 / 410 when it is not there. No access check: ``load_identity`` is the entry for a route.""" check_id(identity_id, what) @@ -369,11 +396,13 @@ async def require(request: Request, user: Optional[User], action: str, *, snapshot: Optional[Dict[str, Any]] = None, evidence: Optional[Dict[str, Any]] = None, dataset: Optional[Dataset] = None, - invitation: Optional[Dict[str, Any]] = None) -> Viewer: + invitation: Optional[Dict[str, Any]] = None, + destination: Optional[Dataset] = None) -> Viewer: """ Section 7.0 for one action: builds the ``Target`` from the documents and raises 401 / 403 unless ``can`` allows it. Read access to the - component is part of every action on it. + component is part of every action on it. ``destination`` is the dataset + a move goes to. """ viewer = viewer_of(user) if snapshot is not None and identity is None: @@ -411,7 +440,7 @@ async def require(request: Request, user: Optional[User], action: str, *, dataset=dataset, kind=kind, status=status_, author_id=author, identity_published=published, reserved_by=(identity or {}).get('reserved') or None, - readable=readable, performer_ids=performers, + readable=readable, performer_ids=performers, destination=destination, correction=bool(kind == 'evidence' and evidence.get('supersedes'))) if not can(viewer, action, target): raise deny_write(viewer, action) @@ -538,7 +567,7 @@ async def load_evidence(request: Request, user: Optional[User], raise deny_read(viewer) -NO_CURRENT_STATE = 'The component has no current state.' +NO_CURRENT_STATE = 'The component has no current snapshot.' async def load_current_snapshot(request: Request, @@ -586,7 +615,7 @@ async def load_invitation(request: Request, user: Optional[User], """One invitation for a route (decision 8.158): 404 "Invitation not found". ``invite``: the caller's current invite permission on the invitation's dataset (an admin for one without a dataset); - ``revoke_invitation``: its creator, moderator(D) or an admin.""" + ``revoke_invitation``: moderator(D) or an admin (8.193 c).""" viewer = viewer_of(user) check_id(invitation_id, 'Invitation') doc = await request.app.mongodb_invitations.find_one( diff --git a/src/backend/apps/catalog/api/actors.py b/src/backend/apps/catalog/api/actors.py index cfc5d6ff..51f516f1 100644 --- a/src/backend/apps/catalog/api/actors.py +++ b/src/backend/apps/catalog/api/actors.py @@ -216,7 +216,7 @@ async def redact_actor( break else: raise HTTPException(status_code=409, detail=( - f'Identity {doc["_id"]} kept changing; run the redaction ' + f'Component {doc["_id"]} kept changing; run the redaction ' f'again.')) async for entry in log.find({}): diff --git a/src/backend/apps/catalog/api/catalog_common.py b/src/backend/apps/catalog/api/catalog_common.py index 83b0e192..d716b795 100644 --- a/src/backend/apps/catalog/api/catalog_common.py +++ b/src/backend/apps/catalog/api/catalog_common.py @@ -138,13 +138,13 @@ async def validate_parent_identities( if self_id and pid == self_id: raise HTTPException( status_code=400, - detail='identity cannot list itself in parent_identities', + detail='a component cannot list itself in parent_identities', ) found = await col.find_one({'_id': pid}, {'_id': 1}) if found is None: raise HTTPException( status_code=404, - detail=f'Parent identity {pid} not found', + detail=f'Parent component {pid} not found', ) @@ -205,7 +205,7 @@ async def validate_snapshot_and_promote( raise HTTPException( status_code=500, detail=( - f'Identity {identity_id} not found for snapshot {snapshot_id}' + f'Component {identity_id} not found for snapshot {snapshot_id}' ), ) diff --git a/src/backend/apps/catalog/api/catalog_list.py b/src/backend/apps/catalog/api/catalog_list.py index 5caa4021..c363b761 100644 --- a/src/backend/apps/catalog/api/catalog_list.py +++ b/src/backend/apps/catalog/api/catalog_list.py @@ -169,7 +169,7 @@ async def _visible_map_payload(request: Request, user: Optional[User], @router.get( '/identities/count', - summary='Count identities (current snapshot filters)', + summary='Count components (current snapshot filters)', response_model=ComponentCount, ) @local_limiter.limit(LIST_RATE, key_func=signed_in_or_ip) @@ -232,7 +232,7 @@ async def _candidate_ids(request: Request, args: Dict[str, Any], @router.get( '/identities/{identity_id}/similar', - summary='The elements nearest to one in descriptor space (kNN)', + summary='The components nearest to one in descriptor space (kNN)', ) @local_limiter.limit(LIST_RATE, key_func=signed_in_or_ip) async def get_similar_identities( @@ -247,13 +247,13 @@ async def get_similar_identities( count: int = Query(10, ge=1, le=sim.MAX_NEIGHBOURS, description='how many neighbours, 1 to 50'), ): - """The ``count`` elements nearest to this one in the full descriptor space + """The ``count`` components nearest to this one in the full descriptor space of ``basis`` (decision 8.174): Euclidean distance after each dimension is - standardised over the catalog (smaller is more similar). The elements ranked + standardised over the catalog (smaller is more similar). The components ranked are those this caller may see that pass the filters of the list (also a dimension and a near search): the filters come first, then the ranking, so "similar and can hold X and within 50 km" returns the k nearest that pass. - The element itself is never one of them. An element the caller cannot see is + The component itself is never one of them. A component the caller cannot see is 404; one without the descriptor of the basis is 422; before the matrix of the basis has been computed (``main_component_map.py``) the answer is 409.""" @@ -364,15 +364,15 @@ async def get_identities_locations( current_user: Annotated[Optional[User], Depends(get_optional_current_user)], filters: Annotated[CatalogFilters, Depends(catalog_filters)], layer: NearLayer = Query( - 'current', description='which place of an element is a point: ' + 'current', description='which place of a component is a point: ' 'current (the location of the current ' - 'version) or origin (the origin building)'), + 'snapshot) or origin (the origin building)'), ): - """Every element this caller may see that matches the filters and has a + """Every component this caller may see that matches the filters and has a point on the layer (decisions 8.170, 8.171), with what the map colours - and labels it by; the elements without a point are only counted + and labels it by; the components without a point are only counted (``left_out``). The filters, the visibility and a near or fit search are - those of the list. An element never appears for someone who may not see it, + those of the list. A component never appears for someone who may not see it, and neither does it count.""" if current_user is None: filters = public_filters(filters) @@ -601,7 +601,7 @@ def _with_location(facet) -> Dict[str, int]: '/identities/stats', summary=( 'Aggregated catalog statistics ' - '(identities joined to current snapshots)' + '(components joined to current snapshots)' ), ) @local_limiter.limit(LIST_RATE, key_func=signed_in_or_ip) @@ -611,7 +611,7 @@ async def get_identities_stats( filters: Annotated[CatalogFilters, Depends(catalog_filters)], limit_dim: int = Query(10, description='Top-N limit for long tail dims'), ): - """Facet counts over the filtered catalog (identity + current snapshot).""" + """Facet counts over the filtered catalog (component + current snapshot).""" if current_user is None: filters = public_filters(filters) try: @@ -681,7 +681,7 @@ def topn(items): @router.get( '/identities', - summary='List identities (join current snapshot)', + summary='List components (join current snapshot)', ) @local_limiter.limit(LIST_RATE, key_func=signed_in_or_ip) async def list_identities_route( @@ -692,7 +692,7 @@ async def list_identities_route( size: int = Query(0, description='Page size (0=get all)'), sortkey: Optional[str] = Query( None, description='Sort key; volume = the product of the three bbx ' - 'sides (an element without bbx last); match = the ' + 'sides (a component without bbx last); match = the ' 'closeness to the dimension search (needs ' 'fit_mode); distance = the distance to the near ' 'point (needs near_lat and near_lon). Default: ' diff --git a/src/backend/apps/catalog/api/change_log.py b/src/backend/apps/catalog/api/change_log.py index 22fc5fb2..bcd6bc74 100644 --- a/src/backend/apps/catalog/api/change_log.py +++ b/src/backend/apps/catalog/api/change_log.py @@ -99,7 +99,7 @@ async def list_changes( identity_id: str, limit: int = Query(200, ge=1, le=1000), ): - """Entries of the identity, its snapshots and evidence, newest first. + """Entries of the component, its snapshots and evidence, newest first. Old values may name people, so the log is for members only (8.36).""" await load_identity(request, current_user, identity_id, 'view_history') entries = await request.app.mongodb_change_log.find( diff --git a/src/backend/apps/catalog/api/datasets.py b/src/backend/apps/catalog/api/datasets.py index 4515f51f..a69c16cd 100644 --- a/src/backend/apps/catalog/api/datasets.py +++ b/src/backend/apps/catalog/api/datasets.py @@ -121,7 +121,7 @@ class DatasetView(BaseModel): 'moderator(D) and admin only, else absent') component_count: Optional[int] = Field( default=None, - description='list rows only: published elements the caller may see') + description='list rows only: published components the caller may see') model_config = {'populate_by_name': True} @@ -144,7 +144,7 @@ class DatasetPatch(BaseModel): visibility: Optional[Visibility] = None reviewed: Optional[bool] = Field( None, description='admin only: the dataset may be catalog and its ' - 'elements public (8.139)') + 'components public (8.139)') class MemberRoles(BaseModel): @@ -569,7 +569,7 @@ async def put_dataset_member( class PublicBody(BaseModel): model_config = ConfigDict(extra='forbid') - is_public: bool = Field(description='the flag to set on the elements') + is_public: bool = Field(description='the flag to set on the components') dry_run: bool = Field(False, description='only count what would change') @@ -584,7 +584,7 @@ class PublicResult(BaseModel): @router.post('/datasets/{did}/public', response_model=PublicResult, - summary='Make every published element of a dataset public or ' + summary='Make every published component of a dataset public or ' 'private (moderator(D))') async def set_dataset_public( request: Request, @@ -592,10 +592,10 @@ async def set_dataset_public( did: str, body: PublicBody, ): - """Sets ``is_public`` on the elements of the dataset that were ever + """Sets ``is_public`` on the components of the dataset that were ever published (3.1.5) and are not withdrawn, where the flag differs, and logs each change like a metadata PATCH (``cause: patch``). Unpublished and - withdrawn elements are left alone, and so are children: no element follows + withdrawn components are left alone, and so are children: no component follows another (6.2). ``dry_run`` only counts.""" dataset = (await load_dataset(request, current_user, did, 'set_dataset_public')).record @@ -627,7 +627,7 @@ async def set_dataset_public( invalid[identity['_id']] = str(exc.detail) if invalid: raise HTTPException(status_code=422, detail={ - 'message': f'{len(invalid)} of {len(pieces)} elements do not pass ' + 'message': f'{len(invalid)} of {len(pieces)} components do not pass ' f'validation; nothing was changed. Correct them first.', 'pieces': invalid}) changed = skipped = 0 @@ -655,8 +655,8 @@ async def delete_dataset( current_user: Annotated[User, Depends(get_current_active_user)], did: str, ): - """Only while the dataset holds no element at all (no identity, whatever - its state; for an admin too: move the elements first, ``move_identity``). + """Only while the dataset holds no component at all (no component, whatever + its state; for an admin too: move the components first, ``move_identity``). The open invitations into it are revoked with it (8.139 f).""" await load_dataset(request, current_user, did, 'delete_dataset') pieces = await request.app.mongodb_component_identities.count_documents( @@ -664,7 +664,7 @@ async def delete_dataset( if pieces: raise HTTPException( status_code=409, - detail='The dataset still holds elements: move them to another ' + detail='The dataset still holds components: move them to another ' 'dataset first.') now = now_iso() revoked = await request.app.mongodb_invitations.update_many( diff --git a/src/backend/apps/catalog/api/evidence.py b/src/backend/apps/catalog/api/evidence.py index e3b84028..dba6dee6 100644 --- a/src/backend/apps/catalog/api/evidence.py +++ b/src/backend/apps/catalog/api/evidence.py @@ -73,6 +73,7 @@ require_contributor, gate_identity, new_evidence_doc, + open_corrections, prepare, viewer_context, ) @@ -347,7 +348,7 @@ async def list_identity_evidence( 'whole day)'), status: str = Query('published', description='a status, or all'), include: Optional[str] = Query( - None, description='comma list: context (the state of the element each ' + None, description='comma list: context (the snapshot of the component each ' 'record belongs to), superseded (corrected ones)'), ): """Published, non-superseded records by default; what the caller may @@ -370,6 +371,8 @@ async def list_identity_evidence( raise HTTPException(status_code=500, detail='Internal server error') viewer = viewer_of(current_user) project = await _projector(request, viewer, identity) + # which records have a correction open: one query for the list (8.195) + open_ids = await open_corrections(request, viewer, identity) snapshots = None if 'context' in flags: snapshots = await request.app.mongodb_component_snapshots.find( @@ -383,7 +386,8 @@ async def list_identity_evidence( if seen == 'full': items.append(await evidence_body( request, viewer, doc, identity, listing=True, - with_context='context' in flags, snapshots=snapshots)) + with_context='context' in flags, snapshots=snapshots, + open_correction=doc['_id'] in (open_ids or ()))) elif seen == 'tombstone': items.append(evidence_tombstone(doc, identity)) return JSONResponse(status_code=200, content=items) @@ -584,20 +588,26 @@ async def get_evidence( return JSONResponse(status_code=200, content=project_evidence( rolled, tier, email_ok=email_ok)) with_context = 'context' in {p.strip() for p in (include or '').split(',')} + open_ids = await open_corrections(request, viewer, identity) + open_correction = record['_id'] in (open_ids or ()) if with_context: # the context follows the snapshots, not the record: never a 304 body = await evidence_body(request, viewer, record, identity, - with_context=True) + with_context=True, + open_correction=open_correction) return JSONResponse(status_code=200, content=body, headers={ 'Cache-Control': 'no-store', 'Vary': 'Authorization'}) tier, email_ok = await viewer_context(request, viewer, identity) etag = hashlib.sha256('::'.join([ - record.get('etag') or '', tier, str(email_ok)]).encode( + record.get('etag') or '', tier, str(email_ok), + # a correction someone opens does not touch the record (8.195) + 'open' if open_correction else '']).encode( 'utf-8')).hexdigest() if request.headers.get('if-none-match') == etag: return not_modified_response(etag, **viewer_headers( cache_control='private, max-age=0')) - body = await evidence_body(request, viewer, record, identity) + body = await evidence_body(request, viewer, record, identity, + open_correction=open_correction) return JSONResponse(status_code=200, content=body, headers=viewer_headers( etag=etag, cache_control='private, max-age=0')) @@ -625,14 +635,14 @@ async def get_identity_properties( @router.get('/snapshots/{snapshot_id}/properties', - summary='Properties of one state of a component') + summary='Properties of one snapshot of a component') async def get_snapshot_properties( request: Request, current_user: Annotated[Optional[User], Depends(get_optional_current_user)], snapshot_id: str, ): """The snapshot block (the materialized as-of fold): the snapshot-scoped - quantities whose records resolve to this state.""" + quantities whose records resolve to this snapshot.""" snapshot = (await load_snapshot(request, current_user, snapshot_id, allow_tombstone=True)).record return JSONResponse(status_code=200, content={ @@ -648,9 +658,9 @@ async def get_timeline( current_user: Annotated[Optional[User], Depends(get_optional_current_user)], identity_id: str, ): - """Archived cycles, the origin, every state and correction, every + """Archived cycles, the origin, every snapshot and correction, every evidence record (where it falls: before cataloguing, in the history, - after the element left circulation), changes of the metadata and the exit. + after the component left circulation), changes of the metadata and the exit. What the caller may not see is left out; a withdrawn record outside the dataset is a bare row; outside the dataset a metadata change shows only its date (8.36).""" diff --git a/src/backend/apps/catalog/api/evidence_attachments.py b/src/backend/apps/catalog/api/evidence_attachments.py index eff67c81..c0cd4eb1 100644 --- a/src/backend/apps/catalog/api/evidence_attachments.py +++ b/src/backend/apps/catalog/api/evidence_attachments.py @@ -150,11 +150,16 @@ async def attach_file( detail=f'record_ids: 1 to {MAX_RECORDS} records') records = [] for rid in ids: - record = (await load_evidence(request, current_user, rid, - 'add_attachment')).record + loaded = await load_evidence(request, current_user, rid, + 'add_attachment') + record = loaded.record if record.get('status') == 'withdrawn': raise HTTPException(status_code=409, detail=f'{rid} is withdrawn.') + if (loaded.identity or {}).get('withdrawn'): + # any record of a withdrawn element, an admin too (8.190) + raise HTTPException(status_code=409, + detail='The component is withdrawn.') if len(record.get('attachments') or []) \ >= evidence_files.MAX_ATTACHMENTS: raise HTTPException( @@ -221,7 +226,7 @@ async def list_attachments( evidence_id: str, ): """The list as the viewer may see it. Anonymous readers of a public - element get media type, size, checksum and date --- no names, no + component get media type, size, checksum and date --- no names, no uploaders --- and "sign in to download" (8.13).""" loaded = await load_evidence(request, current_user, evidence_id, allow_tombstone=True) diff --git a/src/backend/apps/catalog/api/evidence_lifecycle.py b/src/backend/apps/catalog/api/evidence_lifecycle.py index 89def52a..a70947ad 100644 --- a/src/backend/apps/catalog/api/evidence_lifecycle.py +++ b/src/backend/apps/catalog/api/evidence_lifecycle.py @@ -340,6 +340,7 @@ async def reinstate_evidence( loaded = await load_evidence(request, current_user, evidence_id, 'reinstate') record, identity = loaded.record, loaded.identity + gate_identity(identity) # a withdrawn element takes no step forward (8.190) _step(record, 'reinstate', 'published') predecessor = record.get('supersedes') old = None diff --git a/src/backend/apps/catalog/api/evidence_service.py b/src/backend/apps/catalog/api/evidence_service.py index de5d43b1..d1100b56 100644 --- a/src/backend/apps/catalog/api/evidence_service.py +++ b/src/backend/apps/catalog/api/evidence_service.py @@ -50,6 +50,7 @@ ) from apps.catalog.properties import contexts_for from apps.catalog.vocab import ( + OPEN_STATUSES, TERMINAL_EXIT_KINDS, EvidenceMethod, PositionKind, @@ -58,7 +59,8 @@ UncertaintyType, ) from apps.catalog.timeutil import parse_ts -from .access import component_visible, dataset_of, require, viewer_of +from .access import ( + component_visible, dataset_of, may_know_open, require, viewer_of) from .catalog_common import now_iso MAX_BULK = 200 @@ -67,7 +69,7 @@ # WHAT A CLIENT SENDS --------------------------------------------------------- class PositionInput(BaseModel): - """Where on the element (3.3.2). ``kind: none`` with a description is + """Where on the component (3.3.2). ``kind: none`` with a description is always enough; a point is picked on the 3D viewer and needs the snapshot whose stored coordinates it uses.""" model_config = ConfigDict(extra='forbid') @@ -82,7 +84,7 @@ class PositionInput(BaseModel): None, description='Picked point in stored coordinates; for a rebound ' 'grid the server sets the grid centre') description: Optional[str] = Field( - None, description='Where on the element, in words, e.g. "north face, ' + None, description='Where on the component, in words, e.g. "north face, ' 'mid-span"') @@ -209,6 +211,10 @@ class EvidenceView(Evidence): the state of the piece it belongs to (4.1).""" warnings: List[str] = Field(default_factory=list) context: Optional[ContextView] = None + # response-only (8.195): a draft or pending correction of this record is + # open. Only the fact, for a contributor or moderator of the dataset and + # admins; a constant False for everyone else. Not in the exports. + has_open_correction: bool = False # ERRORS ---------------------------------------------------------------------- @@ -254,16 +260,21 @@ async def evidence_body(request: Request, viewer: Viewer, record: Dict[str, Any], identity: Dict[str, Any], *, listing: bool = False, with_context: bool = False, snapshots: Optional[List[Dict[str, Any]]] = None, - context: Optional[Tuple[str, bool]] = None + context: Optional[Tuple[str, bool]] = None, + open_correction: Optional[bool] = None ) -> Dict[str, Any]: """The record as ``viewer`` sees it, validated against the model. - ``context`` is ``viewer_context`` when a list has it already.""" + ``context`` is ``viewer_context`` when a list has it already. + ``open_correction`` is ``has_open_correction`` (8.195); the field is in + the body only when a route asks for it, so the exports do not carry it.""" tier, email_ok = context or await viewer_context(request, viewer, identity) stored = Evidence.model_validate(record).model_dump(by_alias=True, mode='json') body = project_evidence(stored, tier, email_ok=email_ok, listing=listing) body['warnings'] = record_warnings(record) + if open_correction is not None: + body['has_open_correction'] = open_correction body['context'] = None if with_context: if snapshots is None: @@ -277,6 +288,23 @@ async def evidence_body(request: Request, viewer: Viewer, return body +async def open_corrections(request: Request, viewer: Viewer, + identity: Dict[str, Any]) -> Optional[set]: + """The ids of the records of one element that have a draft or pending + correction, for ``has_open_correction`` (8.195): one ``distinct`` per + request, never a query per record. None when the viewer is not told + (``may_know_open``): the flag is then a constant False.""" + if not viewer.logged_in: + return None + if not may_know_open(viewer, await dataset_of(request, + identity.get('dataset'))): + return None + return set(await request.app.mongodb_component_evidence.distinct( + 'supersedes', {'identity_id': identity['_id'], + 'supersedes': {'$ne': None}, + 'status': {'$in': list(OPEN_STATUSES)}})) + + async def projector(request: Request, viewer: Viewer, identity: Dict[str, Any]): """A function ``record -> 'full' | 'tombstone' | None`` for the records @@ -334,7 +362,7 @@ def gate_identity(identity: Dict[str, Any], and parse_ts(observed_at) > parse_ts(exit_['at']): raise HTTPException( status_code=409, - detail=f'The component no longer exists as this element ' + detail=f'The component no longer exists as this component ' f'({exit_["kind"]}, {exit_["at"]}): only observations ' f'from before that date are recorded (I28).') diff --git a/src/backend/apps/catalog/api/history.py b/src/backend/apps/catalog/api/history.py index abccd168..d1375652 100644 --- a/src/backend/apps/catalog/api/history.py +++ b/src/backend/apps/catalog/api/history.py @@ -126,11 +126,11 @@ async def get_identity_history( 'groups', description='groups: evidence per day and method; all: ' 'every record its own event'), ): - """The element is the middle lane (level 0), parents have negative levels + """The component is the middle lane (level 0), parents have negative levels and children positive ones. Every lane has ``id``, ``role``, ``level`` and ``visible``; a visible one also its header and ``events``. ``links`` join a parent and a child lane (``cut``: one parent; ``assemble``: - several) at the child's first version. ``more`` counts the lanes left + several) at the child's first snapshot. ``more`` counts the lanes left out beyond twelve.""" viewer = viewer_of(current_user) root = (await load_identity( diff --git a/src/backend/apps/catalog/api/identities.py b/src/backend/apps/catalog/api/identities.py index 9bdd2830..ce1f8c58 100644 --- a/src/backend/apps/catalog/api/identities.py +++ b/src/backend/apps/catalog/api/identities.py @@ -52,6 +52,7 @@ and_match, dataset_of, deny_read, + has_open_snapshot, load_current_snapshot, load_identity, require, @@ -166,7 +167,7 @@ async def _resolve_passport_snapshot_docs( if not docs: raise HTTPException( status_code=404, - detail=f'No snapshots found for identity {identity_id}', + detail=f'No snapshots found for component {identity_id}', ) elif mode == 'ids': docs = [] @@ -182,7 +183,7 @@ async def _resolve_passport_snapshot_docs( raise HTTPException( status_code=404, detail=( - f'Snapshot {snapshot_id} does not belong to identity ' + f'Snapshot {snapshot_id} does not belong to component ' f'{identity_id}' ), ) @@ -216,10 +217,13 @@ def passport_json( user: Optional[User] = None, remaining: Optional[int] = None, can_undo_deinstall: bool = False, + has_open: Optional[bool] = None, ) -> Dict[str, Any]: """The passport body as ``user`` may see it (people stripped for an anonymous caller, 8.101): what compose answers, and the base of every - export (JSON-LD, CERO, PDF; 8.116 f).""" + export (JSON-LD, CERO, PDF; 8.116 f). ``has_open`` is the flag + ``has_open_snapshot`` of compose (8.195); without it the field is not in + the body, which keeps it out of the exports.""" try: body = passport_body(identity_doc, snapshot_docs) except Exception as exc: @@ -227,6 +231,8 @@ def passport_json( if remaining is not None: # a batch (8.105) body['identity']['remaining'] = remaining body['identity']['can_undo_deinstall'] = can_undo_deinstall + if has_open is not None: + body['identity']['has_open_snapshot'] = has_open if evidence is not None: # ?include=evidence (7.2) body['evidence'] = evidence return for_viewer(body, user) @@ -243,11 +249,13 @@ def _passport_response( user: Optional[User] = None, remaining: Optional[int] = None, can_undo_deinstall: bool = False, + has_open: Optional[bool] = None, ) -> JSONResponse: response_body = passport_json(identity_doc, snapshot_docs, evidence=evidence, user=user, remaining=remaining, - can_undo_deinstall=can_undo_deinstall) + can_undo_deinstall=can_undo_deinstall, + has_open=has_open) resolved_etag = etag or viewer_etag( _compute_passport_etag(identity_doc, snapshot_docs, remaining), user) return JSONResponse( @@ -260,7 +268,7 @@ def _passport_response( @router.get( '/identities/{identity_id}/children', - summary='List identities that list this identity as a parent', + summary='List components that list this component as a parent', ) async def list_identity_children( request: Request, @@ -409,7 +417,7 @@ async def _collect_lineage_identity_docs( @router.get( '/identities/{identity_id}/provenance', - summary='Lineage graph of related identities and snapshots', + summary='Lineage graph of related components and snapshots', ) async def get_identity_provenance( request: Request, @@ -423,8 +431,8 @@ async def get_identity_provenance( ), ): """ - Walk ``parent_identities`` up and down from this identity, then attach - each identity's snapshot versions. Anonymous callers who can read a + Walk ``parent_identities`` up and down from this component, then attach + each component's snapshots. Anonymous callers who can read a public root only see public relatives. """ identity_doc = (await load_identity( @@ -488,7 +496,7 @@ async def get_identity_provenance( @router.get( '/identities/{identity_id}/snapshots', - summary='List snapshot versions for an identity (summary rows)', + summary='List the snapshots of a component (summary rows)', response_model=List[SnapshotSummaryItem], response_model_by_alias=True, ) @@ -497,7 +505,7 @@ async def list_identity_snapshots( current_user: Annotated[Optional[User], Depends(get_optional_current_user)], identity_id: str, ): - """Return all snapshots for one identity, ordered by version ascending.""" + """Return all snapshots of one component, ordered by their number.""" identity_doc = (await load_identity( request, current_user, identity_id, projection={'_id': 1, 'current_snapshot_id': 1, 'is_public': 1})).record @@ -570,7 +578,7 @@ async def _identity_as_of(request: Request, user: Optional[User], @router.get( '/identities/{identity_id}', - summary='Get one identity (shallow, passport, or identity-only)', + summary='Get one component (shallow, passport, or without snapshots)', ) async def get_identity( request: Request, @@ -584,7 +592,7 @@ async def get_identity( ), ), as_of: Optional[str] = Query( - None, description='the identity as it was at this ISO date ' + None, description='the component as it was at this ISO date ' '(members of D and admin; section 3.8)'), ): identity_doc = (await load_identity(request, current_user, @@ -612,6 +620,8 @@ async def get_identity( body['remaining'] = pieces_left body['can_undo_deinstall'] = await _can_undo_deinstall( request, identity_doc, current_user) + body['has_open_snapshot'] = await has_open_snapshot( + request, viewer_of(current_user), identity_doc) return JSONResponse( status_code=200, content=for_viewer(body, current_user), @@ -620,9 +630,11 @@ async def get_identity( current_snapshot_id = identity_doc.get('current_snapshot_id') if not current_snapshot_id: # no published snapshot (8.17) - return _passport_response(identity_doc, [], - anonymous_public=anonymous_public, - user=current_user) + return _passport_response( + identity_doc, [], anonymous_public=anonymous_public, + user=current_user, + has_open=await has_open_snapshot( + request, viewer_of(current_user), identity_doc)) pieces_left = await remaining_of(request, identity_doc) snapshot_doc = await load_current_snapshot(request, identity_doc) await refresh_snapshot_photo_count( @@ -634,6 +646,8 @@ async def get_identity( anonymous_public=anonymous_public, user=current_user, remaining=pieces_left, + has_open=await has_open_snapshot( + request, viewer_of(current_user), identity_doc), ) @@ -668,6 +682,7 @@ class PassportRead: etag: str anonymous_public: bool can_undo_deinstall: bool = False + has_open_snapshot: bool = False async def read_passport( @@ -712,6 +727,12 @@ async def read_passport( if can_undo: # a later record can close the undo without changing the identity etag = hashlib.sha256(f'{etag}::undo'.encode('utf-8')).hexdigest() + open_snapshot = await has_open_snapshot(request, viewer_of(current_user), + identity_doc) + if open_snapshot: + # a draft someone else opens changes neither the identity nor the + # versions shown, so a 304 would hand back a stale False (8.195) + etag = hashlib.sha256(f'{etag}::open'.encode('utf-8')).hexdigest() evidence = None if 'evidence' in {part.strip() for part in (include or '').split(',')}: from .evidence_service import published_bodies, viewer_context @@ -729,7 +750,8 @@ async def read_passport( evidence=evidence, remaining=pieces_left, etag=viewer_etag(etag, current_user), anonymous_public=anonymous_public, - can_undo_deinstall=can_undo) + can_undo_deinstall=can_undo, + has_open_snapshot=open_snapshot) JSONLD_MEDIA_TYPE = 'application/ld+json' @@ -749,7 +771,7 @@ async def get_identity_passport( default=None, description=( 'Which snapshots to include: omitted or "current" = live ' - 'current_snapshot_id; "all" = every version; or one or more ' + 'current_snapshot_id; "all" = every snapshot; or one or more ' 'snapshot UUIDs (comma-separated).' ), ), @@ -773,8 +795,8 @@ async def get_identity_passport( Return ``{identity, snapshots[]}``. - Default / ``?snapshots=current``: live ``current_snapshot_id``. - - ``?snapshots=all``: every version (ascending by version). - - ``?snapshots=`` or comma-separated UUIDs: specific versions. + - ``?snapshots=all``: every snapshot (ascending by version). + - ``?snapshots=`` or comma-separated UUIDs: specific snapshots. - ``?format=jsonld``: the same body as JSON-LD (spec 7.8). """ read = await read_passport(request, current_user, identity_id, @@ -813,4 +835,5 @@ async def get_identity_passport( user=current_user, remaining=read.remaining, can_undo_deinstall=read.can_undo_deinstall, + has_open=read.has_open_snapshot, ) diff --git a/src/backend/apps/catalog/api/identity_edit.py b/src/backend/apps/catalog/api/identity_edit.py index 0c2355e5..65675156 100644 --- a/src/backend/apps/catalog/api/identity_edit.py +++ b/src/backend/apps/catalog/api/identity_edit.py @@ -60,6 +60,7 @@ from apps.catalog.vocab import ( INHERIT_UNITS, IN_PLACE_EXIT_KINDS, + OPEN_STATUSES, TERMINAL_EXIT_KINDS, ExitKind, OriginalFunction, @@ -73,6 +74,7 @@ identity_ever_published, load_datasets, load_identity, + require, viewer_of, ) from .auth import get_current_active_user @@ -140,6 +142,11 @@ class ReenterBody(_Strict): origin: Origin +class MoveBody(_Strict): + """The dataset a component moves to (8.191).""" + dataset: str + + class DeinstallBody(_Strict): """The act of deinstalling an in-place piece (8.104).""" at: Timestamp @@ -347,7 +354,7 @@ async def create_identity( each parent must be cuttable (8.8, 8.34). Every inheritance unit the body does not state is copied from the parents (3.1.2); a merge whose parents disagree on ``material`` or ``original_function`` needs them - stated. The identity stays unpublished until its v0 is published. + stated. The component stays unpublished until its v0 is published. """ from .snapshot_lifecycle import ( # the snapshot module imports this one SnapshotDraftBody, @@ -355,11 +362,11 @@ async def create_identity( ) viewer = viewer_of(current_user) identity_id = body.id or str(uuid.uuid4()) - validate_uuid(identity_id, label='identity id') + validate_uuid(identity_id, label='component id') identities = request.app.mongodb_component_identities if await identities.find_one({'_id': identity_id}, {'_id': 1}): raise HTTPException(status_code=409, - detail=f'Identity {identity_id} already exists') + detail=f'Component {identity_id} already exists') datasets = await load_datasets(request) if body.dataset not in datasets: raise HTTPException(status_code=422, @@ -367,14 +374,14 @@ async def create_identity( parents: List[Dict[str, Any]] = [] for pid in body.parent_identities or []: - validate_uuid(pid, label='parent identity id') + validate_uuid(pid, label='parent component id') if pid == identity_id: raise HTTPException(status_code=422, detail='A component is not its own parent.') parent = await identities.find_one({'_id': pid}) if parent is None: raise HTTPException(status_code=404, - detail=f'Parent identity {pid} not found') + detail=f'Parent component {pid} not found') parents.append(parent) readable = True for parent in parents: @@ -590,6 +597,14 @@ async def patch_identity( return JSONResponse(status_code=200, content=identity_body(written)) +def refuse_withdrawn(identity: Dict[str, Any]) -> None: + """A withdrawn element stays out of circulation (8.190): a moderator + reinstates it first.""" + if identity.get('withdrawn'): + raise HTTPException(status_code=409, + detail='The component is withdrawn.') + + # CIRCULATION ----------------------------------------------------------------- @router.post('/identities/{identity_id}/exit', summary='Take a component out of circulation (moderator(D))') @@ -600,13 +615,11 @@ async def exit_identity( body: ExitBody, ): """Installed, recycled, disposed, returned, lost --- or a hand-set - ``split`` without catalogued elements. ``merged`` is only ever set by the + ``split`` without catalogued components. ``merged`` is only ever set by the server (8.8). ``construction_work`` only for ``installed`` (I18).""" identity = (await load_identity(request, current_user, identity_id, 'exit')).record - if identity.get('withdrawn'): - raise HTTPException(status_code=409, detail='The component is ' - 'withdrawn.') + refuse_withdrawn(identity) if not await identity_ever_published(request, identity): raise HTTPException(status_code=409, detail='Not published yet: it never entered ' @@ -618,12 +631,12 @@ async def exit_identity( if body.kind == 'merged': raise HTTPException(status_code=422, detail='merged is set by the server when a ' - 'merged element is published (8.8).') + 'merged component is published (8.8).') if (identity.get('origin') or {}).get('planned') \ and body.kind not in IN_PLACE_EXIT_KINDS: raise HTTPException( status_code=409, - detail=f'An element still in place leaves as ' + detail=f'A component still in place leaves as ' f'{", ".join(IN_PLACE_EXIT_KINDS)} only; it never left ' f'its works, so it was not {body.kind}. Record its ' f'deinstallation first (8.104).') @@ -646,6 +659,7 @@ async def undo_exit( withdraw the child instead (8.8).""" identity = (await load_identity(request, current_user, identity_id, 'exit')).record + refuse_withdrawn(identity) exit_ = identity.get('exit') if not exit_: raise HTTPException(status_code=409, detail='The component is in ' @@ -653,7 +667,7 @@ async def undo_exit( if exit_.get('recorded_by_user_id') is None: raise HTTPException( status_code=409, - detail='This split / merge follows from published elements cut ' + detail='This split / merge follows from published components cut ' 'from it; withdraw those to undo it (8.8).') after = _validated({**identity, 'exit': None}) written = await _write(request, identity, after, @@ -671,20 +685,21 @@ async def reenter_identity( body: ReenterBody, ): """ - An installed, returned or lost element comes back with a new origin; the + An installed, returned or lost component comes back with a new origin; the old ``{origin, exit}`` goes to ``past_cycles`` (3.1.3). Terminal exits cannot re-enter (I18). The next snapshot defaults to the new ``origin.at`` (8.19). A re-entered child owns its new origin. """ identity = (await load_identity(request, current_user, identity_id, 'reenter')).record + refuse_withdrawn(identity) exit_ = identity.get('exit') if not exit_: raise HTTPException(status_code=409, detail='The component is in ' 'circulation.') if exit_.get('kind') in TERMINAL_EXIT_KINDS: raise HTTPException(status_code=409, - detail=f'A {exit_["kind"]} element no longer exists ' + detail=f'A {exit_["kind"]} component no longer exists ' f'as this component; it cannot re-enter ' f'(I18).') cycles = [*(identity.get('past_cycles') or []), @@ -703,6 +718,66 @@ async def reenter_identity( return JSONResponse(status_code=200, content=identity_body(written)) +# MOVE (decision 8.191) ------------------------------------------------------- +@router.post('/identities/{identity_id}/move', + summary='Move a component to another dataset (moderator of ' + 'both datasets)') +async def move_identity( + request: Request, + current_user: Annotated[User, Depends(get_current_active_user)], + identity_id: str, + body: MoveBody, +): + """ + Changes ``dataset`` on the component (the only place it is stored; catalog + numbers are global) and writes a change-log entry. ``move_identity``: + moderator of the source and of the destination dataset, an admin always. + A withdrawn component moves too, so that a dataset can be emptied and + deleted. 409 while a snapshot or an evidence record of the component is + draft or pending: the rights of its author hang on the dataset. A public + component does not move into a dataset an admin has not reviewed, unless an + admin moves it (8.139 c). Accepted as they are (8.191, amended): the + refusal looks at the component's own records only, so a child's pending + first snapshot does not block its parent; a rejected snapshot or record does + not block; a reservation survives the move. + """ + identity = (await load_identity(request, current_user, identity_id, + None)).record + datasets = await load_datasets(request) + source = await dataset_of(request, identity.get('dataset')) + destination = datasets.get(body.dataset) + # an unknown destination is checked against the source, so that a caller + # who may not move from it gets the 403 before any word about the target + viewer = await require(request, current_user, 'move_identity', + identity=identity, + destination=destination or source) + if destination is None: + raise HTTPException(status_code=422, + detail=f'dataset: unknown dataset {body.dataset!r}') + if destination.id == identity.get('dataset'): + raise HTTPException(status_code=409, + detail='The component is in this dataset ' + 'already.') + for name, collection in ( + ('version', request.app.mongodb_component_snapshots), + ('evidence record', request.app.mongodb_component_evidence)): + if await collection.count_documents( + {'identity_id': identity_id, 'status': {'$in': list( + OPEN_STATUSES)}}, limit=1): + raise HTTPException( + status_code=409, + detail=f'A {name} of the component is still draft or ' + f'pending; publish, reject or delete it first, ' + f'since the rights of its author hang on the dataset ' + f'(8.191).') + if identity.get('is_public') is True: + refuse_unreviewed(destination, viewer) # 8.139 c + after = _validated({**identity, 'dataset': destination.id}) + written = await _write(request, identity, after, + user_id=current_user.id, cause='patch') + return JSONResponse(status_code=200, content=identity_body(written)) + + # DEINSTALL (decisions 8.104, 8.110) ------------------------------------------ def _own_origin(identity: Dict[str, Any], origin: Dict[str, Any] ) -> Dict[str, Any]: @@ -739,7 +814,7 @@ async def _dated_after(request: Request, identity_id: str, at: str {'identity_id': identity_id, 'status': live}, {'effective_from': 1}).to_list(length=None) if any(_moment(s['effective_from']) > moment for s in snapshots): - return 'a state starts after the deinstallation' + return 'a snapshot starts after the deinstallation' records = await request.app.mongodb_component_evidence.find( {'identity_id': identity_id, 'status': live}, {'observed_at': 1, 'sampled_at': 1}).to_list(length=None) @@ -758,15 +833,17 @@ async def undo_deinstall_refusal(request: Request, identity: Dict[str, Any] act, 8.115 a) and no state or evidence is dated after it (8.104). The undo route answers 409 with this text; the passport carries ``can_undo_deinstall`` for the menu.""" + if identity.get('withdrawn'): + return 'The component is withdrawn.' origin = identity.get('origin') or {} if origin.get('planned') or origin.get('kind') not in ( 'deinstallation', 'demolition'): - return 'The element is not a deinstalled one.' + return 'The component is not a deinstalled one.' exit_ = identity.get('exit') if (exit_ and exit_.get('recorded_by_user_id') is not None and exit_.get('kind') not in IN_PLACE_EXIT_KINDS): - return (f'The element left as {exit_["kind"]}, which only a ' - f'deinstalled element can do (8.104).') + return (f'The component left as {exit_["kind"]}, which only a ' + f'deinstalled component can do (8.104).') if not origin.get('at'): return ('The deinstallation has no date; set the date by PATCH ' 'of the origin first (8.115).') @@ -783,7 +860,7 @@ async def undo_deinstall_refusal(request: Request, identity: Dict[str, Any] @router.post('/identities/{identity_id}/deinstall', - summary='Record the deinstallation of an in-place element ' + summary='Record the deinstallation of an in-place component ' '(moderator(D))') async def deinstall_identity( request: Request, @@ -794,7 +871,7 @@ async def deinstall_identity( """ ``planned`` becomes false and the given fields go into the existing origin; ``kind`` may switch to ``demolition``. A reservation survives; - no snapshot is created. The origin is now the element's own, and every + no snapshot is created. The origin is now the component's own, and every descendant that still inherits it follows, like a parent's PATCH of ``origin`` (3.1.2, 8.110). """ @@ -803,15 +880,13 @@ async def deinstall_identity( origin = identity.get('origin') or {} if not origin.get('planned'): raise HTTPException(status_code=409, - detail='The element is not in place; there is ' + detail='The component is not in place; there is ' 'nothing to deinstall.') - if identity.get('withdrawn'): - raise HTTPException(status_code=409, - detail='The component is withdrawn.') + refuse_withdrawn(identity) if (identity.get('exit') or {}).get('recorded_by_user_id') is not None: # a split the server keeps from cut pieces does not stop it raise HTTPException(status_code=409, - detail='The element left circulation while in ' + detail='The component left circulation while in ' 'place; undo that exit first.') given = body.model_dump(mode='json', exclude_none=True) new_origin = {**origin, 'planned': False, **given} @@ -831,7 +906,7 @@ async def undo_deinstall( current_user: Annotated[User, Depends(get_current_active_user)], identity_id: str, ): - """``planned`` is true again, but only while no state starts and no + """``planned`` is true again, but only while no snapshot starts and no evidence is valid after the deinstallation's ``at``; later than that a moderator corrects the origin by PATCH (8.104). Propagates like the deinstall.""" diff --git a/src/backend/apps/catalog/api/identity_filters.py b/src/backend/apps/catalog/api/identity_filters.py index c6cec7b8..f4e5dfb1 100644 --- a/src/backend/apps/catalog/api/identity_filters.py +++ b/src/backend/apps/catalog/api/identity_filters.py @@ -228,14 +228,14 @@ def catalog_filters( q: str = Query('', max_length=FILTER_MAX_LENGTH, description='name, catalogue number or id'), evidence_method: Optional[EvidenceMethod] = Query( - None, description='only elements with at least one published, current ' + None, description='only components with at least one published, current ' 'evidence record of this method (8.177), for example ' 'reinforcement_layout; combines with every other ' 'filter'), fit_mode: Optional[FitMode] = Query( None, description='dimension search (8.169): about = every side ' 'within fit_tol of fit_size; can_hold = every side ' - 'of the element at least fit_size'), + 'of the component at least fit_size'), fit_size: Optional[str] = Query( None, max_length=FILTER_MAX_LENGTH, description='three sizes in mm in any order, for example ' @@ -251,12 +251,12 @@ def catalog_filters( None, description='near search: longitude, -180 to 180; needs ' 'near_lat'), near_layer: Optional[NearLayer] = Query( - None, description='which point of an element is measured: current (the ' - 'location of the current version, default) or ' + None, description='which point of a component is measured: current (the ' + 'location of the current snapshot, default) or ' 'origin (the origin building)'), radius_km: Optional[float] = Query( - None, description='near search: only elements within this many km; ' - 'without it every element with a point on the layer, ' + None, description='near search: only components within this many km; ' + 'without it every component with a point on the layer, ' 'nearest first'), ) -> CatalogFilters: """FastAPI dependency: the catalog filters from the query string.""" diff --git a/src/backend/apps/catalog/api/identity_lifecycle.py b/src/backend/apps/catalog/api/identity_lifecycle.py index c2de46f0..de323059 100644 --- a/src/backend/apps/catalog/api/identity_lifecycle.py +++ b/src/backend/apps/catalog/api/identity_lifecycle.py @@ -45,7 +45,7 @@ class WithdrawIdentityBody(BaseModel): reason: str = Field(min_length=1) duplicate_of: Optional[str] = Field( - None, description='the canonical element this one duplicates') + None, description='the canonical component this one duplicates') class PurgeBody(BaseModel): @@ -95,8 +95,8 @@ async def withdraw_identity( """ Hidden everywhere by default; members of D see it in full, everyone else who could see it a tombstone (8.17). With ``duplicate_of`` the - resolver and the component page lead to the canonical element; elements - that named this one as their canonical element follow along (I19). + resolver and the component page lead to the canonical component; components + that named this one as their canonical component follow along (I19). """ identity = (await load_identity(request, current_user, identity_id, 'withdraw_identity')).record @@ -118,15 +118,15 @@ async def withdraw_identity( if target.get('withdrawn'): raise HTTPException( status_code=422, - detail='duplicate_of is withdrawn itself; name the element it ' + detail='duplicate_of is withdrawn itself; name the component it ' 'leads to (I19).') followers = await request.app.mongodb_component_identities.count_documents( {'withdrawn.duplicate_of': identity_id}) if followers and duplicate_of is None: raise HTTPException( status_code=409, - detail=f'{followers} withdrawn element(s) name this one as their ' - f'canonical element; give duplicate_of so they follow ' + detail=f'{followers} withdrawn component(s) name this one as their ' + f'canonical component; give duplicate_of so they follow ' f'(I19).') now = now_iso() withdrawn = {'at': now, 'by_user_id': current_user.id, @@ -222,7 +222,7 @@ async def delete_identity( if referenced: raise HTTPException( status_code=409, - detail=f'Other elements name this one (catalog numbers ' + detail=f'Other components name this one (catalog numbers ' f'{referenced}); resolve those links first.') snapshots = await db.mongodb_component_snapshots.find( {'identity_id': identity_id}, {'_id': 1}).to_list(length=None) @@ -304,8 +304,8 @@ async def resolve_id( """ ``Accept: text/html`` --> 302 to the component page; otherwise 302 to the passport. A withdrawn duplicate --> 301 to ``/id/{duplicate_of}``; - other withdrawn elements and elements without a current state still - redirect (the page shows the tombstone / "no current state"); purged + other withdrawn components and components without a current snapshot still + redirect (the page shows the tombstone / "no current snapshot"); purged --> 410; unknown or never published (unless the caller may see it) --> 404. Visibility applies after the redirect (8.11). """ diff --git a/src/backend/apps/catalog/api/identity_query.py b/src/backend/apps/catalog/api/identity_query.py index 1db423b9..3db98276 100644 --- a/src/backend/apps/catalog/api/identity_query.py +++ b/src/backend/apps/catalog/api/identity_query.py @@ -439,7 +439,7 @@ async def shallow_row_for_identity( if not docs: raise HTTPException( status_code=404, - detail=f'Identity {identity_id} not found', + detail=f'Component {identity_id} not found', ) return catalog_row(docs[0]) diff --git a/src/backend/apps/catalog/api/identity_workflows.py b/src/backend/apps/catalog/api/identity_workflows.py index b7bce46f..2afa9587 100644 --- a/src/backend/apps/catalog/api/identity_workflows.py +++ b/src/backend/apps/catalog/api/identity_workflows.py @@ -50,7 +50,7 @@ async def _resolve_user_id( @router.get( '/identities/reserved/{user_identifier}', - summary='List identities reserved by a user (shallow rows)', + summary='List components reserved by a user (shallow rows)', ) async def list_reserved_identities( request: Request, @@ -154,7 +154,7 @@ async def get_vocabularies(): @router.get( '/identities/meta/datasets', - summary='Datasets that hold identities (dropdowns)', + summary='Datasets that hold components (dropdowns)', ) @local_limiter.limit('120/minute', key_func=signed_in_or_ip) async def list_identity_datasets( @@ -180,7 +180,7 @@ async def list_identity_datasets( @router.post( '/identities/{identity_id}/reserve', - summary='Reserve identity for the current user', + summary='Reserve a component for the current user', ) async def reserve_identity( request: Request, @@ -194,7 +194,7 @@ async def reserve_identity( if identity.get('exit'): raise HTTPException( status_code=409, - detail='An element out of circulation cannot be reserved (I18)', + detail='A component out of circulation cannot be reserved (I18)', ) reserved = identity.get('reserved') or '' @@ -215,6 +215,12 @@ async def reserve_identity( ) # any signed-in user who can read the piece (7.0) await require(request, current_user, 'reserve', identity=identity) + if identity.get('withdrawn'): + # after the permission, so that a caller who cannot read the element + # learns nothing of its state; the reservation was cleared when it + # was withdrawn (8.190) + raise HTTPException(status_code=409, + detail='The component is withdrawn.') identities = await get_identities_col(request) try: @@ -246,7 +252,7 @@ async def reserve_identity( @router.delete( '/identities/{identity_id}/reserve', - summary='Release reservation on an identity', + summary='Release reservation on a component', ) async def release_identity_reservation( request: Request, diff --git a/src/backend/apps/catalog/api/idtransmission.py b/src/backend/apps/catalog/api/idtransmission.py index 4ee1c0b4..1deb1b03 100644 --- a/src/backend/apps/catalog/api/idtransmission.py +++ b/src/backend/apps/catalog/api/idtransmission.py @@ -45,7 +45,7 @@ class TransmitPayload(BaseModel): identity_id: str = Field( min_length=1, max_length=MAX_IDENTITY_ID_LEN, - description='Identity UUID scanned from the QR code.', + description='Component id scanned from the QR code.', ) force_overwrite: bool = Field( default=False, @@ -123,7 +123,7 @@ def _snapshot_conflict_response(identity_id: str) -> JSONResponse: 'status': 'snapshot_id_exists', 'message': ( 'This UUID is already a snapshot id. Transmit the physical ' - 'identity id from the tag, not a snapshot id.' + 'component id from the tag, not a snapshot id.' ), 'identity_id': identity_id, }, @@ -132,14 +132,14 @@ def _snapshot_conflict_response(identity_id: str) -> JSONResponse: @router.get( '/component_id_transmission/availability/{identity_id}', - summary='Check whether a UUID is already an identity or snapshot id', + summary='Check whether a UUID is already a component id or snapshot id', ) async def check_identity_availability( identity_id: str, current_user: Annotated[User, Depends(get_current_active_user)], request: Request, ): - identity_id = validate_uuid(identity_id.strip(), label='identity id') + identity_id = validate_uuid(identity_id.strip(), label='component id') conflict = await _catalog_id_conflict(request, identity_id) return JSONResponse( status_code=status.HTTP_200_OK, @@ -153,7 +153,7 @@ async def check_identity_availability( @router.get( '/component_id_transmission', - summary='Get the current pending transmitted identity id for the user', + summary='Get the current pending transmitted component id for the user', ) async def get_pending_transmission( current_user: Annotated[User, Depends(get_current_active_user)], @@ -178,7 +178,7 @@ async def get_pending_transmission( @router.post( '/component_id_transmission', - summary='Transmit a scanned identity id (one pending per user)', + summary='Transmit a scanned component id (one pending per user)', ) async def transmit_identity_id( payload: TransmitPayload, @@ -191,7 +191,7 @@ async def transmit_identity_id( status_code=status.HTTP_400_BAD_REQUEST, detail='identity_id must not be empty', ) - validate_uuid(identity_id, label='identity id') + validate_uuid(identity_id, label='component id') coll = await get_transmit_col(request) now = _now_iso() @@ -218,7 +218,7 @@ async def transmit_identity_id( content={ 'status': 'conflict', 'message': ( - 'A different identity id is still pending. ' + 'A different component id is still pending. ' 'Confirm overwrite to replace it.' ), 'existing': _serialize_item(existing), @@ -258,7 +258,7 @@ async def transmit_identity_id( @router.delete( '/component_id_transmission', - summary='Clear the current pending transmitted identity id', + summary='Clear the current pending transmitted component id', ) async def clear_pending_transmission( current_user: Annotated[User, Depends(get_current_active_user)], @@ -286,7 +286,7 @@ async def clear_pending_transmission( @router.post( '/component_id_transmission/consume', - summary='Consume pending transmission after identity was created', + summary='Consume pending transmission after the component was created', ) async def consume_pending_transmission( payload: ConsumePayload, @@ -299,7 +299,7 @@ async def consume_pending_transmission( if payload.identity_id: query['identity_id'] = validate_uuid( payload.identity_id.strip(), - label='identity id', + label='component id', ) result = await coll.delete_one(query) diff --git a/src/backend/apps/catalog/api/invitations.py b/src/backend/apps/catalog/api/invitations.py index d315ed07..5ce2bc91 100644 --- a/src/backend/apps/catalog/api/invitations.py +++ b/src/backend/apps/catalog/api/invitations.py @@ -10,8 +10,8 @@ * ``POST /invitations/{iid}/resend`` --- a new code (the old one is void), mailed again; who may revoke may resend * ``GET /invitations`` --- admin: all; moderator: their datasets' -* ``DELETE /invitations/{iid}`` --- revoke while unused: its creator, - ``moderator(D)``, admin +* ``DELETE /invitations/{iid}`` --- revoke while unused: ``moderator(D)``, + admin (the creator loses the right with the role, 8.193 c) * ``POST /datasets/{did}/members`` --- ``moderator(D)``: in a reviewed dataset an existing account (exact email) is added and notified, any other address invited; in a dataset an admin has not reviewed yet every address is diff --git a/src/backend/apps/catalog/api/materials.py b/src/backend/apps/catalog/api/materials.py index deb2e578..c87d88e3 100644 --- a/src/backend/apps/catalog/api/materials.py +++ b/src/backend/apps/catalog/api/materials.py @@ -161,7 +161,7 @@ async def delete_material( current_user: Annotated[User, Depends(get_current_active_user)], mid: str, ): - """Only while no identity references it, withdrawn ones included.""" + """Only while no component references it, withdrawn ones included.""" await load_material(request, current_user, mid, 'manage_materials') used = await request.app.mongodb_component_identities.count_documents( {'material': mid}) @@ -186,7 +186,7 @@ async def merge_material( mid: str, body: MergeBody, ): - """Every identity moves to the target; derived classes follow the + """Every component moves to the target; derived classes follow the target's default, assigned ones stay; ``mid`` remains as an alias ``{_id, merged_into}`` so old references resolve (8.35).""" source = (await load_material(request, current_user, mid, diff --git a/src/backend/apps/catalog/api/schema_routes.py b/src/backend/apps/catalog/api/schema_routes.py index c61c5cd8..ce05c342 100644 --- a/src/backend/apps/catalog/api/schema_routes.py +++ b/src/backend/apps/catalog/api/schema_routes.py @@ -162,7 +162,7 @@ def _create_schema_response(request: Request, schema: dict): ) async def get_create_snapshot_json_schema(request: Request): """ - The 0.6 body of a new state or a correction, as the Grasshopper + The 0.6 body of a new snapshot or a correction, as the Grasshopper bridge and other clients send it. Derived fields are not part of it. """ from .snapshot_lifecycle import SnapshotDraftBody diff --git a/src/backend/apps/catalog/api/snapshot_lifecycle.py b/src/backend/apps/catalog/api/snapshot_lifecycle.py index e6f5085f..361a714d 100644 --- a/src/backend/apps/catalog/api/snapshot_lifecycle.py +++ b/src/backend/apps/catalog/api/snapshot_lifecycle.py @@ -98,13 +98,13 @@ # BODIES ---------------------------------------------------------------------- class SnapshotDraftBody(BaseModel): - """A new state or a correction, as the client sends it. Derived fields + """A new snapshot or a correction, as the client sends it. Derived fields (frame, bbx, descriptors, fitted proxies, ...) are never accepted.""" model_config = ConfigDict(extra='forbid') name: Optional[str] = None effective_from: Optional[Timestamp] = Field( - None, description='a new state: default now; a correction inherits') + None, description='a new snapshot: default now; a correction inherits') effective_from_precision: Optional[Precision] = None geometry: Geometry capture: Optional[Capture] = None @@ -118,7 +118,7 @@ class SnapshotDraftBody(BaseModel): location: Optional[GeoLocation] = None notes: Optional[str] = None photo_credit: Optional[PhotoCredit] = Field( - None, description='who the photos of this version come from ' + None, description='who the photos of this snapshot come from ' '(mutable metadata, 8.128 a)') @model_validator(mode='after') @@ -347,6 +347,7 @@ async def _publish(request: Request, user: User, snapshot: dict, parent_datasets=tuple(parents)) if not can(viewer, 'publish', target): raise deny_write(viewer, 'publish') + _refuse_withdrawn(identity) # after the right (8.190) # the parents may have changed since the cut was recorded (8.34) await check_cut_allowed(request, parent_docs) _ensure_monotonic(snapshot, await _snapshots_of(request, identity['_id'])) @@ -429,17 +430,26 @@ async def _publish_locked(request: Request, user: User, snapshot: dict, return published +def _refuse_withdrawn(identity: dict) -> None: + """A withdrawn element stays out of circulation (8.190): a version of it + is not submitted, published or made current, whoever asks, an admin + included. Recall, reject, back to draft and delete stay.""" + if identity.get('withdrawn'): + raise HTTPException(status_code=409, + detail='The component is withdrawn.') + + # CREATE ---------------------------------------------------------------------- @router.post('/identities/{identity_id}/snapshots', status_code=201, - summary='Record a new state of a component (always a draft)') + summary='Record a new snapshot of a component (always a draft)') async def create_snapshot( request: Request, current_user: Annotated[User, Depends(get_current_active_user)], identity_id: str, body: SnapshotDraftBody, ): - """contributor(D). ``effective_from`` defaults to now. Only for an element - in circulation: an exited element re-enters first (section 3.1.3).""" + """contributor(D). ``effective_from`` defaults to now. Only for a component + in circulation: an exited component re-enters first (section 3.1.3).""" identity = (await load_identity(request, current_user, identity_id, 'create_snapshot')).record if identity.get('withdrawn'): @@ -449,7 +459,7 @@ async def create_snapshot( raise HTTPException( status_code=409, detail='The component is out of circulation; it re-enters ' - 'before it gets a new state (section 3.1.3).') + 'before it gets a new snapshot (section 3.1.3).') _check_client_geometry(body) size = await current_quantity(request, identity) if size is not None: @@ -459,7 +469,7 @@ async def create_snapshot( raise HTTPException( status_code=422, detail=f'quantity: this component records {size} and keeps ' - f'it in later states; correct the state to change it ' + f'it in later snapshots; correct the snapshot to change it ' f'(I32).') body = body.model_copy(update={'quantity': size}) snapshots = await _snapshots_of(request, identity_id) @@ -495,6 +505,11 @@ async def supersede_snapshot( loaded = await load_snapshot(request, current_user, snapshot_id, 'supersede_snapshot') old, identity = loaded.record, loaded.identity + if identity.get('withdrawn'): + # a withdrawn element stays out of circulation (8.190): a correction + # would publish a new state of it; reinstate it first + raise HTTPException(status_code=409, + detail='The component is withdrawn.') if old.get('status') != 'published' or old.get('superseded_by'): raise HTTPException( status_code=409, @@ -514,9 +529,9 @@ async def supersede_snapshot( s['_id'] != old['_id'] for s in _live(snapshots)): raise HTTPException( status_code=409, - detail='The component has other states that record ' + detail='The component has other snapshots that record ' f'{old_quantity}; correct the quantity while it has ' - 'one state only (I32).') + 'one snapshot only (I32).') _ensure_nothing_in_flight(snapshots) version = max(s['version'] for s in snapshots) + 1 doc = _new_snapshot( @@ -544,6 +559,7 @@ async def submit_snapshot( request, current_user, snapshot_id, lambda s: _transition_or_409(s, 'pending')) snapshot = loaded.record + _refuse_withdrawn(loaded.identity) # the frame and the class are current when it goes to review (6.14) snapshot = await derive_sync(request, snapshot_id) or snapshot return _ok(await _change_status(request, current_user, snapshot, @@ -622,6 +638,7 @@ async def promote_snapshot( loaded = await load_snapshot(request, current_user, snapshot_id, 'promote') snapshot, identity = loaded.record, loaded.identity + _refuse_withdrawn(identity) if snapshot.get('status') != 'published' or snapshot.get('superseded_by'): raise HTTPException( status_code=409, @@ -645,6 +662,10 @@ async def withdraw_snapshot( request, current_user, snapshot_id, lambda s: _transition_or_409(s, 'withdrawn')) snapshot, identity = loaded.record, loaded.identity + if body.replacement_id: + # a replacement makes another version current: not on a withdrawn + # element (8.190); a plain withdrawal stays allowed + _refuse_withdrawn(identity) snapshots = await _snapshots_of(request, identity['_id']) remaining = [s for s in _live(snapshots) if s['_id'] != snapshot['_id']] replacement = None @@ -678,6 +699,7 @@ async def reinstate_snapshot( request, current_user, snapshot_id, lambda s: _transition_or_409(s, 'published')) snapshot, identity = loaded.record, loaded.identity + _refuse_withdrawn(identity) # reinstate the element first (8.190) published = await _change_status(request, current_user, snapshot, 'published') if not identity.get('current_snapshot_id') \ diff --git a/src/backend/apps/catalog/api/snapshot_media.py b/src/backend/apps/catalog/api/snapshot_media.py index 9d2b3e23..d91de59b 100644 --- a/src/backend/apps/catalog/api/snapshot_media.py +++ b/src/backend/apps/catalog/api/snapshot_media.py @@ -258,9 +258,17 @@ async def put_snapshot_photo( """ Accept up to upload limit; store JPEG scaled/compressed to max output. """ - await load_snapshot( + loaded = await load_snapshot( request, current_user, snapshot_id, 'add_photo', files=True, frozen=False) + # a withdrawn version, or any version of a withdrawn element, takes no + # new photo, for an admin as well: the state refuses (8.190) + if (loaded.identity or {}).get('withdrawn'): + raise HTTPException(status_code=409, + detail='The component is withdrawn.') + if loaded.record.get('status') == 'withdrawn': + raise HTTPException(status_code=409, + detail='This snapshot is withdrawn.') content_type = (photo.content_type or '').split(';', 1)[0].strip().lower() if content_type not in _ALLOWED_PHOTO_TYPES: diff --git a/src/backend/apps/catalog/api/snapshots.py b/src/backend/apps/catalog/api/snapshots.py index bc1ed793..3d833c82 100644 --- a/src/backend/apps/catalog/api/snapshots.py +++ b/src/backend/apps/catalog/api/snapshots.py @@ -69,9 +69,9 @@ async def list_my_snapshots( limit: int = Query(100, ge=1, le=500), ): """ - The versions the caller added (``added_by_user_id``), for "My work" + The snapshots the caller added (``added_by_user_id``), for "My work" (8.118 Q4): drafts, pending and rejected ones by default, each with its - element and, when rejected, the reason. Nobody lists another person's + component and, when rejected, the reason. Nobody lists another person's snapshots here. """ if not mine: @@ -100,7 +100,8 @@ async def list_my_snapshots( i['_id']: i async for i in identities.find( {'_id': {'$in': ids}}, {'_id': 1, 'current_snapshot_id': 1, 'catalog_number': 1, - 'original_function': 1, 'material': 1, 'dataset': 1})} + 'original_function': 1, 'material': 1, 'dataset': 1, + 'withdrawn': 1})} except ConnectionFailure: raise # the 503 handler of main_fastapi.py except PyMongoError: @@ -125,6 +126,7 @@ async def list_my_snapshots( 'original_function': piece.get('original_function'), 'material': piece.get('material'), 'dataset': piece.get('dataset'), + 'identity_withdrawn': bool(piece.get('withdrawn')), 'rejection_reason': reason, }).model_dump(by_alias=True)) except Exception as exc: @@ -185,6 +187,7 @@ async def list_pending_snapshots( 'original_function': 1, 'material': 1, 'dataset': 1, + 'withdrawn': 1, }, ) if identity_doc is None or identity_doc.get('dataset') not in moderated: @@ -207,6 +210,7 @@ async def list_pending_snapshots( 'original_function': identity_doc.get('original_function'), 'material': identity_doc.get('material'), 'dataset': identity_doc.get('dataset'), + 'identity_withdrawn': bool(identity_doc.get('withdrawn')), 'live_version': live_version, } try: diff --git a/src/backend/apps/catalog/documents.py b/src/backend/apps/catalog/documents.py index 9013f467..00510fca 100644 --- a/src/backend/apps/catalog/documents.py +++ b/src/backend/apps/catalog/documents.py @@ -208,7 +208,7 @@ class GeoLocation(_Block): class PhotoCredit(_Block): - """Who the photos of one version come from (decision 8.128 a): a short + """Who the photos of one snapshot come from (decision 8.128 a): a short text for all its photos and, optionally, the page they come from. Good practice, not a licence.""" text: str = Field(min_length=1, max_length=300) @@ -240,7 +240,7 @@ class Place(_Block): class ConstructionWork(_Block): - """The works an element left or went into --- never the company.""" + """The works a component left or went into --- never the company.""" name: str identifier: Optional[str] = None year_built: Optional[int] = None @@ -257,10 +257,10 @@ class CircularityClass(_Block): class Origin(_Block): - """How the element entered circulation (section 3.1.1).""" + """How the component entered circulation (section 3.1.1).""" kind: OriginKind planned: bool = Field( - False, description='true while the element is in place: identified in ' + False, description='true while the component is in place: identified in ' 'its works, not yet deinstalled (decision 8.104)') at: Optional[Timestamp] = None at_precision: Precision = 'unknown' @@ -290,7 +290,7 @@ def _construction_work_kind(self) -> 'Origin': class Exit(_Block): - """How the element left circulation (section 3.1.3).""" + """How the component left circulation (section 3.1.3).""" kind: ExitKind at: Timestamp at_precision: Precision = 'exact' @@ -396,19 +396,19 @@ def _consistency(self) -> 'ComponentIdentity': 'inherited_from must be one of parent_identities (I17)') if self.reserved and self.exit is not None: raise ValueError( - 'an element out of circulation cannot be reserved (I18)') + 'a component out of circulation cannot be reserved (I18)') if (self.origin is not None and self.origin.planned and self.exit is not None and self.exit.recorded_by_user_id is not None and self.exit.kind not in IN_PLACE_EXIT_KINDS): raise ValueError( 'an exit set by hand from in place is recycled, disposed or ' - 'lost: the element never left its works (I31)') + 'lost: the component never left its works (I31)') if self.withdrawn and self.withdrawn.duplicate_of == self.id: raise ValueError( - 'an identity cannot be a duplicate of itself (I19)') + 'a component cannot be a duplicate of itself (I19)') if self.parent_identities and self.id in self.parent_identities: - raise ValueError('an identity cannot be its own parent') + raise ValueError('a component cannot be its own parent') return self @@ -679,7 +679,7 @@ class Derivation(_Block): class ComponentSnapshot(_Document): - """``component_snapshots``: one recorded state of a component.""" + """``component_snapshots``: one snapshot of a component.""" id: str = Field(alias='_id') identity_id: str version: int = Field(ge=0) @@ -750,7 +750,7 @@ class Standard(_Block): class Position(_Block): - """Where on the element (3.3.2); kind none + description always works.""" + """Where on the component (3.3.2); kind none + description always works.""" kind: PositionKind = 'none' snapshot_id: Optional[str] = None point: Optional[Vec3] = None @@ -1108,7 +1108,7 @@ class AccessToken(_Document): class ChangeLogEntry(_Document): - """``change_log``: one write to an identity, snapshot or evidence + """``change_log``: one write to a component, snapshot or evidence record (section 3.8, decision 8.36, I30); append-only.""" id: str = Field(alias='_id') record_kind: str = Field(pattern='^(identity|snapshot|evidence)$') diff --git a/src/backend/apps/catalog/evidence/payloads.py b/src/backend/apps/catalog/evidence/payloads.py index ff26533c..8dea93ca 100644 --- a/src/backend/apps/catalog/evidence/payloads.py +++ b/src/backend/apps/catalog/evidence/payloads.py @@ -145,7 +145,7 @@ class Grid(Payload): class ReboundTestArea(Payload): label: Optional[str] = Field( - None, description='Name of the test area on the element, e.g. TA-1.') + None, description='Name of the test area on the component, e.g. TA-1.') surface_preparation: Literal['ground', 'as_found'] = Field( description='Whether the surface was ground before testing.') surface_condition: Literal['dry', 'damp', 'wet'] = Field( @@ -226,7 +226,7 @@ class ReboundHammerPayload(Payload): class CoreSampling(Payload): cored_at: Timestamp = Field( description='When the core was drilled; becomes the record\'s ' - 'sampled_at and decides which state of the element the ' + 'sampled_at and decides which snapshot of the component the ' 'result belongs to.') paired_rebound_id: Optional[str] = Field( None, description='The rebound hammer record taken at this drill ' @@ -402,7 +402,7 @@ class ArchivalDocumentPayload(Payload): claim: Optional[ArchivalClaim] = Field( None, description='What the document says. Without a claim and a ' 'summary the record is a document: it documents ' - 'the element and never enters the fold.') + 'the component and never enters the fold.') class VisualObservation(Payload): diff --git a/src/backend/apps/catalog/evidence/registry.py b/src/backend/apps/catalog/evidence/registry.py index 0602a714..46a91048 100644 --- a/src/backend/apps/catalog/evidence/registry.py +++ b/src/backend/apps/catalog/evidence/registry.py @@ -220,7 +220,7 @@ def prepare_record(data: Dict[str, Any], *, position = dict(WHOLE_COMPONENT) if position is None: problems.append(Problem( - 'position', 'say where on the element: kind none with a ' + 'position', 'say where on the component: kind none with a ' 'description is always enough')) else: position = dict(position) diff --git a/src/backend/apps/catalog/evidence/specs.py b/src/backend/apps/catalog/evidence/specs.py index 620a08d4..958d09c3 100644 --- a/src/backend/apps/catalog/evidence/specs.py +++ b/src/backend/apps/catalog/evidence/specs.py @@ -50,9 +50,9 @@ def _claimable(tier: str) -> Tuple[str, ...]: name='core_compression', label='Drilled core in compression (EN 12504-1, EN 12390-3)', description=( - 'A core drilled from the element, prepared and crushed. The record ' - 'carries both dates: sampled_at (the element was drilled) decides the ' - 'state of the element it belongs to, observed_at is the test. The ' + 'A core drilled from the component, prepared and crushed. The record ' + 'carries both dates: sampled_at (the component was drilled) decides the ' + 'snapshot of the component it belongs to, observed_at is the test. The ' 'server recomputes F / A and the length-to-diameter class and ' 'derives the in-situ strength (EN 13791).'), payload_model=CoreCompressionPayload, @@ -69,7 +69,7 @@ def _claimable(tier: str) -> Tuple[str, ...]: 'A claim from a drawing, specification, report, photo, marking, ' 'type plate or declaration of performance. The claim is the ' 'summary: a value or a range, or a class. Without a summary it is a ' - 'document: it documents the element (a plan, an element passport, a ' + 'document: it documents the component (a plan, an element passport, a ' 'report), never enters the fold, and may carry the link it was read ' 'from.'), payload_model=ArchivalDocumentPayload, @@ -99,7 +99,7 @@ def _claimable(tier: str) -> Tuple[str, ...]: label='Rule of thumb by era, region or typology', description=( 'An estimate from the construction year, regional practice or the ' - 'typology of the element. The estimate is the summary.'), + 'typology of the component. The estimate is the summary.'), payload_model=EraHeuristicPayload, source_tier=METHOD_TIER['era_heuristic'], destructive=False, default_standard=None, summary_quantities=_claimable('heuristic'), @@ -122,7 +122,7 @@ def _claimable(tier: str) -> Tuple[str, ...]: name='reinforcement_layout', label='Reinforcement layout', description=( - 'The bars of the element from one source: a drawing (archival), a ' + 'The bars of the component from one source: a drawing (archival), a ' 'cover-meter or radar scan (non-destructive) or exposed bars ' '(visual). The bar centrelines are in the stored coordinates of ' 'the snapshot named by position.snapshot_id, which is required. ' diff --git a/src/backend/apps/catalog/exports/cero.py b/src/backend/apps/catalog/exports/cero.py index 7425383c..00a696e9 100644 --- a/src/backend/apps/catalog/exports/cero.py +++ b/src/backend/apps/catalog/exports/cero.py @@ -35,7 +35,7 @@ CERO = 'https://w3id.org/cero#' CERO_MATERIALS = ('concrete', 'autoclaved_aerated_concrete') -NOT_CONCRETE = 'CERO covers concrete elements only' +NOT_CONCRETE = 'CERO covers concrete components only' # CERO declares these two as strings, all other exported scalars as decimals _STRING_RANGE = ('chlorideContent',) diff --git a/src/backend/apps/catalog/exports/pdf.py b/src/backend/apps/catalog/exports/pdf.py index 239fe7a7..ade8aa14 100644 --- a/src/backend/apps/catalog/exports/pdf.py +++ b/src/backend/apps/catalog/exports/pdf.py @@ -377,7 +377,7 @@ def _story(data: PassportPdfData, rows_cap: int, props_cap: int, Paragraph( f'Dataset: {escape(data.dataset_name)}
' f'Issued {escape(data.generated_at[:10])}' - + (f' · state v{snapshot["version"]}' + + (f' · snapshot v{snapshot["version"]}' if snapshot.get('version') is not None else '') + f'
{_link(iri)}', st['sub']), ] @@ -399,7 +399,7 @@ def _story(data: PassportPdfData, rows_cap: int, props_cap: int, + (f' {date}' if date else ' (date not set)'), st['note'])] # IDENTITY -------------------------------------------------------------- - story.append(_p('Identity', st['section'])) + story.append(_p('Component', st['section'])) function = identity.get('original_function') ifc = '' if function == 'CscDebris' else f' ({function})' table = _kv([ @@ -430,7 +430,7 @@ def _story(data: PassportPdfData, rows_cap: int, props_cap: int, f'{", " + escape(place) if place else ""}', st['body'])] # CURRENT STATE --------------------------------------------------------- - story.append(_p('Current state', st['section'])) + story.append(_p('Current snapshot', st['section'])) props = {**(snapshot.get('properties') or {}), **(identity.get('properties') or {})} bbx = snapshot.get('bbx') or [] diff --git a/src/backend/apps/catalog/lineage.py b/src/backend/apps/catalog/lineage.py index 7d9a8e73..122727c2 100644 --- a/src/backend/apps/catalog/lineage.py +++ b/src/backend/apps/catalog/lineage.py @@ -282,7 +282,7 @@ def cut_refusal(parent: Dict[str, Any], *, ever_published: bool if exit_.get('kind') in ('installed', 'returned', 'lost'): return (f'{label} is out of circulation ({exit_["kind"]}); ' f'it re-enters first.') - return f'{label} no longer exists as this element ({exit_["kind"]}).' + return f'{label} no longer exists as this component ({exit_["kind"]}).' return None diff --git a/src/backend/apps/catalog/mcp_server.py b/src/backend/apps/catalog/mcp_server.py index e86133ad..d24e6da3 100644 --- a/src/backend/apps/catalog/mcp_server.py +++ b/src/backend/apps/catalog/mcp_server.py @@ -67,9 +67,9 @@ 'The Catalog of Second Chances (CSC) is a catalog of reused and ' 'salvaged building components (German: wiederverwendete Bauteile, ' 'Wiederverwendung, Bauteilboerse): concrete walls and beams ' - '(Betonwaende, Traeger), stone, timber and other elements, each ' - 'with its shape, origin, versions and measurements ("evidence"). Use ' - 'these tools before a web search when the user looks for such elements, ' + '(Betonwaende, Traeger), stone, timber and other components, each ' + 'with its shape, origin, snapshots and measurements ("evidence"). Use ' + 'these tools before a web search when the user looks for such components, ' 'for example "Betontraeger mit Bewehrung" or reused beams with ' 'reinforcement (Bewehrung): search_components with the filters below, ' 'and has_evidence=reinforcement_layout for "with reinforcement". ' @@ -85,7 +85,7 @@ + EVIDENCE_METHOD_TEXT + '. A list gives short rows: method, source ' 'tier, when observed, who performed it, summary, status, verification; ' 'a reinforcement_layout row also gives a summary of its bars (count, ' - 'basis, specs, diameters, cover, the version it refers to). Filter with ' + 'basis, specs, diameters, cover, the snapshot it refers to). Filter with ' 'method. Pass evidence_id for one record in full, with its payload (the ' 'bars of a layout).') @@ -204,7 +204,7 @@ def layout_bars(record: dict) -> list: return [b for b in bars if isinstance(b, dict)] -def layouts_of_version(rows: list, snapshot_id: Optional[str]) -> dict: +def layouts_of_snapshot(rows: list, snapshot_id: Optional[str]) -> dict: """The reinforcement of one version, from the published ``reinforcement_layout`` evidence that names it in ``position.snapshot_id`` (decision 7.8: the bars are evidence, not geometry): how many records and @@ -236,7 +236,7 @@ def layout_summary(record: dict) -> dict: 'diameters_mm': sorted({b['diameter_mm'] for b in bars if isinstance(b.get('diameter_mm'), (int, float))}), - 'version_id': (record.get('position') or {}).get('snapshot_id')} + 'snapshot_id': (record.get('position') or {}).get('snapshot_id')} if covers: summary['cover_mm'] = {'min': min(covers), 'max': max(covers)} return summary @@ -296,8 +296,8 @@ def size() -> int: 'active (default: in circulation), in_place, deinstalled, ' 'exited, all.'))] StatusArg = Annotated[str, Field(description=( - 'Version status: published (default), or any to include ' - 'pending and other states you may see.'))] + 'Snapshot status: published (default), or any to include ' + 'pending and other statuses you may see.'))] WithdrawnArg = Annotated[bool, Field(description=( 'Also withdrawn components, if you may see them.'))] HasEvidenceArg = Annotated[str, Field(description=( @@ -307,11 +307,11 @@ def size() -> int: 'filter. Leave empty for all.'))] FitModeArg = Annotated[str, Field(description=( 'Search by size, with size_mm: about = every side within the ' - 'tolerance of the asked side (which elements are about this ' - 'size); can_hold = every side of the element at least the asked ' - 'side (which elements can this part be cut from). The sides are ' + 'tolerance of the asked side (which components are about this ' + 'size); can_hold = every side of the component at least the asked ' + 'side (which components can this part be cut from). The sides are ' 'compared largest to smallest, so the orientation does not ' - 'matter. An element without a known size never matches.'))] + 'matter. A component without a known size never matches.'))] SizeArg = Annotated[Optional[list[float]], Field(description=( 'The asked size: three numbers in mm in any order, for example ' '[1200, 600, 200]. Needs fit_mode.'))] @@ -320,18 +320,18 @@ def size() -> int: 'millimetres, for example "10%" (the default) or "50mm".'))] NearLatArg = Annotated[Optional[float], Field(description=( 'Search by place: the latitude of the point, -90 to 90, with ' - 'near_lon. Only elements with a known place on the chosen layer ' + 'near_lon. Only components with a known place on the chosen layer ' 'are listed, nearest first, each with its distance_km.'))] NearLonArg = Annotated[Optional[float], Field(description=( 'The longitude of the point, -180 to 180. Needs near_lat.' ))] NearLayerArg = Annotated[str, Field(description=( - 'Which place of an element is measured: current (where the element ' + 'Which place of a component is measured: current (where the component ' 'is now; the default) or origin (the building it comes from, ' - 'known for fewer elements).'))] + 'known for fewer components).'))] RadiusArg = Annotated[Optional[float], Field(description=( - 'Only elements within this many km of the point. Without it every ' - 'element with a place on the layer is listed, nearest first.' + 'Only components within this many km of the point. Without it every ' + 'component with a place on the layer is listed, nearest first.' ))] @@ -445,8 +445,8 @@ async def search_components( radius_km: RadiusArg = None, sort: Annotated[str, Field(description=( 'catalog_number (default without a size or place search), date ' - '(the version applies from), created, volume (length x width x ' - 'height; elements without a size last), match (closeness to the ' + '(the snapshot applies from), created, volume (length x width x ' + 'height; components without a size last), match (closeness to the ' 'size search: smallest deviation, or least waste, first; the ' 'default with fit_mode and no place search), distance (from the ' 'near point, nearest first; the default with near_lat and ' @@ -460,7 +460,7 @@ async def search_components( component (name, function, material, dataset, size, status, visibility) with its web link, and the total. With fit_mode and size_mm each row also carries its deviation (about, in per cent) or - waste (can_hold, in m3 and in per cent of the element); with near_lat + waste (can_hold, in m3 and in per cent of the component); with near_lat and near_lon each row carries its distance_km. has_evidence keeps only components with a published, current evidence record of one method, for example reinforcement_layout for "with reinforcement". Use @@ -506,7 +506,7 @@ async def get_component( ) -> dict: """One component: what it is, where it comes from, how it left circulation, its derived properties with confidence, its current - version in short (with the count of its reinforcement layouts and + snapshot in short (with the count of its reinforcement layouts and bars), and links. Geometry is a summary only.""" passport = await get(f'/identities/{component_id}/compose') versions = await get(f'/identities/{component_id}/snapshots') @@ -543,7 +543,7 @@ async def get_component( ('range', 'unit', 'confidence', 'source', 'n')} for k, v in (identity.get('properties') or {}).items() if isinstance(v, dict)}, - 'current_version': { + 'current_snapshot': { 'id': current.get('_id'), 'version': current.get('version'), 'status': current.get('status'), 'shape_class': current.get('shape_class'), @@ -554,26 +554,26 @@ async def get_component( 'effective_from': current.get('effective_from'), 'location': current.get('location'), 'geometry': geometry_summary(current.get('geometry')), - 'reinforcement_layouts': layouts_of_version( + 'reinforcement_layouts': layouts_of_snapshot( layouts, current.get('_id'))}, - 'version_count': len(versions), + 'snapshot_count': len(versions), 'web_link': link_component(identity.get('_id') or component_id), - 'next': ('list_versions, get_evidence and get_timeline take ' + 'next': ('list_snapshots, get_evidence and get_timeline take ' 'this id.')})) # 3 ------------------------------------------------------------------------- - @mcp.tool(title='List the versions of a component', annotations=READ_ONLY) - async def list_versions( + @mcp.tool(title='List the snapshots of a component', annotations=READ_ONLY) + async def list_snapshots( component_id: Annotated[str, Field(description='The component id.')], ) -> dict: - """The versions (states) of a component, oldest first: version number, + """The snapshots of a component, oldest first: version number, status, name, from when it applies, which one is current, with the id - to pass to get_version and a web link for each.""" + to pass to get_snapshot and a web link for each.""" rows = await get(f'/identities/{component_id}/snapshots') return limited(clean({ 'component_id': component_id, 'web_link': link_component(component_id), - 'versions': [{ + 'snapshots': [{ 'id': r.get('_id'), 'version': r.get('version'), 'status': r.get('status'), 'is_current': r.get('is_current'), 'name': r.get('name'), @@ -585,16 +585,16 @@ async def list_versions( for r in rows]})) # 4 ------------------------------------------------------------------------- - @mcp.tool(title='Get one version of a component', annotations=READ_ONLY) - async def get_version( - version_id: Annotated[str, Field(description=( - 'The version id (a UUID) from list_versions.'))], + @mcp.tool(title='Get one snapshot of a component', annotations=READ_ONLY) + async def get_snapshot( + snapshot_id: Annotated[str, Field(description=( + 'The snapshot id (a UUID) from list_snapshots.'))], ) -> dict: - """One version of a component: size, shape class, descriptors, + """One snapshot of a component: size, shape class, descriptors, derived properties, status and notes. The geometry is only a summary (counts); the web link opens the viewer. The reinforcement layouts - of the version are counted from the evidence.""" - s = await get(f'/snapshots/{version_id}') + of the snapshot are counted from the evidence.""" + s = await get(f'/snapshots/{snapshot_id}') identity_id = s.get('identity_id') layouts = await get(f'/identities/{identity_id}/evidence', {'method': 'reinforcement_layout'} @@ -616,7 +616,7 @@ async def get_version( 'supersedes': s.get('supersedes'), 'superseded_by': s.get('superseded_by'), 'geometry': geometry_summary(s.get('geometry')), - 'reinforcement_layouts': layouts_of_version( + 'reinforcement_layouts': layouts_of_snapshot( layouts, s.get('_id')), 'web_link': link_component(identity_id, s.get('_id')) if identity_id else None})) @@ -710,7 +710,7 @@ async def get_dataset( async def get_timeline( component_id: Annotated[str, Field(description='The component id.')], ) -> dict: - """What happened to a component, in order: origin, versions, + """What happened to a component, in order: origin, snapshots, corrections, evidence, changes, how it left circulation. Each event has a kind, a time (with its precision) and a short detail.""" body = await get(f'/identities/{component_id}/timeline') @@ -807,11 +807,11 @@ async def catalog_overview( ) -> dict: """What the catalog holds, in numbers, for the components that match the filters of search_components (none: the whole catalog you may - see). It counts components (one per element or batch, with its current - version), not rows of a list: the total, how many physical elements they + see). It counts components (one per single component or batch, with its current + snapshot), not rows of a list: the total, how many physical elements they stand for, and the counts by material (with its label), original function, dataset, shape class and circulation. The ranges give the - smallest and the largest value of each side of the elements that have a + smallest and the largest value of each side of the components that have a size, sides sorted largest, middle, smallest; lengths are in millimetres. It also says how many components have a current and how many an origin location, and how many of the counted components are @@ -841,7 +841,7 @@ def counted(rows, label_of=None): not_public = int(stats.get('notPublic') or 0) total = int(stats.get('total') or 0) return limited(clean({ - 'counted': 'components with a current version that match the ' + 'counted': 'components with a current snapshot that match the ' 'filters and that you may see', 'total': total, 'pieces': stats.get('pieces'), 'by_material': counted(stats.get('byMaterial'), labels.get), diff --git a/src/backend/apps/catalog/models.py b/src/backend/apps/catalog/models.py index 7902c81a..9ba7a0a9 100644 --- a/src/backend/apps/catalog/models.py +++ b/src/backend/apps/catalog/models.py @@ -376,7 +376,7 @@ class ComponentIdentity(BaseModel): id: str = Field( default_factory=lambda: str(uuid.uuid4()), alias="_id", - description="Globally unique identity identifier (GUID)" + description="Globally unique component id (GUID)" ) catalog_number: int = Field( description=( @@ -432,19 +432,19 @@ class ComponentIdentity(BaseModel): ) attributes: Optional[Dict] = Field( default_factory=dict, - description="Additional static metadata about the physical element" + description="Additional static metadata about the physical component" ) parent_identities: Optional[List[str]] = Field( None, description=( - "UUIDs of immediate parent identities. Single-element for 1:1 " + "UUIDs of immediate parent components. Single-element for 1:1 " "splits; multi-element for N:1 merges. `None` if no known parent." ) ) consumed_at: Optional[str] = Field( None, description=( - "ISO-8601 timestamp when the physical element ceased to exist as " + "ISO-8601 timestamp when the physical component ceased to exist as " "a discrete object (split, demolished, returned). `None` = active." ) ) @@ -458,14 +458,14 @@ class ComponentIdentity(BaseModel): current_snapshot_id: str = Field( description=( "UUID of the snapshot in `component_snapshots` that represents " - "the current state of this identity." + "the current snapshot of this component." ) ) created: str = Field( - description="ISO timestamp when this identity was first recorded" + description="ISO timestamp when this component was first recorded" ) lastmodified: str = Field( - description="ISO timestamp when this identity was last modified" + description="ISO timestamp when this component was last modified" ) @field_validator('componenttype') @@ -521,7 +521,7 @@ def _validate_parent_identities( class ComponentSnapshot(BaseModel): - """State of one identity at one point in time. Version 0 created at M3.""" + """A snapshot: the state of one component at one point in time. Snapshot v0 created at M3.""" id: str = Field( default_factory=lambda: str(uuid.uuid4()), alias="_id", @@ -532,8 +532,8 @@ class ComponentSnapshot(BaseModel): ) version: int = Field( description=( - "Per-identity monotonic version, zero-based. First snapshot for " - "an identity is `0`. Unique on (identity_id, version). " + "Per-component monotonic snapshot number, zero-based. First snapshot for " + "a component is `0`. Unique on (identity_id, version). " "Server-assigned: never accept this field from client payloads; " "the backend computes it (`0` on initial create, " "`max(existing)+1` on snapshot evolution)." @@ -543,14 +543,14 @@ class ComponentSnapshot(BaseModel): default=False, description=( "True when this snapshot represents a hypothetical / proposal " - "(not yet realized on the physical element). Migrated snapshots " + "(not yet realized on the physical component). Migrated snapshots " "from legacy are `False`." ) ) name: Optional[str] = Field( 'Unnamed Component', description=( - "Human readable name for this state (can change across " + "Human readable name for this snapshot (can change across " "snapshots, e.g. on remanufacturing)." ) ) @@ -584,7 +584,7 @@ class ComponentSnapshot(BaseModel): condition: Optional[int] = Field( None, description=( - "Condition grade for this state. 0 = destroyed/retired, " + "Condition grade for this snapshot. 0 = destroyed/retired, " "1 = poor, 2 = average, 3 = good. `None` = unknown." ) ) @@ -595,22 +595,22 @@ class ComponentSnapshot(BaseModel): location: Optional[ComponentLocation] = Field( {'lat': 0.0, 'lon': 0.0}, description=( - "Geographic location of the element at the time of this snapshot. " + "Geographic location of the component at the time of this snapshot. " "PATCH-able on the current snapshot without creating a new one." ) ) processes: Optional[Dict] = Field( default_factory=dict, - description="Manufacturing or processing information for this state" + description="Manufacturing or processing information for this snapshot" ) iframe: ComponentFrame = Field( description=( - "Insertion frame / transformation matrix for this state" + "Insertion frame / transformation matrix for this snapshot" ) ) pca_frame: ComponentFrame = Field( description=( - "PCA frame / principal-component transformation for this state" + "PCA frame / principal-component transformation for this snapshot" ) ) validated: bool = Field( @@ -633,7 +633,7 @@ class ComponentSnapshot(BaseModel): None, description=( "User id of whoever created this snapshot (set on v0 create; " - "records who added the identity to the catalog)" + "records who added the component to the catalog)" ), ) added_by_username: Optional[str] = Field( @@ -646,7 +646,7 @@ class ComponentSnapshot(BaseModel): notes: Optional[str] = Field( None, max_length=5000, - description="Free-text notes for this snapshot state", + description="Free-text notes for this snapshot", ) quantity: int = Field( default=1, @@ -673,7 +673,7 @@ class ComponentSnapshot(BaseModel): description=( "Indices of ``geometry.point_clouds`` whose full cloud is stored " "as a file (``point_clouds//.ply``); set by the " - "upload route. Absent on versions uploaded before the marker " + "upload route. Absent on snapshots uploaded before the marker " "existed. Example: [0]." ), ) diff --git a/src/backend/apps/catalog/permissions.py b/src/backend/apps/catalog/permissions.py index cd9644a6..630b4bc0 100644 --- a/src/backend/apps/catalog/permissions.py +++ b/src/backend/apps/catalog/permissions.py @@ -304,8 +304,9 @@ def _review_verification(viewer: Viewer, roles: Roles, def _revoke_invitation(viewer: Viewer, roles: Roles, target: Target) -> bool: - """Its creator or moderator(D) (8.14).""" - return _author_or_moderator(viewer, roles, target) + """moderator(D) only; the creator loses the right with the role + (8.14, amended by 8.193 c).""" + return 'moderator' in roles RULES: Dict[str, Rule] = { diff --git a/src/backend/apps/catalog/proxies/fit.py b/src/backend/apps/catalog/proxies/fit.py index 113e2a84..d9531daa 100644 --- a/src/backend/apps/catalog/proxies/fit.py +++ b/src/backend/apps/catalog/proxies/fit.py @@ -138,7 +138,7 @@ def fit_primary(source: Source, frame: Dict[str, list], chosen = (spec, fitted, stats, local, signed) break if chosen is None: - raise ValueError(f'no proxy fits a {shape_class} element') + raise ValueError(f'no proxy fits a {shape_class} component') spec, fitted, stats, local, signed = chosen rotation = np.array([fitted.placement['x'], fitted.placement['y'], fitted.placement['z']]) diff --git a/src/backend/apps/catalog/read_models.py b/src/backend/apps/catalog/read_models.py index 868f67de..2f667050 100644 --- a/src/backend/apps/catalog/read_models.py +++ b/src/backend/apps/catalog/read_models.py @@ -29,23 +29,27 @@ # PASSPORT -------------------------------------------------------------------- class ComponentIdentity(documents.ComponentIdentity): - """The identity as the read routes serve it: the stored document plus the + """The component as the read routes serve it: the stored document plus the status of the reservation. ``reserved`` holds the id of the reserving user, which an anonymous caller never gets (8.101); ``is_reserved`` stays for everyone. ``remaining`` is derived for a batch (8.105): its recorded quantity minus the pieces drawn, None for anything else. ``can_undo_deinstall`` says whether the undo of the deinstall act is open - (the passport and the single identity read; False elsewhere). Same + (the passport and the single component read; False elsewhere). Same name as the stored model, so the generated frontend type keeps it.""" is_reserved: bool = False remaining: Optional[int] = None # response-only (8.115 a, P11): true while a deinstall act can still be # taken back; the Actions menu shows "Undo deinstallation" only then can_undo_deinstall: bool = False + # response-only (8.195): a draft or pending version of the element exists. + # Only the fact, for a contributor or moderator of the dataset and admins; + # a constant False for everyone else. Not in the exports. + has_open_snapshot: bool = False class ComponentPassport(BaseModel): - """``GET /identities/{id}/compose``: one identity and its snapshots.""" + """``GET /identities/{id}/compose``: one component and its snapshots.""" identity: ComponentIdentity snapshots: List[ComponentSnapshot] # only with ?include=evidence (spec 7.2): the published evidence, as the @@ -54,9 +58,12 @@ class ComponentPassport(BaseModel): def identity_body(doc: Dict[str, Any]) -> Dict[str, Any]: + """The identity as the read routes serve it. ``has_open_snapshot`` is left + out: only a route that computed it puts it in (8.195), so a write response + or a batch row never claims a False it did not look up.""" return ComponentIdentity.model_validate( {**doc, 'is_reserved': bool(doc.get('reserved'))}).model_dump( - by_alias=True, mode='json') + by_alias=True, mode='json', exclude={'has_open_snapshot'}) def snapshot_body(doc: Dict[str, Any]) -> Dict[str, Any]: @@ -93,15 +100,15 @@ class FitCanHold(BaseModel): """The match of a dimension search *can hold this size* (8.169).""" mode: Literal['can_hold'] waste_mm3: float = Field( - description='box volume of the element minus the asked volume, in mm3') + description='box volume of the component minus the asked volume, in mm3') waste_percent: float = Field( - description='that waste as a share of the box volume of the element, ' + description='that waste as a share of the box volume of the component, ' 'in per cent') class CatalogRow(BaseModel): """ - One catalog list row: identity core + current-snapshot metadata. Not a + One catalog list row: component core + current-snapshot metadata. Not a stored document; the list, map and children routes serve it. """ model_config = ConfigDict(populate_by_name=True) @@ -121,17 +128,17 @@ class CatalogRow(BaseModel): is_public: bool = False has_preview: Optional[bool] = Field( default=None, - description='whether the current state has a rendered preview ' + description='whether the current snapshot has a rendered preview ' '(list rows only; absent elsewhere)') current_snapshot_id: Optional[str] = None fit: Optional[Union[FitAbout, FitCanHold]] = Field( default=None, - description='how close the element is to the asked size, while the ' + description='how close the component is to the asked size, while the ' 'list has a dimension search (fit_mode); absent otherwise') distance_m: Optional[float] = Field( default=None, description='distance in metres from the near point of the list ' - '(near_lat, near_lon) to the element, on the layer asked ' + '(near_lat, near_lon) to the component, on the layer asked ' '(near_layer); absent without a near search') # current snapshot identity_id: str @@ -154,7 +161,7 @@ class CatalogRow(BaseModel): class LocationPoint(BaseModel): - """One element on the location map (``GET /identities/locations``): where + """One component on the location map (``GET /identities/locations``): where it is and what the map colours and labels it by.""" id: str catalog_number: Optional[int] = None @@ -175,11 +182,11 @@ class LocationMap(BaseModel): """The points of the location map (decisions 8.170, 8.171).""" layer: Literal['current', 'origin'] total: int = Field( - description='the elements this caller may see that match the filters') + description='the components this caller may see that match the filters') displayed: int = Field( description='of those, the ones with a point on the layer') left_out: int = Field( - description='the elements without a point on the layer') + description='the components without a point on the layer') points: List[LocationPoint] @@ -194,15 +201,15 @@ class SimilarPiece(BaseModel): class SimilarPieces(BaseModel): - """``GET /identities/{id}/similar``: the nearest elements by descriptor.""" + """``GET /identities/{id}/similar``: the nearest components by descriptor.""" query_id: str basis: Literal['radial_signature', 'scalars', 'hks'] basis_label: str computed_at: Optional[str] = Field( default=None, description='when the matrix of the catalog was built') considered: int = Field( - description='how many visible elements that pass the filters were ' - 'ranked (the query element not among them)') + description='how many visible components that pass the filters were ' + 'ranked (the query component not among them)') results: List[SimilarPiece] @@ -294,17 +301,19 @@ class PendingSnapshotItem(BaseModel): original_function: Optional[str] = None material: Optional[str] = None dataset: Optional[str] = None + identity_withdrawn: bool = Field( + default=False, description='the component is withdrawn (8.190): no publish') live_version: Optional[int] = Field( default=None, - description='Version of the identity\'s current snapshot, if any') + description='Number of the current snapshot of the component, if any') supersedes: Optional[str] = Field( default=None, description='set when this corrects a published one') added_by_username: Optional[str] = None class MySnapshotItem(BaseModel): - """Row for ``GET /snapshots?mine=1``: one of the caller's own versions, - with the element it belongs to and, for a rejected one, the reason.""" + """Row for ``GET /snapshots?mine=1``: one of the caller's own snapshots, + with the component it belongs to and, for a rejected one, the reason.""" model_config = ConfigDict(populate_by_name=True) id: str = Field(alias='_id') @@ -319,6 +328,8 @@ class MySnapshotItem(BaseModel): original_function: Optional[str] = None material: Optional[str] = None dataset: Optional[str] = None + identity_withdrawn: bool = Field( + default=False, description='the component is withdrawn (8.190): no submit') supersedes: Optional[str] = Field( default=None, description='set when this corrects a published one') rejection_reason: Optional[str] = Field( diff --git a/src/backend/apps/catalog/vocab.py b/src/backend/apps/catalog/vocab.py index 086037e6..d8c4ed5d 100644 --- a/src/backend/apps/catalog/vocab.py +++ b/src/backend/apps/catalog/vocab.py @@ -189,7 +189,7 @@ 'withdraw': 'Withdrawn', 'reinstate': 'Reinstated', 'migration': 'Migration', - 'derived_exit': 'Cut into elements', + 'derived_exit': 'Cut into components', 'deinstall': 'Deinstalled', 'undo_deinstall': 'Deinstallation undone', 'verify': 'Verification changed', @@ -564,7 +564,7 @@ class MaterialSeed: '17 06 04'), MaterialSeed('polymer_foam', 'Polymer foam insulation (EPS, XPS, PUR/PIR)', 'insulation', '17 06 04'), - MaterialSeed('mixed', 'Mixed / composite element', 'other', '17 09 04'), + MaterialSeed('mixed', 'Mixed / composite component', 'other', '17 09 04'), MaterialSeed('unknown', 'Unknown', 'other', '17 09 04'), ) MATERIAL_SEED_BY_ID: Dict[str, MaterialSeed] = { @@ -675,7 +675,7 @@ class MaterialSeed: 'IfcRailing': 'A railing or balustrade.', 'IfcDuctSegment': 'A length of ventilation duct.', 'IfcBuildingElementProxy': 'The former function is not known.', - 'CscDebris': 'No former function as a single element: rubble, aggregate, fragments.', + 'CscDebris': 'No former function as a single component: rubble, aggregate, fragments.', }, 'shape_class': { 'linear': 'One extent is much larger than the other two, like a beam or a column.', @@ -686,18 +686,18 @@ class MaterialSeed: }, 'origin_kind': { 'deinstallation': 'Taken out of a construction work in which it was installed.', - 'demolition': 'Recovered from demolition output, not taken out as a single element.', + 'demolition': 'Recovered from demolition output, not taken out as a single component.', 'offcut': 'Residue of a fabrication process; it was never installed.', 'surplus': 'An unused whole product: overstock, a return or a site leftover.', - 'unknown': 'Where the element came from is not recorded.', + 'unknown': 'Where the component came from is not recorded.', }, 'exit_kind': { - 'split': 'Cut into smaller elements; they are catalogued as children of this element.', - 'merged': 'Joined with other elements into a new element, which is catalogued as its child.', - 'installed': 'Built into a construction work. The element still exists and may come back.', - 'recycled': 'The material was recovered, for example crushed or melted; the element is gone.', + 'split': 'Cut into smaller components; they are catalogued as children of this component.', + 'merged': 'Joined with other components into a new component, which is catalogued as its child.', + 'installed': 'Built into a construction work. The component still exists and may come back.', + 'recycled': 'The material was recovered, for example crushed or melted; the component is gone.', 'disposed': 'Disposed of as waste.', - 'returned': 'Given back to its owner or supplier. The element exists but left the custody of the catalog.', + 'returned': 'Given back to its owner or supplier. The component exists but left the custody of the catalog.', 'lost': 'Its whereabouts are not recorded.', }, 'status': { @@ -753,24 +753,24 @@ class MaterialSeed: 'polymer': 'Plastics and plastic composites, such as acrylic, PVC and solid surface.', 'bituminous': 'Asphalt and bituminous membranes.', 'insulation': 'Mineral wool and polymer foam insulation.', - 'other': 'Mixed or composite elements, and materials not known.', + 'other': 'Mixed or composite components, and materials not known.', }, 'evidence_method': { 'rebound_hammer': 'A rebound hammer test of concrete: at least nine readings, no strength by itself.', 'core_compression': 'A drilled core crushed in a press; a destructive test with a measured strength.', - 'archival_document': 'A drawing, report, type plate or marking that documents the element; it may carry a claim.', + 'archival_document': 'A drawing, report, type plate or marking that documents the component; it may carry a claim.', 'visual_inspection': 'An observation of the condition: cracks, spalling, corrosion or an overall grade.', 'era_heuristic': 'An estimate from the year of construction, the regional practice or the type.', 'manufacturer_datasheet': 'A claim from the manufacturer of the product.', - 'reinforcement_layout': 'The reinforcement bars of the element as centre lines in its coordinates.', + 'reinforcement_layout': 'The reinforcement bars of the component as centre lines in its coordinates.', }, 'source_tier': { 'destructive': 'A test that destroys a sample. For most quantities the most trusted source.', - 'ndt': 'A test that leaves the element intact, with an instrument.', + 'ndt': 'A test that leaves the component intact, with an instrument.', 'archival': 'A claim from a document, a drawing or a datasheet.', 'visual': 'An observation by a person.', 'heuristic': 'An estimate from rules of thumb. The least trusted source.', - 'inherited': 'Taken over from a parent element, with a lower confidence.', + 'inherited': 'Taken over from a parent component, with a lower confidence.', }, 'verification_state': { 'unverified': 'No one has confirmed it yet. It counts with a low weight.', @@ -792,7 +792,7 @@ class MaterialSeed: 'exposure_class': 'Exposure class of the concrete after EN 206, such as XC3.', 'chloride_content': 'Chloride content, as a percentage of the mass of cement.', 'elastic_modulus': 'Stiffness of the material (GPa).', - 'mass': 'Weight of the element in this state (kg).', + 'mass': 'Weight of the component in this snapshot (kg).', 'carbonation_depth': 'Depth to which the concrete is carbonated (mm).', 'spalling': 'Severity of spalled concrete, from 0 (none) to 3 (severe).', 'cracking': 'Severity of cracking, from 0 (none) to 3 (severe).', diff --git a/src/backend/main_fastapi.py b/src/backend/main_fastapi.py index bf9501ce..8c5d48e1 100644 --- a/src/backend/main_fastapi.py +++ b/src/backend/main_fastapi.py @@ -176,6 +176,10 @@ async def lifespan(app: FastAPI): await app.mongodb_component_snapshots.create_index( 'derivation_due', name='derivation_due_marked', partialFilterExpression=DUE_INDEX['partialFilterExpression']) + # has_open_snapshot (8.195): one find_one on the element and the open + # statuses + await app.mongodb_component_snapshots.create_index( + [('identity_id', 1), ('status', 1)]) await app.mongodb_component_evidence.create_index('identity_id') await app.mongodb_component_evidence.create_index( [('status', 1), ('method', 1)]) diff --git a/src/backend/templates/mail/dataset_created.html.j2 b/src/backend/templates/mail/dataset_created.html.j2 index e65e9ceb..ab333720 100644 --- a/src/backend/templates/mail/dataset_created.html.j2 +++ b/src/backend/templates/mail/dataset_created.html.j2 @@ -2,5 +2,5 @@ {% from "_macros.html.j2" import p %} {% block body %} {% call p() %}{{ by_name }} created the dataset "{{ dataset_name }}" ({{ slug }}).{% endcall %} -{% call p() %}It is visible to its members only, and its elements cannot be made public until you have reviewed it.{% endcall %} +{% call p() %}It is visible to its members only, and its components cannot be made public until you have reviewed it.{% endcall %} {% endblock %} diff --git a/src/backend/templates/mail/dataset_created.txt.j2 b/src/backend/templates/mail/dataset_created.txt.j2 index 08d9b8b3..d2b672f3 100644 --- a/src/backend/templates/mail/dataset_created.txt.j2 +++ b/src/backend/templates/mail/dataset_created.txt.j2 @@ -2,5 +2,5 @@ {% block body -%} {{ by_name }} created the dataset "{{ dataset_name }}" ({{ slug }}). -It is visible to its members only, and its elements cannot be made public until you have reviewed it. +It is visible to its members only, and its components cannot be made public until you have reviewed it. {%- endblock %} diff --git a/tests/api/test_exports_routes.py b/tests/api/test_exports_routes.py index 030708a7..2e3b8ff5 100644 --- a/tests/api/test_exports_routes.py +++ b/tests/api/test_exports_routes.py @@ -347,7 +347,7 @@ def test_cero_covers_concrete_only(world): steel = _published(world, material='steel') got = api.get(f'/identities/{steel}/export/cero', headers=world['m']) assert got.status_code == 409 - assert got.json()['detail'] == 'CERO covers concrete elements only' + assert got.json()['detail'] == 'CERO covers concrete components only' # the other exports of the same piece are fine assert api.get(f'/identities/{steel}/export/pdf', headers=world['m']).status_code == 200 diff --git a/tests/api/test_invitation_accept.py b/tests/api/test_invitation_accept.py index 15b2ccd5..c4723715 100644 --- a/tests/api/test_invitation_accept.py +++ b/tests/api/test_invitation_accept.py @@ -242,7 +242,7 @@ def test_accepting_is_limited_per_user(world): # RESEND NEEDS THE CURRENT PERMISSION ----------------------------------------- -def test_a_demoted_moderator_cannot_resend_but_can_still_revoke(world): +def test_a_demoted_moderator_can_neither_resend_nor_revoke(world): api, db = world['api'], world['db'] made = _invite(world, world['moderator'], ['late@partner.example']) iid = made.json()[0]['invitation']['_id'] @@ -254,9 +254,14 @@ def test_a_demoted_moderator_cannot_resend_but_can_still_revoke(world): # an admin may; so may a moderator of the dataset assert api.post(f'/invitations/{iid}/resend', headers=world['admin']).status_code == 200 - # revoke stays with the creator + # revoke goes with the role as well (8.193 c): the creator loses it assert api.delete(f'/invitations/{iid}', - headers=world['moderator']).status_code == 200 + headers=world['moderator']).status_code == 403 + assert api.get('/invitations', + headers=world['moderator']).status_code == 403 + # an admin revokes it (a moderator of the dataset: test_invitations.py) + assert api.delete(f'/invitations/{iid}', + headers=world['admin']).status_code == 200 def test_a_moderator_of_another_dataset_and_a_user_cannot_resend( diff --git a/tests/api/test_loaders.py b/tests/api/test_loaders.py index 7a7f823d..983ac2be 100644 --- a/tests/api/test_loaders.py +++ b/tests/api/test_loaders.py @@ -84,7 +84,7 @@ def check(world, rows): def standard_rows(kind, read_or_write, make, existing, member_ok, purged=True): """The rows every kind shares; ``make(id)`` is the call, ``existing`` the id of a record that is not public.""" - name = kind.capitalize() + name = 'Component' if kind == 'identity' else kind.capitalize() rows = [ (f'{kind} {read_or_write}: a malformed id', 'admin' if read_or_write == 'write' else 'anonymous', make(MALFORMED), 404, f'{name} not found'), @@ -272,4 +272,4 @@ def test_a_component_without_a_current_state(world): for path in (url, f'/identities/{iid("beam")}/compose'): response = world['api'].get(path, headers=headers) assert response.status_code == 409, (path, response.status_code, response.text[:100]) - assert 'no current state' in response.json()['detail'], path + assert 'no current snapshot' in response.json()['detail'], path diff --git a/tests/api/test_mcp_endpoint.py b/tests/api/test_mcp_endpoint.py index 57ce5e37..aab33eaa 100644 --- a/tests/api/test_mcp_endpoint.py +++ b/tests/api/test_mcp_endpoint.py @@ -27,7 +27,7 @@ ) from support import iid, seed_05_catalog, sid -TOOLS = {'search_components', 'get_component', 'list_versions', 'get_version', +TOOLS = {'search_components', 'get_component', 'list_snapshots', 'get_snapshot', 'get_evidence', 'list_datasets', 'get_dataset', 'get_timeline', 'similar_components', 'catalog_overview'} WEB = 'http://localhost:3000' @@ -173,8 +173,8 @@ def test_the_tools_write_nothing(api, db, world): 'change_log', 'users', 'invitations') before = {n: sorted(map(repr, db[n].find({}))) for n in names} for name, args in (('search_components', {}), ('get_component', {'component_id': iid('beam')}), - ('list_versions', {'component_id': iid('beam')}), - ('get_version', {'version_id': sid('beam', 1)}), + ('list_snapshots', {'component_id': iid('beam')}), + ('get_snapshot', {'snapshot_id': sid('beam', 1)}), ('get_evidence', {'component_id': iid('beam')}), ('list_datasets', {}), ('get_dataset', {'dataset_id': 'dbu_zirkus'}), ('get_timeline', {'component_id': iid('beam')})): @@ -448,8 +448,8 @@ def test_nothing_private_reaches_an_account_without_a_role_in_the_dataset(api, w assert iid('beam') not in str(found) is_error, text = tool_result(api, plain['pat'], 'get_component', component_id=iid('beam')) assert is_error and text.endswith('Not found, or not visible to you.') - for name, args in (('list_versions', {'component_id': iid('beam')}), - ('get_version', {'version_id': sid('beam', 1)}), + for name, args in (('list_snapshots', {'component_id': iid('beam')}), + ('get_snapshot', {'snapshot_id': sid('beam', 1)}), ('get_evidence', {'component_id': iid('beam')}), ('get_timeline', {'component_id': iid('beam')}), ('get_dataset', {'dataset_id': 'dbu_zirkus'})): @@ -475,11 +475,11 @@ def test_get_component_is_short_with_a_geometry_summary_and_its_links(api, world assert answer['origin']['place'] == 'TU Darmstadt Lichtwiese Campus' assert answer['properties']['rebar_diameter']['unit'] == 'mm' assert 'confidence' in answer['properties']['rebar_diameter'] - current = answer['current_version'] + current = answer['current_snapshot'] assert current['version'] == 1 and current['status'] == 'published' and current['id'] == sid('beam', 1) assert current['geometry']['meshes'] == 1 and current['geometry']['mesh_vertices'] == 4 assert 'Geometry is not sent' in current['geometry']['note'] - assert answer['version_count'] == 2 + assert answer['snapshot_count'] == 2 assert answer['web_link'] == f'{WEB}/components/{iid("beam")}' text = json.dumps(answer) assert '"vertices"' not in text and '"faces"' not in text @@ -491,12 +491,12 @@ def test_an_unknown_component_is_not_found_not_an_error_of_ours(api, world): assert is_error and text.endswith('Not found, or not visible to you.') or 'not valid' in text, text -def test_list_versions_and_get_version(api, world): - versions = tool(api, world['admin'], 'list_versions', component_id=iid('beam')) - assert [v['version'] for v in versions['versions']] == [0, 1] - assert [v['is_current'] for v in versions['versions']] == [False, True] - assert versions['versions'][1]['web_link'] == f'{WEB}/components/{iid("beam")}?snapshot={sid("beam", 1)}' - one = tool(api, world['admin'], 'get_version', version_id=sid('beam', 1)) +def test_list_snapshots_and_get_snapshot(api, world): + versions = tool(api, world['admin'], 'list_snapshots', component_id=iid('beam')) + assert [v['version'] for v in versions['snapshots']] == [0, 1] + assert [v['is_current'] for v in versions['snapshots']] == [False, True] + assert versions['snapshots'][1]['web_link'] == f'{WEB}/components/{iid("beam")}?snapshot={sid("beam", 1)}' + one = tool(api, world['admin'], 'get_snapshot', snapshot_id=sid('beam', 1)) assert one['id'] == sid('beam', 1) and one['component_id'] == iid('beam') and one['status'] == 'published' assert one['geometry'] == {'meshes': 1, 'mesh_vertices': 4, 'mesh_faces': 4, 'point_clouds': 0, 'proxies': 0, 'note': 'Geometry is not sent; open the web link to see it.'} @@ -531,8 +531,8 @@ def test_no_e_mail_address_and_no_account_id_in_any_answer(api, db, world): answers = [] for name, args in (('search_components', {'circulation': 'all', 'status': 'any'}), ('get_component', {'component_id': iid('beam')}), - ('list_versions', {'component_id': iid('beam')}), - ('get_version', {'version_id': sid('beam', 1)}), + ('list_snapshots', {'component_id': iid('beam')}), + ('get_snapshot', {'snapshot_id': sid('beam', 1)}), ('get_evidence', {'component_id': iid('beam')}), ('get_evidence', {'evidence_id': record['_id']}), ('list_datasets', {}), ('get_dataset', {'dataset_id': 'dbu_zirkus'}), @@ -895,28 +895,28 @@ def test_the_geometry_summary_has_no_reinforcement_count_any_more(): def test_a_version_reports_its_reinforcement_layouts_from_the_evidence(api, db, world): admin = world['admin'] component = tool(api, admin, 'get_component', component_id=iid('beam')) - layouts = component['current_version']['reinforcement_layouts'] + layouts = component['current_snapshot']['reinforcement_layouts'] assert layouts['records'] == 1 and layouts['bars'] == 1 assert 'get_evidence' in layouts['note'] and 'reinforcement_layout' in layouts['note'] - assert 'reinforcements' not in component['current_version']['geometry'] - assert 'Geometry is not sent' in component['current_version']['geometry']['note'] - now = tool(api, admin, 'get_version', version_id=sid('beam', 1)) + assert 'reinforcements' not in component['current_snapshot']['geometry'] + assert 'Geometry is not sent' in component['current_snapshot']['geometry']['note'] + now = tool(api, admin, 'get_snapshot', snapshot_id=sid('beam', 1)) assert now['reinforcement_layouts']['records'] == 1 and now['reinforcement_layouts']['bars'] == 1 assert 'reinforcements' not in now['geometry'] # the layout names version 1: the version before it has none - before = tool(api, admin, 'get_version', version_id=sid('beam', 0)) + before = tool(api, admin, 'get_snapshot', snapshot_id=sid('beam', 0)) assert before['reinforcement_layouts']['records'] == 0 and before['reinforcement_layouts']['bars'] == 0 plain_piece = tool(api, admin, 'get_component', component_id=iid('feld')) - assert plain_piece['current_version']['reinforcement_layouts']['records'] == 0 + assert plain_piece['current_snapshot']['reinforcement_layouts']['records'] == 0 def test_a_pending_layout_is_not_counted_and_two_records_add_their_bars(api, db, world): admin = world['admin'] pending = _layout_for(db, 'beam', status='pending') db['component_evidence'].update_one({'_id': pending}, {'$set': {'position.snapshot_id': sid('beam', 1)}}) - assert tool(api, admin, 'get_version', version_id=sid('beam', 1))['reinforcement_layouts']['records'] == 1 + assert tool(api, admin, 'get_snapshot', snapshot_id=sid('beam', 1))['reinforcement_layouts']['records'] == 1 db['component_evidence'].update_one({'_id': pending}, {'$set': {'status': 'published'}}) - counted = tool(api, admin, 'get_version', version_id=sid('beam', 1))['reinforcement_layouts'] + counted = tool(api, admin, 'get_snapshot', snapshot_id=sid('beam', 1))['reinforcement_layouts'] assert counted['records'] == 2 and counted['bars'] == 2 @@ -926,10 +926,10 @@ def record(snapshot, bars, status='published', method='reinforcement_layout'): 'payload': {'bars': [{}] * bars}} rows = [record('a', 3), record('a', 2), record('b', 7), record('a', 9, status='pending'), record('a', 5, method='visual_inspection'), {'method': 'reinforcement_layout', 'status': 'withdrawn'}] - assert mcp_server.layouts_of_version(rows, 'a')['records'] == 2 - assert mcp_server.layouts_of_version(rows, 'a')['bars'] == 5 - assert mcp_server.layouts_of_version(rows, 'c')['records'] == 0 - assert mcp_server.layouts_of_version(None, 'a')['bars'] == 0 + assert mcp_server.layouts_of_snapshot(rows, 'a')['records'] == 2 + assert mcp_server.layouts_of_snapshot(rows, 'a')['bars'] == 5 + assert mcp_server.layouts_of_snapshot(rows, 'c')['records'] == 0 + assert mcp_server.layouts_of_snapshot(None, 'a')['bars'] == 0 def test_a_layout_row_carries_a_summary_of_its_bars(api, db, world): @@ -942,7 +942,7 @@ def test_a_layout_row_carries_a_summary_of_its_bars(api, db, world): row = tool(api, admin, 'get_evidence', component_id=iid('beam'), method='reinforcement_layout')['evidence'][0] assert row['reinforcement'] == {'bars': 3, 'basis': 'drawing', 'specs': ['BSt I', 'BSt III'], 'diameters_mm': [8.0, 12.0], 'cover_mm': {'min': 25, 'max': 40}, - 'version_id': sid('beam', 1)} + 'snapshot_id': sid('beam', 1)} assert 'payload' not in row and 'points' not in json.dumps(row) full = tool(api, admin, 'get_evidence', evidence_id=row['id']) assert len(full['record']['payload']['bars']) == 3 diff --git a/tests/api/test_move_identity.py b/tests/api/test_move_identity.py new file mode 100644 index 00000000..f650d4b8 --- /dev/null +++ b/tests/api/test_move_identity.py @@ -0,0 +1,257 @@ +""" +Moving an element to another dataset (decision 8.191, #50): +``POST /identities/{id}/move``, rule ``move_identity`` --- a moderator of the +source and of the destination dataset. It changes the field ``dataset`` on +the identity and writes a change-log entry; a withdrawn element moves; a +version or record that is draft or pending stops it; a public element does not +move into an unreviewed dataset unless an admin moves it; a dataset emptied +this way can be deleted. +""" + +from __future__ import annotations + +import pytest + +from apps.catalog.migration06.steps import CUTOVER_STEPS, Context, run +from evidence_samples import claim_body +from support import iid, seed_05_catalog, sid + +BEAM = iid('beam') # dbu_zirkus +FELD = iid('feld') # schoenes_neues_feld, its only element +SOURCE = 'dbu_zirkus' +TARGET = 'ddu_aggregations' + + +@pytest.fixture +def world(api, db, auth_headers, member_headers): + seed_05_catalog(db) + run(Context(db=db, files=False, log=lambda _m: None), CUTOVER_STEPS) + both, both_id = member_headers({SOURCE: ['moderator'], + TARGET: ['moderator']}) + source_only, _ = member_headers({SOURCE: ['moderator']}) + target_only, _ = member_headers({TARGET: ['moderator']}) + contributor, contributor_id = member_headers({SOURCE: ['contributor']}) + return {'api': api, 'db': db, 'both': both, 'both_id': both_id, + 'src': source_only, 'dst': target_only, 'c': contributor, + 'cid': contributor_id, 'admin': auth_headers('admin'), + 'user': auth_headers('user')} + + +def _move(w, headers, identity=BEAM, dataset=TARGET): + return w['api'].post(f'/identities/{identity}/move', + json={'dataset': dataset}, headers=headers) + + +def _stored(w, identity=BEAM): + return w['db']['component_identities'].find_one({'_id': identity}) + + +# WHO --------------------------------------------------------------------------- +def test_a_moderator_of_both_datasets_moves_the_element(world): + w, api = world, world['api'] + # a members-only destination: only its own members read what is in it + w['db']['datasets'].update_one({'_id': TARGET}, + {'$set': {'visibility': 'members'}}) + before = _stored(w) + done = _move(w, w['both']) + assert done.status_code == 200, done.text + assert done.json()['dataset'] == TARGET + after = _stored(w) + assert after['dataset'] == TARGET + # the move changes that field and nothing else: the catalog number is + # global and the versions stay where they are + assert after['catalog_number'] == before['catalog_number'] + assert after['current_snapshot_id'] == before['current_snapshot_id'] + assert api.get(f'/identities/{BEAM}/compose', + headers=w['both']).status_code == 200 + # a change-log entry names the move + entry = w['db']['change_log'].find_one({'record_id': BEAM, + 'cause': 'patch'}) + assert entry['by_user_id'] == w['both_id'] + assert entry['at'] == after['lastmodified'] + assert entry['changes'] == [{'path': 'dataset', 'old': SOURCE, + 'new': TARGET}] + # the rights follow the dataset: a contributor of the old one lost sight + # of the element that is not public + assert api.get(f'/identities/{BEAM}/compose', + headers=w['c']).status_code == 403 + + +def test_an_admin_moves_the_element(world): + done = _move(world, world['admin']) + assert done.status_code == 200, done.text + assert _stored(world)['dataset'] == TARGET + + +def test_nobody_else_moves_it(world): + w = world + for who in ('src', 'dst', 'c', 'user'): + refused = _move(w, w[who]) + assert refused.status_code == 403, (who, refused.text) + assert w['api'].post(f'/identities/{BEAM}/move', + json={'dataset': TARGET}).status_code == 401 + assert _stored(w)['dataset'] == SOURCE + assert w['db']['change_log'].find_one({'record_id': BEAM}) is None + # a caller who may not move from the source hears no word of the target + for who in ('dst', 'c', 'user'): + assert _move(w, w[who], dataset='nowhere').status_code == 403 + + +# WHAT THE DESTINATION IS ------------------------------------------------------- +def test_an_unknown_destination_and_the_same_dataset_are_refused(world): + w = world + unknown = _move(w, w['both'], dataset='nowhere') + assert unknown.status_code == 422 and 'unknown dataset' in unknown.text + same = _move(w, w['both'], dataset=SOURCE) + assert same.status_code == 409 and 'already' in same.json()['detail'] + # a moderator of the source and an admin hear the same of an unknown one + for who in ('src', 'admin'): + assert _move(w, w[who], dataset='nowhere').status_code == 422 + assert _move(w, w['admin'], dataset=SOURCE).status_code == 409 + assert _move(w, w['both'], identity=iid('nobody')).status_code == 404 + assert _stored(w)['dataset'] == SOURCE + + +def test_the_body_names_the_dataset_only(world): + api, w = world['api'], world + assert api.post(f'/identities/{BEAM}/move', json={}, + headers=w['both']).status_code == 422 + assert api.post(f'/identities/{BEAM}/move', + json={'dataset': TARGET, 'all': True}, + headers=w['both']).status_code == 422 + + +# DRAFT AND PENDING ------------------------------------------------------------- +def _add_version(w, status): + snapshot = w['db']['component_snapshots'].find_one({'_id': sid('beam', 1)}) + snapshot.update({'_id': sid('beam', 2), 'version': 2, 'status': status, + 'superseded_by': None, 'supersedes': None}) + w['db']['component_snapshots'].insert_one(snapshot) + return snapshot['_id'] + + +@pytest.mark.parametrize('status', ['draft', 'pending']) +def test_a_draft_or_pending_version_stops_the_move(world, status): + w = world + open_id = _add_version(w, status) + for who in ('both', 'admin'): + refused = _move(w, w[who]) + assert refused.status_code == 409, (who, refused.text) + assert 'draft or pending' in refused.json()['detail'] + assert _stored(w)['dataset'] == SOURCE + # the version leaves: the move goes through + w['db']['component_snapshots'].update_one( + {'_id': open_id}, {'$set': {'status': 'rejected'}}) + assert _move(w, w['both']).status_code == 200 + + +@pytest.mark.parametrize('submit', [False, True]) +def test_a_draft_or_pending_evidence_record_stops_the_move(world, submit): + w, api = world, world['api'] + created = api.post(f'/identities/{BEAM}/evidence', json=claim_body(), + headers=w['c']) + assert created.status_code == 201, created.text + eid = created.json()['_id'] + if submit: + assert api.post(f'/evidence/{eid}/submit', + headers=w['c']).status_code == 200 + for who in ('both', 'admin'): + refused = _move(w, w[who]) + assert refused.status_code == 409, (who, refused.text) + assert 'draft or pending' in refused.json()['detail'] + assert api.delete(f'/evidence/{eid}', headers=w['c']).status_code in ( + 200, 204) + assert _move(w, w['both']).status_code == 200 + + +# WITHDRAWN --------------------------------------------------------------------- +def test_a_withdrawn_element_moves(world): + w, api = world, world['api'] + assert api.post(f'/identities/{BEAM}/withdraw', json={'reason': 'x'}, + headers=w['both']).status_code == 200 + done = _move(w, w['both']) + assert done.status_code == 200, done.text + assert _stored(w)['dataset'] == TARGET and _stored(w)['withdrawn'] + + +# UNREVIEWED -------------------------------------------------------------------- +def _unreview(w): + w['db']['datasets'].update_one({'_id': TARGET}, {'$set': { + 'reviewed': False}}) + + +def test_a_public_element_does_not_move_into_an_unreviewed_dataset(world): + w = world + _unreview(w) + w['db']['component_identities'].update_one({'_id': BEAM}, {'$set': { + 'is_public': True}}) + refused = _move(w, w['both']) + assert refused.status_code == 409, refused.text + assert 'not been reviewed' in refused.json()['detail'] + assert _stored(w)['dataset'] == SOURCE + # an admin may (8.139 c) + assert _move(w, w['admin']).status_code == 200 + assert _stored(w)['dataset'] == TARGET + + +def test_a_non_public_element_moves_into_an_unreviewed_dataset(world): + w = world + _unreview(w) + assert _stored(w)['is_public'] is False + assert _move(w, w['both']).status_code == 200 + + +# THE EMPTIED DATASET ----------------------------------------------------------- +def test_a_dataset_emptied_by_the_move_can_be_deleted(world, member_headers): + w, api = world, world['api'] + owner, _ = member_headers({'schoenes_neues_feld': ['moderator'], + SOURCE: ['moderator']}) + held = api.delete('/datasets/schoenes_neues_feld', headers=owner) + assert held.status_code == 409 + assert 'move them' in held.json()['detail'] + assert _move(w, owner, identity=FELD, dataset=SOURCE).status_code == 200 + done = api.delete('/datasets/schoenes_neues_feld', headers=owner) + assert done.status_code == 200, done.text + assert done.json()['deleted'] == 'schoenes_neues_feld' + assert w['db']['datasets'].find_one( + {'_id': 'schoenes_neues_feld'}) is None + assert _stored(w, FELD)['dataset'] == SOURCE + + +def test_a_dataset_emptied_by_the_move_can_be_deleted_by_an_admin(world): + w, api = world, world['api'] + assert api.delete('/datasets/schoenes_neues_feld', + headers=w['admin']).status_code == 409 + assert _move(w, w['admin'], identity=FELD, dataset=SOURCE + ).status_code == 200 + assert api.delete('/datasets/schoenes_neues_feld', + headers=w['admin']).status_code == 200 + + +def test_a_public_element_moves_into_a_reviewed_dataset(world): + w = world + w['db']['datasets'].update_one({'_id': TARGET}, {'$set': { + 'reviewed': True}}) + w['db']['component_identities'].update_one({'_id': BEAM}, {'$set': { + 'is_public': True}}) + assert _move(w, w['both']).status_code == 200 + assert _stored(w)['dataset'] == TARGET + + +def test_a_withdrawn_element_with_open_records_moves_once_they_are_gone(world): + w, api = world, world['api'] + created = api.post(f'/identities/{BEAM}/evidence', json=claim_body(), + headers=w['c']) + assert created.status_code == 201, created.text + eid = created.json()['_id'] + open_id = _add_version(w, 'draft') + assert api.post(f'/identities/{BEAM}/withdraw', json={'reason': 'x'}, + headers=w['both']).status_code == 200 + assert _move(w, w['both']).status_code == 409 + # a moderator deletes both, then the move goes through + assert api.delete(f'/snapshots/{open_id}', + headers=w['both']).status_code in (200, 204) + assert api.delete(f'/evidence/{eid}', + headers=w['both']).status_code in (200, 204) + assert _move(w, w['both']).status_code == 200 + assert _stored(w)['dataset'] == TARGET and _stored(w)['withdrawn'] diff --git a/tests/api/test_my_snapshots.py b/tests/api/test_my_snapshots.py index 558e7a15..fa27f213 100644 --- a/tests/api/test_my_snapshots.py +++ b/tests/api/test_my_snapshots.py @@ -109,3 +109,40 @@ def test_the_status_filter_and_the_required_flag(world): assert w['api'].get('/snapshots', params={'mine': 1, 'status': 'bogus'}, headers=w['c']).status_code == 422 assert w['api'].get('/snapshots', params={'mine': 1}).status_code == 401 + + +def _withdraw_in_db(w, identity_id): + w['db']['component_identities'].update_one( + {'_id': identity_id}, + {'$set': {'withdrawn': {'at': '2026-11-01T00:00:00Z', + 'reason': 'test'}}}) + + +def test_a_row_says_whether_its_element_is_withdrawn(world): + """8.190: the web offers no submit on a draft of a withdrawn element.""" + w = world + kept = _piece(w, w['c'], 'kept') + gone = _piece(w, w['c'], 'gone') + assert {r['name']: r['identity_withdrawn'] for r in _mine(w, w['c'])} == { + 'kept': False, 'gone': False} + _withdraw_in_db(w, gone['identity']['_id']) + assert {r['name']: r['identity_withdrawn'] for r in _mine(w, w['c'])} == { + 'kept': False, 'gone': True} + assert kept + + +def test_a_queue_row_says_whether_its_element_is_withdrawn(world): + """8.190: the queue offers no publish on a version of a withdrawn element.""" + w = world + for name in ('queued', 'queued but withdrawn'): + made = _piece(w, w['c'], name) + assert w['api'].post(f"/snapshots/{made['snapshot']['_id']}/submit", + headers=w['c']).status_code == 200 + if name != 'queued': + _withdraw_in_db(w, made['identity']['_id']) + + def flags(): + got = w['api'].get('/snapshots/pending', headers=w['m']) + assert got.status_code == 200, got.text + return {r['name']: r['identity_withdrawn'] for r in got.json()} + assert flags() == {'queued': False, 'queued but withdrawn': True} diff --git a/tests/api/test_no_piece_in_user_text.py b/tests/api/test_no_piece_in_user_text.py index e40a8c3f..915371da 100644 --- a/tests/api/test_no_piece_in_user_text.py +++ b/tests/api/test_no_piece_in_user_text.py @@ -1,4 +1,4 @@ -"""'Element', not 'piece' (decision 8.183): no text a user reads from the +"""'Component' (or 'element', an item of a batch), not 'piece' (decision 8.183): no text a user reads from the backend says 'piece' or 'pieces'. The check reads the string literals of the backend and the docstrings that become API documentation (routes, tools, models); comments, other docstrings, log lines, identifiers and the cron @@ -93,7 +93,7 @@ def test_no_text_of_the_backend_says_piece(): continue for line, text in piece_texts(source): problems.append(f'{path.relative_to(BACKEND).as_posix()}:{line}: {text}') - assert not problems, 'say "element" instead:\n' + '\n'.join(problems) + assert not problems, 'say "component" instead (an item of a batch is an "element"):\n' + '\n'.join(problems) def test_the_check_sees_a_message_a_route_docstring_and_a_description(): diff --git a/tests/api/test_open_flags.py b/tests/api/test_open_flags.py new file mode 100644 index 00000000..9a66dc8a --- /dev/null +++ b/tests/api/test_open_flags.py @@ -0,0 +1,328 @@ +""" +Two booleans tell the web that something is open (decision 8.195, #47): +``has_open_snapshot`` on the identity payload and ``has_open_correction`` on an +evidence record. A draft or pending version is visible only to its author and +the moderators, so a contributor cannot see from the rows that another +person's version is open; the flag gives the fact and nothing else, to the +contributors and moderators of the dataset and admins. Everyone else, a member +who only reviews included, gets a constant False. The +ETag follows the flag, and the exports do not carry either field. +""" + +from __future__ import annotations + +import pytest + +from apps.catalog.migration06.steps import CUTOVER_STEPS, Context, run +from evidence_samples import claim_body +from support import iid, seed_05_catalog, sid + +BEAM = iid('beam') +OPEN_VERSION = sid('beam', 2) + + +@pytest.fixture +def world(api, db, auth_headers, member_headers): + seed_05_catalog(db) + run(Context(db=db, files=False, log=lambda _m: None), CUTOVER_STEPS) + author, author_id = member_headers({'dbu_zirkus': ['contributor']}) + other, _ = member_headers({'dbu_zirkus': ['contributor']}) + reviewer, _ = member_headers({'dbu_zirkus': ['reviewer']}) + moderator, _ = member_headers({'dbu_zirkus': ['moderator']}) + elsewhere, _ = member_headers({'ddu_aggregations': ['moderator']}) + return {'api': api, 'db': db, 'author': author, 'author_id': author_id, + 'other': other, 'reviewer': reviewer, 'moderator': moderator, + 'elsewhere': elsewhere, 'admin': auth_headers('admin'), + 'user': auth_headers('user')} + + +MEMBERS = ('author', 'other', 'moderator', 'admin') # told +NOT_MEMBERS = ('reviewer', 'elsewhere', 'user') # not told + + +def _open_snapshot(w, status='draft'): + snapshot = w['db']['component_snapshots'].find_one({'_id': sid('beam', 1)}) + snapshot.update({'_id': OPEN_VERSION, 'version': 2, 'status': status, + 'superseded_by': None, 'supersedes': None, + 'added_by_user_id': w['author_id']}) + w['db']['component_snapshots'].insert_one(snapshot) + + +def _public(w): + """The element public, so that callers outside the dataset read it too.""" + w['db']['component_identities'].update_one({'_id': BEAM}, {'$set': { + 'is_public': True}}) + + +def _flag(w, who, route='compose'): + headers = {} if who is None else w[who] + url = f'/identities/{BEAM}/compose' if route == 'compose' \ + else f'/identities/{BEAM}' + params = {} if route == 'compose' else {'expand': 'none'} + response = w['api'].get(url, params=params, headers=headers) + assert response.status_code == 200, (who, response.text) + body = response.json() + return (body['identity'] if route == 'compose' else body)[ + 'has_open_snapshot'] + + +# HAS_OPEN_VERSION ------------------------------------------------------------ +@pytest.mark.parametrize('route', ['compose', 'none']) +@pytest.mark.parametrize('status', ['draft', 'pending']) +def test_the_members_and_admins_are_told_of_an_open_snapshot( + world, route, status): + w = world + _public(w) + for who in (*MEMBERS, *NOT_MEMBERS, None): + assert _flag(w, who, route) is False, who + _open_snapshot(w, status) + for who in MEMBERS: + assert _flag(w, who, route) is True, who + # nobody else, an anonymous caller included: a constant False + for who in (*NOT_MEMBERS, None): + assert _flag(w, who, route) is False, who + + +def test_a_closed_version_is_not_open(world): + w = world + for status in ('published', 'rejected', 'withdrawn'): + w['db']['component_snapshots'].delete_many({'_id': OPEN_VERSION}) + _open_snapshot(w, status) + assert _flag(w, 'author') is False, status + + +def test_a_non_member_costs_no_query(): + """The gate answers before it touches the database: a database that + refuses every call is not asked for an anonymous caller, a signed-in + stranger or a moderator of another dataset.""" + import asyncio + from types import SimpleNamespace + + from apps.catalog.api.access import ( + has_open_snapshot, may_know_open) + from apps.catalog.documents import Dataset + from apps.catalog.permissions import ANONYMOUS, Viewer + + dataset = Dataset.model_validate({ + '_id': 'ds', 'name': 'ds', 'visibility': 'members', + 'members': [{'user_id': 'm', 'roles': ['reviewer']}], + 'created': '1970-01-01T00:00:00Z', + 'lastmodified': '1970-01-01T00:00:00Z'}) + + class Refusing: + async def find_one(self, *args, **kwargs): + raise AssertionError('the database was asked') + + request = SimpleNamespace( + state=SimpleNamespace(csc_datasets={'ds': dataset}), + app=SimpleNamespace(mongodb_component_snapshots=Refusing())) + identity = {'_id': 'x', 'dataset': 'ds'} + for viewer in (ANONYMOUS, Viewer('stranger', 'user')): + assert asyncio.run(has_open_snapshot(request, viewer, identity)) is False + assert may_know_open(Viewer('m', 'user'), dataset) is False # a reviewer only + dataset.members[0].roles = ['reviewer', 'contributor'] + assert may_know_open(Viewer('m', 'user'), dataset) is True + dataset.members[0].roles = ['moderator'] + assert may_know_open(Viewer('m', 'user'), dataset) is True + assert may_know_open(Viewer('a', 'admin'), dataset) is True + assert may_know_open(Viewer('stranger', 'user'), dataset) is False + assert may_know_open(ANONYMOUS, dataset) is False + + +def test_the_etag_follows_the_flag(world): + w, api = world, world['api'] + first = api.get(f'/identities/{BEAM}/compose', headers=w['other']) + etag = first.headers['etag'] + assert first.json()['identity']['has_open_snapshot'] is False + same = api.get(f'/identities/{BEAM}/compose', + headers={**w['other'], 'If-None-Match': etag}) + assert same.status_code == 304 + # someone else's draft changes neither the identity nor the versions shown + _open_snapshot(w) + again = api.get(f'/identities/{BEAM}/compose', + headers={**w['other'], 'If-None-Match': etag}) + assert again.status_code == 200 + assert again.json()['identity']['has_open_snapshot'] is True + assert again.headers['etag'] != etag + # and back: the draft leaves, the old validator does not give True + w['db']['component_snapshots'].delete_one({'_id': OPEN_VERSION}) + gone = api.get(f'/identities/{BEAM}/compose', + headers={**w['other'], 'If-None-Match': again.headers['etag']}) + assert gone.status_code == 200 + assert gone.json()['identity']['has_open_snapshot'] is False + + +def test_the_flag_is_not_in_the_exports(world): + w, api = world, world['api'] + _open_snapshot(w) + for params in ({'format': 'jsonld'},): + text = api.get(f'/identities/{BEAM}/compose', params=params, + headers=w['moderator']).text + assert 'has_open_snapshot' not in text + for params in ({}, {'format': 'jsonld'}): + response = api.get(f'/identities/{BEAM}/export/cero', params=params, + headers=w['moderator']) + assert response.status_code == 200, response.text + assert 'has_open_snapshot' not in response.text + # the plain compose body carries it + assert _flag(w, 'moderator') is True + + +# HAS_OPEN_CORRECTION --------------------------------------------------------- +def _published_record(w): + api = w['api'] + created = api.post(f'/identities/{BEAM}/evidence', json=claim_body(), + headers=w['author']) + assert created.status_code == 201, created.text + eid = created.json()['_id'] + assert api.post(f'/evidence/{eid}/submit', + headers=w['author']).status_code == 200 + assert api.post(f'/evidence/{eid}/publish', + headers=w['moderator']).status_code == 200 + return eid + + +def _correct(w, eid, submit=True): + made = w['api'].post(f'/evidence/{eid}/supersede', json=claim_body(), + headers=w['author']) + assert made.status_code == 201, made.text + return made.json()['_id'] + + +def _listed(w, who): + headers = {} if who is None else w[who] + response = w['api'].get(f'/identities/{BEAM}/evidence', + params={'status': 'all'}, headers=headers) + assert response.status_code == 200, (who, response.text) + return {row['_id']: row.get('has_open_correction') + for row in response.json() if 'method' in row} + + +def test_members_are_told_of_an_open_correction_nobody_else(world): + w = world + _public(w) + old = _published_record(w) + for who in (*MEMBERS, *NOT_MEMBERS, None): + assert _listed(w, who).get(old) is False, who + new = _correct(w, old) + for who in MEMBERS: + rows = _listed(w, who) + assert rows[old] is True, who + # a pending correction is seen by its author and the moderators + assert rows.get(new, False) is False, who + assert (new in rows) == (who in ('author', 'moderator', 'admin')), who + # a draft or pending record is not shown to the others at all; the + # published one carries a constant False + for who in (*NOT_MEMBERS, None): + assert _listed(w, who)[old] is False, who + # the single record agrees + for who in MEMBERS: + got = w['api'].get(f'/evidence/{old}', headers=w[who]) + assert got.json()['has_open_correction'] is True, who + for who in NOT_MEMBERS: + got = w['api'].get(f'/evidence/{old}', headers=w[who]) + assert got.json()['has_open_correction'] is False, who + assert w['api'].get(f'/evidence/{old}').json()[ + 'has_open_correction'] is False + + +def test_a_closed_correction_is_not_open(world): + w = world + old = _published_record(w) + new = _correct(w, old) + assert _listed(w, 'other')[old] is True + w['api'].post(f'/evidence/{new}/reject', json={'reason': 'x'}, + headers=w['moderator']) + assert _listed(w, 'other')[old] is False + + +def test_the_list_asks_once(world, monkeypatch): + w = world + old = _published_record(w) + other = _published_record(w) + _correct(w, old) + from apps.catalog.api import evidence as route + calls = [] + original = route.open_corrections + + async def counting(*args, **kwargs): + calls.append(1) + return await original(*args, **kwargs) + monkeypatch.setattr(route, 'open_corrections', counting) + rows = _listed(w, 'other') + assert rows[old] is True and rows[other] is False + assert len(calls) == 1 + + +def test_the_record_etag_follows_the_flag(world): + w, api = world, world['api'] + old = _published_record(w) + first = api.get(f'/evidence/{old}', headers=w['other']) + etag = first.headers['etag'] + assert first.json()['has_open_correction'] is False + assert api.get(f'/evidence/{old}', headers={ + **w['other'], 'If-None-Match': etag}).status_code == 304 + _correct(w, old) + again = api.get(f'/evidence/{old}', headers={ + **w['other'], 'If-None-Match': etag}) + assert again.status_code == 200 + assert again.json()['has_open_correction'] is True + + +def test_the_flag_is_not_in_the_evidence_of_the_passport(world): + w, api = world, world['api'] + old = _published_record(w) + _correct(w, old) + got = api.get(f'/identities/{BEAM}/compose', params={'include': 'evidence'}, + headers=w['moderator']) + assert got.status_code == 200 + assert got.json()['evidence'] + assert 'has_open_correction' not in got.text + jsonld = api.get(f'/identities/{BEAM}/compose', + params={'include': 'evidence', 'format': 'jsonld'}, + headers=w['moderator']) + assert 'has_open_correction' not in jsonld.text + + +def test_a_route_that_did_not_look_it_up_does_not_claim_false(world): + """`identity_body` leaves `has_open_snapshot` out; only compose, `expand=none` + and the passport of an element without a current version compute it.""" + w, api = world, world['api'] + _open_snapshot(w) + patched = api.patch(f'/identities/{BEAM}', json={'trade_name': 'Open flag'}, + headers=w['moderator']) + assert patched.status_code == 200, patched.text + assert 'has_open_snapshot' not in patched.json() + listed = api.get('/identities', params={'expand': 'none', 'circulation': 'all'}, + headers=w['moderator']) + assert listed.status_code == 200, listed.text + rows = [r for r in listed.json() if r.get('_id') == BEAM] + if rows: + assert 'has_open_snapshot' not in rows[0] + # the routes that look it up say so, also while it is open + assert _flag(w, 'moderator') is True + assert _flag(w, 'moderator', 'none') is True + + +def test_a_reviewer_only_member_is_told_of_neither_flag(world): + """8.195 amended: a member who only reviews gets False on both flags, on + the single and on the list routes, with a version and a correction open.""" + w = world + _public(w) + old = _published_record(w) + new = _correct(w, old) + _open_snapshot(w, 'pending') + for route in ('compose', 'none'): + assert _flag(w, 'reviewer', route) is False, route + assert _flag(w, 'moderator', route) is True, route + # the list: the reviewer sees the pending correction and the published + # record, and both say False + rows = _listed(w, 'reviewer') + assert new in rows and rows[old] is False and rows[new] is False + assert _listed(w, 'moderator')[old] is True + for rid in (old, new): + got = w['api'].get(f'/evidence/{rid}', headers=w['reviewer']) + assert got.status_code == 200, got.text + assert got.json()['has_open_correction'] is False, rid + assert w['api'].get(f'/evidence/{old}', headers=w['moderator']).json()[ + 'has_open_correction'] is True diff --git a/tests/api/test_withdrawn_refusals.py b/tests/api/test_withdrawn_refusals.py new file mode 100644 index 00000000..e7f72413 --- /dev/null +++ b/tests/api/test_withdrawn_refusals.py @@ -0,0 +1,390 @@ +""" +A withdrawn element stays out of circulation (decision 8.190, #49): the +backend refuses reserve, re-enter, undo exit, undo deinstall, a new photo on a +withdrawn version or on any version of a withdrawn element, and a new +attachment on a withdrawn record, a correction of a version, and the submit, publish, promote and reinstate of a version, the +reinstate of an evidence record and a withdrawal with a replacement, with a 409 --- for a site admin as well, since it is the state that refuses. +Recall, reject, back to draft and delete stay. Removing a photo or an attachment and +editing a text stay as they are. +""" + +from __future__ import annotations + +import pytest + +from apps.catalog.migration06.steps import CUTOVER_STEPS, Context, run +from evidence_samples import PDF, claim_body, png_bytes +from support import iid, seed_05_catalog, sid + +BEAM = iid('beam') +V1 = sid('beam', 1) +WITHDRAWN = 'The component is withdrawn.' + + +@pytest.fixture +def world(api, db, auth_headers, member_headers): + seed_05_catalog(db) + run(Context(db=db, files=False, log=lambda _m: None), CUTOVER_STEPS) + contributor, contributor_id = member_headers( + {'dbu_zirkus': ['contributor']}) + moderator, _ = member_headers({'dbu_zirkus': ['moderator']}) + return {'api': api, 'db': db, 'c': contributor, 'cid': contributor_id, + 'm': moderator, 'admin': auth_headers('admin'), + 'user': auth_headers('user')} + + +def _withdraw(w): + done = w['api'].post(f'/identities/{BEAM}/withdraw', + json={'reason': 'test'}, headers=w['m']) + assert done.status_code == 200, done.text + + +def _reinstate(w): + done = w['api'].post(f'/identities/{BEAM}/reinstate', headers=w['m']) + assert done.status_code == 200, done.text + + +def _photo(w, headers, snapshot=V1): + return w['api'].put(f'/snapshots/{snapshot}/photos/0', + files={'photo': ('p.png', png_bytes(), 'image/png')}, + headers=headers) + + +def _refused(response): + assert response.status_code == 409, response.text + assert response.json()['detail'] == WITHDRAWN + + +# CIRCULATION ----------------------------------------------------------------- +def test_reserve_answers_409_on_a_withdrawn_element(world): + w, api = world, world['api'] + _withdraw(w) + for who in ('c', 'm', 'admin'): + _refused(api.post(f'/identities/{BEAM}/reserve', headers=w[who])) + assert w['db']['component_identities'].find_one( + {'_id': BEAM})['reserved'] == '' + # a caller who cannot read the element learns nothing of its state + assert api.post(f'/identities/{BEAM}/reserve', + headers=w['user']).status_code == 403 + _reinstate(w) + assert api.post(f'/identities/{BEAM}/reserve', + headers=w['c']).status_code == 200 + + +def test_undo_exit_and_re_enter_answer_409_on_a_withdrawn_element(world): + w, api = world, world['api'] + assert api.post(f'/identities/{BEAM}/exit', json={ + 'kind': 'installed', 'at': '2026-08-01T00:00:00Z'}, + headers=w['m']).status_code == 200 + _withdraw(w) + again = {'origin': {'kind': 'deinstallation', + 'at': '2026-10-01T00:00:00Z', 'at_precision': 'day'}} + for who in ('m', 'admin'): + _refused(api.delete(f'/identities/{BEAM}/exit', headers=w[who])) + _refused(api.post(f'/identities/{BEAM}/reenter', json=again, + headers=w[who])) + # the permission comes first: a contributor is refused, not told the state + assert api.delete(f'/identities/{BEAM}/exit', + headers=w['c']).status_code == 403 + assert w['db']['component_identities'].find_one( + {'_id': BEAM})['exit']['kind'] == 'installed' + _reinstate(w) + assert api.post(f'/identities/{BEAM}/reenter', json=again, + headers=w['m']).status_code == 200 + + +def test_undo_deinstall_answers_409_on_a_withdrawn_element(world): + w, api = world, world['api'] + # an in-place element that was deinstalled, then withdrawn + w['db']['component_identities'].update_one({'_id': BEAM}, {'$set': { + 'origin': {'kind': 'deinstallation', 'planned': True, + 'at': '2026-01-01T00:00:00Z', 'at_precision': 'day'}}}) + deinstall = {'at': '2026-09-01T00:00:00Z'} + assert api.post(f'/identities/{BEAM}/deinstall', json=deinstall, + headers=w['m']).status_code == 200 + _withdraw(w) + for who in ('m', 'admin'): + _refused(api.post(f'/identities/{BEAM}/undo-deinstall', + headers=w[who])) + assert w['db']['component_identities'].find_one( + {'_id': BEAM})['origin']['planned'] is False + # the passport does not offer the undo of a withdrawn element + _reinstate(w) + passport = api.get(f'/identities/{BEAM}/compose', headers=w['m']).json() + assert passport['identity']['can_undo_deinstall'] is True + _withdraw(w) + passport = api.get(f'/identities/{BEAM}/compose', headers=w['m']).json() + assert not passport['identity'].get('can_undo_deinstall') + + +# PHOTOS AND ATTACHMENTS ------------------------------------------------------ +def test_a_photo_is_refused_on_any_version_of_a_withdrawn_element(world): + w = world + assert _photo(w, w['c']).status_code == 200 # baseline: published + _withdraw(w) + for who in ('c', 'm', 'admin'): + _refused(_photo(w, w[who])) + # nobody who may not add one learns the state + assert _photo(w, w['user']).status_code == 403 + # removing stays as it is: a moderator removes + assert w['api'].delete(f'/snapshots/{V1}/photos/0', + headers=w['m']).status_code in (200, 204) + _reinstate(w) + assert _photo(w, w['c']).status_code == 200 + + +def test_a_photo_is_refused_on_a_withdrawn_version(world): + w, api = world, world['api'] + # v0 of the beam is published and no longer current: withdraw it alone + v0 = sid('beam', 0) + done = api.post(f'/snapshots/{v0}/withdraw', json={'reason': 'wrong scan'}, + headers=w['m']) + assert done.status_code == 200, done.text + for who in ('c', 'm', 'admin'): + refused = _photo(w, w[who], snapshot=v0) + assert refused.status_code == 409, refused.text + assert refused.json()['detail'] == 'This snapshot is withdrawn.' + # the other version of the same, not withdrawn element still takes one + assert _photo(w, w['c']).status_code == 200 + + +def test_an_attachment_is_refused_on_a_withdrawn_record(world): + w, api = world, world['api'] + created = api.post(f'/identities/{BEAM}/evidence', json=claim_body(), + headers=w['c']) + assert created.status_code == 201, created.text + eid = created.json()['_id'] + assert api.post(f'/evidence/{eid}/submit', headers=w['c']).status_code == 200 + assert api.post(f'/evidence/{eid}/publish', + headers=w['m']).status_code == 200 + + def attach(headers, data=PDF): + return api.post('/evidence/attachments', data={'record_ids': [eid]}, + files={'file': ('a.pdf', data, 'application/pdf')}, + headers=headers) + assert attach(w['c']).status_code == 201 + assert api.post(f'/evidence/{eid}/withdraw', json={'reason': 'x'}, + headers=w['m']).status_code == 200 + for who, data in (('c', PDF + b'1'), ('m', PDF + b'2'), + ('admin', PDF + b'3')): + refused = attach(w[who], data) + assert refused.status_code == 409, (who, refused.text) + assert 'withdrawn' in refused.json()['detail'] + # removing stays: a moderator takes the file out, with a reason + removed = api.delete(f'/evidence/{eid}/attachments/0', + params={'reason': 'wrong file'}, headers=w['m']) + assert removed.status_code == 200, removed.text + + +def test_a_text_edit_of_a_withdrawn_version_stays_allowed(world): + w, api = world, world['api'] + _withdraw(w) + edit = api.patch(f'/snapshots/{V1}', json={'name': 'Typo fixed'}, + headers=w['m']) + assert edit.status_code == 200, edit.text + + +def test_an_attachment_is_refused_on_any_record_of_a_withdrawn_element(world): + w, api = world, world['api'] + published = api.post(f'/identities/{BEAM}/evidence', json=claim_body(), + headers=w['c']).json()['_id'] + assert api.post(f'/evidence/{published}/submit', + headers=w['c']).status_code == 200 + assert api.post(f'/evidence/{published}/publish', + headers=w['m']).status_code == 200 + draft = api.post(f'/identities/{BEAM}/evidence', json=claim_body(), + headers=w['c']).json()['_id'] + + def attach(eid, headers, data): + return api.post('/evidence/attachments', data={'record_ids': [eid]}, + files={'file': ('a.pdf', data, 'application/pdf')}, + headers=headers) + assert attach(published, w['c'], PDF).status_code == 201 + _withdraw(w) + for eid in (published, draft): + for who, data in (('c', PDF + b'1'), ('m', PDF + b'2'), + ('admin', PDF + b'3')): + refused = attach(eid, w[who], data) + assert refused.status_code == 409, (eid, who, refused.text) + assert refused.json()['detail'] == WITHDRAWN + # removing stays as it is + removed = api.delete(f'/evidence/{published}/attachments/0', + params={'reason': 'wrong file'}, headers=w['m']) + assert removed.status_code == 200, removed.text + _reinstate(w) + assert attach(published, w['c'], PDF + b'4').status_code == 201 + + +def _correction_body(): + import trimesh + mesh = trimesh.creation.box(extents=(310, 200, 150)) + return {'geometry': {'meshes': [{'vertices': mesh.vertices.tolist(), + 'faces': mesh.faces.tolist()}], + 'point_clouds': [], 'proxies': []}} + + +def test_a_correction_answers_409_on_a_withdrawn_element(world): + """8.190 amended: a correction would publish a new state of an element out + of circulation; the check comes before any other 409 on the route.""" + w, api = world, world['api'] + _withdraw(w) + for who in ('c', 'admin'): # a correction is a contributor's step + _refused(api.post(f'/snapshots/{V1}/supersede', + json=_correction_body(), headers=w[who])) + assert w['db']['component_snapshots'].count_documents( + {'identity_id': BEAM, 'status': {'$in': ['draft', 'pending']}}) == 0 + # reinstate, then the correction works + _reinstate(w) + made = api.post(f'/snapshots/{V1}/supersede', json=_correction_body(), + headers=w['c']) + assert made.status_code == 201, made.text + + +def _draft(w): + made = w['api'].post(f'/identities/{BEAM}/snapshots', + json=_correction_body(), headers=w['c']) + assert made.status_code == 201, made.text + return made.json()['_id'] + + +def _step(w, who, path, **kw): + return w['api'].post(path, headers=w[who], **kw) + + +def test_submit_answers_409_on_a_withdrawn_element(world): + """8.190 amended: a version opened before the withdrawal is not submitted + after it; deleting it stays allowed; reinstate, then it submits.""" + w = world + sid_ = _draft(w) + _withdraw(w) + for who in ('c', 'admin'): + _refused(_step(w, who, f'/snapshots/{sid_}/submit')) + assert w['db']['component_snapshots'].find_one( + {'_id': sid_})['status'] == 'draft' + # a caller without the right still gets 403, not a word of the state + assert _step(w, 'user', f'/snapshots/{sid_}/submit').status_code == 403 + _reinstate(w) + assert _step(w, 'c', f'/snapshots/{sid_}/submit').status_code == 200 + # and delete stays allowed on a withdrawn element + _withdraw(w) + recalled = _step(w, 'c', f'/snapshots/{sid_}/recall') + assert recalled.status_code == 200, recalled.text + gone = w['api'].delete(f'/snapshots/{sid_}', headers=w['m']) + assert gone.status_code == 200, gone.text + + +def test_publish_and_promote_answer_409_on_a_withdrawn_element(world): + w = world + sid_ = _draft(w) + assert _step(w, 'c', f'/snapshots/{sid_}/submit').status_code == 200 + _withdraw(w) + for who in ('m', 'admin'): + _refused(_step(w, who, f'/snapshots/{sid_}/publish')) + _refused(_step(w, who, f'/snapshots/{sid_}/publish', + params={'promote': 1})) + # promote: the check comes before any other 409 on the route + _refused(_step(w, who, f'/snapshots/{V1}/promote')) + assert w['db']['component_snapshots'].find_one( + {'_id': sid_})['status'] == 'pending' + assert _step(w, 'user', f'/snapshots/{sid_}/publish').status_code == 403 + # the allowed steps stay: recall, submit again is refused, reject, resubmit + assert _step(w, 'c', f'/snapshots/{sid_}/recall').status_code == 200 + _refused(_step(w, 'c', f'/snapshots/{sid_}/submit')) + _reinstate(w) + assert _step(w, 'c', f'/snapshots/{sid_}/submit').status_code == 200 + _withdraw(w) + rejected = _step(w, 'm', f'/snapshots/{sid_}/reject', + json={'reason': 'not now'}) + assert rejected.status_code == 200, rejected.text + again = _step(w, 'c', f'/snapshots/{sid_}/resubmit') + assert again.status_code == 200, again.text + # reinstate, then submit, publish and promote work + _reinstate(w) + assert _step(w, 'c', f'/snapshots/{sid_}/submit').status_code == 200 + done = _step(w, 'm', f'/snapshots/{sid_}/publish', + params={'promote': 1}) + assert done.status_code == 200, done.text + assert _step(w, 'm', f'/snapshots/{V1}/promote').status_code == 200 + + +def test_withdrawing_stays_allowed_while_a_version_is_open(world): + w = world + sid_ = _draft(w) + _withdraw(w) # asserts 200 + assert w['db']['component_snapshots'].find_one( + {'_id': sid_})['status'] == 'draft' + + +def test_a_version_is_reinstated_after_the_element_not_before(world): + """8.190 amended: ``reinstate_snapshot`` answers 409 on a withdrawn + element, admin included; the element's own reinstate comes first.""" + w, api = world, world['api'] + # every version withdrawn, then the element + for row in list(w['db']['component_snapshots'].find( + {'identity_id': BEAM, 'status': 'published'})): + gone = api.post(f'/snapshots/{row["_id"]}/withdraw', + json={'reason': 'x'}, headers=w['m']) + assert gone.status_code == 200, gone.text + assert w['db']['component_identities'].find_one( + {'_id': BEAM}).get('current_snapshot_id') in (None, '') + _withdraw(w) + for who in ('m', 'admin'): + _refused(_step(w, who, f'/snapshots/{V1}/reinstate')) + assert w['db']['component_snapshots'].find_one( + {'_id': V1})['status'] == 'withdrawn' + assert _step(w, 'user', f'/snapshots/{V1}/reinstate').status_code == 403 + # the element comes back without a current version, and a moderator + # reinstates a version afterwards: it becomes the current one + _reinstate(w) + assert w['db']['component_identities'].find_one( + {'_id': BEAM}).get('current_snapshot_id') in (None, '') + assert w['db']['component_identities'].find_one( + {'_id': BEAM}).get('withdrawn') is None + back = _step(w, 'm', f'/snapshots/{V1}/reinstate') + assert back.status_code == 200, back.text + assert w['db']['component_identities'].find_one( + {'_id': BEAM})['current_snapshot_id'] == V1 + + +def test_an_evidence_record_is_reinstated_after_the_element_not_before(world): + w, api = world, world['api'] + created = api.post(f'/identities/{BEAM}/evidence', json=claim_body(), + headers=w['c']) + assert created.status_code == 201, created.text + eid = created.json()['_id'] + assert api.post(f'/evidence/{eid}/submit', headers=w['c']).status_code == 200 + assert api.post(f'/evidence/{eid}/publish', headers=w['m']).status_code == 200 + assert api.post(f'/evidence/{eid}/withdraw', json={'reason': 'x'}, + headers=w['m']).status_code == 200 + _withdraw(w) + for who in ('m', 'admin'): + refused = api.post(f'/evidence/{eid}/reinstate', headers=w[who]) + assert refused.status_code == 409, (who, refused.text) + assert 'withdrawn' in str(refused.json()['detail']) + assert w['db']['component_evidence'].find_one( + {'_id': eid})['status'] == 'withdrawn' + _reinstate(w) + back = api.post(f'/evidence/{eid}/reinstate', headers=w['m']) + assert back.status_code == 200, back.text + + +def test_a_withdrawal_with_a_replacement_is_refused_a_plain_one_is_not(world): + w, api = world, world['api'] + second = _draft(w) + assert _step(w, 'c', f'/snapshots/{second}/submit').status_code == 200 + assert _step(w, 'm', f'/snapshots/{second}/publish').status_code == 200 + _withdraw(w) + for who in ('m', 'admin'): + _refused(_step(w, who, f'/snapshots/{second}/withdraw', json={ + 'reason': 'x', 'replacement_id': V1})) + assert w['db']['component_snapshots'].find_one( + {'_id': second})['status'] == 'published' + plain = _step(w, 'm', f'/snapshots/{second}/withdraw', + json={'reason': 'x'}) + assert plain.status_code == 200, plain.text + # reinstate the element, then the version, and a replacement works again + _reinstate(w) + assert _step(w, 'm', f'/snapshots/{second}/reinstate').status_code == 200 + again = _step(w, 'm', f'/snapshots/{second}/withdraw', json={ + 'reason': 'y', 'replacement_id': V1}) + assert again.status_code == 200, again.text diff --git a/tests/catalog/test_evidence_registry.py b/tests/catalog/test_evidence_registry.py index 63a51cb5..6a1bdbe6 100644 --- a/tests/catalog/test_evidence_registry.py +++ b/tests/catalog/test_evidence_registry.py @@ -630,6 +630,29 @@ def test_quantity_must_fit_method_and_tier(): assert 'payload.manufacturer' in paths(sheet) +def test_a_claim_needs_its_kind_in_the_summary_the_web_sends(): + """8.189 amended: the web sends ``kind: claimed`` with the result of a + claim; without it the server answers ``summary.kind``. A document without + a result needs no summary.""" + era = {'method': 'era_heuristic', 'observed_at': T, + 'payload': {'basis': 'construction_year', 'year': 1968}, + 'summary': {'quantity': 'compressive_strength', 'value': 25, + 'unit': 'MPa'}} + sheet = {'method': 'manufacturer_datasheet', 'observed_at': T, + 'payload': {'manufacturer': 'Rosskopf', 'product': 'Corian'}, + 'summary': {'quantity': 'density', 'value': 1.7, + 'unit': 'g/cm3'}} + document = archival(summary={'quantity': 'concrete_class', + 'range': ['B225']}) + for data in (era, sheet, document): + assert 'summary.kind' in paths(data), data['method'] + data['summary'] = {**data['summary'], 'kind': 'claimed'} + assert prepare_record(data), data['method'] + bare = archival(summary=None, payload={ + 'document': {'title': 'Plan', 'date': '1968-03', 'kind': 'drawing'}}) + assert prepare_record(bare) + + def visual(observations, **over): data = {'method': 'visual_inspection', 'observed_at': T, 'payload': {'observations': observations}} diff --git a/tests/catalog/test_exports.py b/tests/catalog/test_exports.py index 50cef82b..46d4ace1 100644 --- a/tests/catalog/test_exports.py +++ b/tests/catalog/test_exports.py @@ -297,7 +297,7 @@ def test_the_pdf_holds_the_spec_7_8_contents(): children=[{'id': EID, 'catalog_number': 9}], member=True, change_info={'count': 4, 'last_at': '2026-10-01T09:00:00Z'})) for needle in ('Component passport', '#7 beam', 'Dataset: ZirKuS', - 'state v1', 'Beam (IfcBeam)', 'Concrete', '17 01 01', + 'snapshot v1', 'Beam (IfcBeam)', 'Concrete', '17 01 01', 'Deinstalled', '2022-05', 'Werdh\u00f6lzli', 'Hall 7', 'built 1969', 'Welded', '6000 x 300 x 200 mm', 'Linear', 'Mass', diff --git a/tests/catalog/test_permissions.py b/tests/catalog/test_permissions.py index 741fbf36..85263039 100644 --- a/tests/catalog/test_permissions.py +++ b/tests/catalog/test_permissions.py @@ -148,8 +148,9 @@ def test_unknown_action_is_an_error(): ('delete_dataset', Target(D, kind='dataset'), {'mod', 'admin'}), # 8.139 f ('set_dataset_public', Target(D, kind='dataset'), {'mod', 'admin'}), # 8.131 c ('invite', Target(D, kind='dataset'), {'mod', 'admin'}), + # the creator loses the right with the role (8.193 c) ('revoke_invitation', Target(D, kind='invitation', author_id='contrib'), - {'contrib', 'mod', 'admin'}), + {'mod', 'admin'}), # admin only ('create_dataset', Target(D), {'stranger', 'author', 'contrib', 'review', 'mod', 'admin'}), # 8.139 diff --git a/tests/fixtures/data_model_examples.json b/tests/fixtures/data_model_examples.json index 43010492..01df8682 100644 --- a/tests/fixtures/data_model_examples.json +++ b/tests/fixtures/data_model_examples.json @@ -647,7 +647,7 @@ "position": { "kind": "none", "snapshot_id": "example-snapshot-v0", - "description": "Whole element; bars in the stored coordinates of this version" + "description": "Whole component; bars in the stored coordinates of this snapshot" }, "summary": { "quantity": "rebar_diameter", diff --git a/tests/grasshopper/test_signin.py b/tests/grasshopper/test_signin.py index a54dbcf6..c8f2eb9d 100644 --- a/tests/grasshopper/test_signin.py +++ b/tests/grasshopper/test_signin.py @@ -429,5 +429,8 @@ def test_the_module_is_python_3_9_and_standard_library_only(): elif isinstance(node, ast.ImportFrom): imported.add((node.module or '').split('.')[0]) import sys - assert imported <= set(sys.stdlib_module_names), imported - set(sys.stdlib_module_names) + # sys.stdlib_module_names exists from Python 3.10; the 3.9 of the headless Rhino + # environment skips the import check and keeps the rest (8.194) + if sys.version_info >= (3, 10): + assert imported <= set(sys.stdlib_module_names), imported - set(sys.stdlib_module_names) assert all(ord(c) < 128 for c in source) From 5067d30830c56f8de29a28e7d4f5dab95e89eb11 Mon Sep 17 00:00:00 2001 From: fstwn Date: Sun, 8 Nov 2026 19:44:44 +0100 Subject: [PATCH 7/9] fix(web): controls follow the permission rules, move and delete a component, claims save (#46, #47, #48, #49, #50) User text says component, snapshot and component id, as the data model does. New page description. --- .../app/admin/datasets/[did]/page.tsx | 48 +++-- src/frontend/app/admin/validation/page.tsx | 2 +- src/frontend/app/analytics/page.tsx | 4 +- .../app/components/[component_id]/page.tsx | 87 ++++---- src/frontend/app/components/page.tsx | 4 +- .../gh-interface/GHInterfacePageClient.tsx | 2 +- src/frontend/app/layout.tsx | 2 +- src/frontend/app/my-work/page.tsx | 4 + src/frontend/app/page.tsx | 4 +- src/frontend/app/reference/page.tsx | 2 +- .../components/admin/RoleCheckboxes.tsx | 8 +- .../components/ComponentAccessNotice.tsx | 4 +- .../ComponentDetailSnapshotBanner.tsx | 22 +- .../components/ComponentLocateById.tsx | 6 +- .../components/ComponentProvenanceCard.tsx | 9 +- .../ComponentSnapshotVersionList.tsx | 17 +- .../components/components/ComponentViewer.tsx | 6 +- .../components/detail/AddEvidenceButton.tsx | 5 +- .../detail/ComponentActionsMenu.tsx | 113 +++++++--- .../detail/ComponentDescriptorsCard.tsx | 4 +- .../components/detail/ComponentFactsCard.tsx | 2 +- .../detail/ComponentHeaderStrip.tsx | 8 +- .../detail/ComponentHistoryCard.tsx | 14 +- .../components/detail/ComponentPageView.tsx | 14 +- .../detail/ComponentPhotosLocationCard.tsx | 3 +- .../detail/ComponentPropertiesCard.tsx | 12 +- .../detail/ComponentRecordsCard.tsx | 11 +- .../detail/ComponentSimilarCard.tsx | 12 +- .../components/detail/HistoryList.tsx | 10 +- .../components/history/SwimlaneGraph.tsx | 10 +- .../components/history/SwimlaneSvg.tsx | 10 +- .../components/map/LocationMapPageClient.tsx | 6 +- .../overview/ComponentOverviewColumns.tsx | 4 +- .../components/datasets/YourDatasets.tsx | 2 +- .../evidence/EvidenceAttachments.tsx | 29 ++- .../components/evidence/EvidenceCard.tsx | 16 +- .../components/evidence/LayoutDetails.tsx | 3 +- .../evidence/PositionPickerDialog.tsx | 8 +- .../components/evidence/PropertiesCard.tsx | 6 +- .../components/evidence/form/ClaimEditor.tsx | 14 +- .../components/evidence/form/EvidenceForm.tsx | 35 ++- .../evidence/form/PositionField.tsx | 2 +- .../evidence/form/RecordsEditor.tsx | 2 +- .../components/evidence/form/state.ts | 16 +- .../idtransmission/ComponentIdTransmitter.tsx | 12 +- .../components/lineage/CirculationActions.tsx | 4 +- .../components/lineage/DeinstallActions.tsx | 6 +- .../lineage/ProvenanceEditDialog.tsx | 4 +- .../moderation/EvidenceLifecycleActions.tsx | 44 ++-- .../components/moderation/EvidenceQueue.tsx | 2 +- .../moderation/IdentityModerationActions.tsx | 138 +++++++++++- .../moderation/SnapshotLifecycleActions.tsx | 56 +++-- .../components/moderation/SnapshotQueue.tsx | 32 ++- .../photos/SnapshotPhotoCapture.tsx | 6 +- .../components/reference/ModelDiagram.tsx | 4 +- .../components/scan/ScanPageClient.tsx | 4 +- .../components/snapshot/AddComponentEntry.tsx | 6 +- .../components/snapshot/DetailsStep.tsx | 14 +- .../components/snapshot/EditSnapshotForm.tsx | 83 +++++--- .../components/snapshot/ParentTags.tsx | 4 +- .../snapshot/PositionedEvidence.tsx | 6 +- src/frontend/components/snapshot/SizeStep.tsx | 6 +- .../components/snapshot/SnapshotForm.tsx | 45 ++-- .../components/snapshot/UnknownTag.tsx | 8 +- .../components/viewer/OpacitySlider.tsx | 10 +- src/frontend/generated/AccessModels.ts | 6 +- src/frontend/generated/CatalogModels.ts | 23 +- src/frontend/generated/CatalogSharedTypes.ts | 4 +- .../generated/EvidenceCreateModels.ts | 12 +- src/frontend/generated/EvidenceModels.ts | 5 +- src/frontend/generated/LineageModels.ts | 4 +- src/frontend/generated/SnapshotModels.ts | 8 +- src/frontend/generated/Vocab.ts | 34 +-- src/frontend/lib/analytics.ts | 2 +- src/frontend/lib/browse.ts | 8 +- src/frontend/lib/componentDetail.test.ts | 125 ++++++++++- src/frontend/lib/componentDetail.ts | 108 +++++++--- src/frontend/lib/dataModelExamples.ts | 106 +++++----- src/frontend/lib/dataModelTabs.test.ts | 2 +- src/frontend/lib/dataModelTabs.ts | 2 +- src/frontend/lib/dataModelText.ts | 170 +++++++-------- src/frontend/lib/datasets.ts | 2 +- src/frontend/lib/everPublished.test.ts | 43 ++++ src/frontend/lib/everPublished.ts | 27 +++ src/frontend/lib/evidence/claimBody.test.ts | 37 ++++ src/frontend/lib/evidence/edit.test.ts | 12 ++ src/frontend/lib/evidence/issues.test.ts | 2 +- src/frontend/lib/evidence/issues.ts | 4 +- src/frontend/lib/evidence/methodGroups.ts | 6 +- src/frontend/lib/evidence/paired.ts | 2 +- src/frontend/lib/fit.ts | 8 +- src/frontend/lib/history/swimlane.test.ts | 2 +- src/frontend/lib/history/swimlane.ts | 2 +- src/frontend/lib/ids.ts | 2 +- src/frontend/lib/lifecycleRights.test.ts | 199 ++++++++++++++++++ src/frontend/lib/lifecycleRights.ts | 157 ++++++++++++++ src/frontend/lib/locationMap.test.ts | 16 +- src/frontend/lib/locationMap.ts | 10 +- src/frontend/lib/members.test.ts | 24 ++- src/frontend/lib/members.ts | 29 +++ src/frontend/lib/moderationCard.test.ts | 4 +- src/frontend/lib/moderationCard.ts | 4 +- src/frontend/lib/moveTargets.test.ts | 54 +++++ src/frontend/lib/moveTargets.ts | 38 ++++ src/frontend/lib/myWork.test.ts | 25 ++- src/frontend/lib/myWork.ts | 17 +- src/frontend/lib/near.ts | 6 +- src/frontend/lib/newestVersion.test.ts | 34 +++ src/frontend/lib/newestVersion.ts | 48 +++++ src/frontend/lib/photoRights.test.ts | 28 ++- src/frontend/lib/photoRights.ts | 22 +- src/frontend/lib/privacyText.ts | 2 +- src/frontend/lib/publicSwitch.test.ts | 16 +- src/frontend/lib/publicSwitch.ts | 10 +- src/frontend/lib/publishCheck.ts | 70 ++++++ src/frontend/lib/publishRights.test.ts | 62 ++++++ src/frontend/lib/publishRights.ts | 56 +++++ src/frontend/lib/snapshotEdit.test.ts | 42 ++++ src/frontend/lib/snapshotEdit.ts | 37 ++++ src/frontend/lib/snapshotForm.ts | 6 +- src/frontend/lib/userText.test.ts | 134 +++++++++++- 121 files changed, 2352 insertions(+), 662 deletions(-) create mode 100644 src/frontend/lib/everPublished.test.ts create mode 100644 src/frontend/lib/everPublished.ts create mode 100644 src/frontend/lib/evidence/claimBody.test.ts create mode 100644 src/frontend/lib/lifecycleRights.test.ts create mode 100644 src/frontend/lib/lifecycleRights.ts create mode 100644 src/frontend/lib/moveTargets.test.ts create mode 100644 src/frontend/lib/moveTargets.ts create mode 100644 src/frontend/lib/newestVersion.test.ts create mode 100644 src/frontend/lib/newestVersion.ts create mode 100644 src/frontend/lib/publishCheck.ts create mode 100644 src/frontend/lib/publishRights.test.ts create mode 100644 src/frontend/lib/publishRights.ts diff --git a/src/frontend/app/admin/datasets/[did]/page.tsx b/src/frontend/app/admin/datasets/[did]/page.tsx index 46c98a49..2ee05318 100644 --- a/src/frontend/app/admin/datasets/[did]/page.tsx +++ b/src/frontend/app/admin/datasets/[did]/page.tsx @@ -37,7 +37,7 @@ import { } from '@/components/ui/table' import { Textarea } from '@/components/ui/textarea' import InviteDialog from '@/components/admin/InviteDialog' -import { addMemberHint, memberLabel, memberLine } from '@/lib/members' +import { addMemberHint, deleteDatasetReason, lastModeratorReason, memberLabel, memberLine } from '@/lib/members' import InvitationsTable from '@/components/admin/InvitationsTable' import RoleCheckboxes, { type DatasetRole } from '@/components/admin/RoleCheckboxes' import type { @@ -202,7 +202,7 @@ function DatasetSettings({ dataset, isAdmin, onSaved }: {

{waiting ? REVIEW_EXPLANATION - : 'An administrator has looked at this dataset: it may be visible to all signed-in users and its elements may be made public.'} + : 'An administrator has looked at this dataset: it may be visible to all signed-in users and its components may be made public.'}

setVisibility(v as DatasetView['visibility'])}> - Members only (and elements marked public) + Members only (and components marked public) All signed-in users @@ -270,7 +270,7 @@ function PublicPiecesCard({ dataset }: { dataset: DatasetView }) { const result = await backendJson<{ changed: number; skipped?: number }>(path, { method: 'POST', body: { is_public: isPublic }, }) - toast.success(`${result.changed} element${result.changed === 1 ? '' : 's'} now ${isPublic ? 'public' : 'private'}` + toast.success(`${result.changed} component${result.changed === 1 ? '' : 's'} now ${isPublic ? 'public' : 'private'}` + (result.skipped ? `; ${result.skipped} changed meanwhile and were left as they were` : '')) await count() } catch (err) { @@ -284,10 +284,10 @@ function PublicPiecesCard({ dataset }: { dataset: DatasetView }) { return ( - Public elements + Public components - Sets the public flag of every published element of this dataset at once. Unpublished and withdrawn - elements, and other datasets, stay as they are. Every element keeps its own flag: children do not follow + Sets the public flag of every published component of this dataset at once. Unpublished and withdrawn + components, and other datasets, stay as they are. Every component keeps its own flag: children do not follow their parents. @@ -312,8 +312,8 @@ function PublicPiecesCard({ dataset }: { dataset: DatasetView }) { { if (!busy) setConfirm(open) }} - title={`Make ${counts.toPublic ?? 'all'} published elements public?`} - subject={`${counts.toPublic ?? 'All'} published element${counts.toPublic === 1 ? '' : 's'} of ${dataset.name} become public.`} + title={`Make ${counts.toPublic ?? 'all'} published components public?`} + subject={`${counts.toPublic ?? 'All'} published component${counts.toPublic === 1 ? '' : 's'} of ${dataset.name} become public.`} confirmLabel="Make public" onConfirm={() => void apply(true)} /> @@ -332,11 +332,22 @@ function DeleteDatasetCard({ dataset }: { dataset: DatasetView }) { const { refresh } = useMe() const { confirm, dialog } = useConfirm() const [busy, setBusy] = useState(false) + // the list counts the published elements the caller sees (the dataset itself carries no count) + const [count, setCount] = useState(null) + useEffect(() => { + let cancelled = false + backendJson('/datasets') + .then((rows) => { if (!cancelled) setCount(rows.find((row) => row._id === dataset._id)?.component_count ?? null) }) + .catch(() => { if (!cancelled) setCount(null) }) + return () => { cancelled = true } + }, [dataset._id]) + const blocked = deleteDatasetReason(count) const remove = async () => { const ok = await confirm({ title: `Delete ${dataset.name}?`, - description: 'The dataset and its open invitations are deleted. Its members keep their accounts. This cannot be undone.', + description: 'The dataset and its open invitations are deleted. Its members keep their accounts. It must hold no component at all: ' + + 'a draft, a withdrawn or a private one counts too, and the server refuses the delete then. This cannot be undone.', confirmLabel: 'Delete the dataset', destructive: true, }) @@ -360,14 +371,16 @@ function DeleteDatasetCard({ dataset }: { dataset: DatasetView }) { Delete this dataset - Only possible while the dataset holds no element: move its elements to another dataset first. Open + Only possible while the dataset holds no component: move its components to another dataset first. Open invitations are revoked with it. - - void remove()}> + + void remove()}> Delete the dataset + {blocked &&

{blocked}

}
) @@ -383,6 +396,8 @@ function MembersCard({ onChanged: () => void }) { const members = dataset.members ?? [] + // the reason a locked box or button carries only as a tooltip, in text as well (8.139 g) + const lockNote = members.map((member) => lastModeratorReason(members, member, isAdmin)).find(Boolean) const { confirm, dialog } = useConfirm() const setRoles = async (member: DatasetMemberView, roles: DatasetRole[]) => { if (roles.length === 0 && !(await confirm({ @@ -441,11 +456,17 @@ function MembersCard({ idPrefix={`m-${member.user_id}`} compact value={member.roles as DatasetRole[]} + locked={(() => { + const reason = lastModeratorReason(members, member, isAdmin) + return reason ? { moderator: reason } : undefined + })()} onChange={(roles) => void setRoles(member, roles)} /> void setRoles(member, [])}> @@ -455,6 +476,7 @@ function MembersCard({ )} + {lockNote &&

{lockNote}

} ) diff --git a/src/frontend/app/admin/validation/page.tsx b/src/frontend/app/admin/validation/page.tsx index 116d41eb..1492f599 100644 --- a/src/frontend/app/admin/validation/page.tsx +++ b/src/frontend/app/admin/validation/page.tsx @@ -15,7 +15,7 @@ type Tab = 'snapshots' | 'evidence' | 'verification' const TAB_HELP: Record = { snapshots: - 'Versions of components waiting in the datasets you moderate, oldest first. Publishing makes a version the current state of its component; a rejection goes back to its author with your reason.', + 'Snapshots of components waiting in the datasets you moderate, oldest first. Publishing makes a snapshot the current snapshot of its component; a rejection goes back to its author with your reason.', evidence: 'Records waiting in the datasets you moderate, oldest first. Publishing freezes a record and updates the properties of its component; a rejection goes back to its author with your reason.', verification: diff --git a/src/frontend/app/analytics/page.tsx b/src/frontend/app/analytics/page.tsx index 1b09865b..8d345a0f 100644 --- a/src/frontend/app/analytics/page.tsx +++ b/src/frontend/app/analytics/page.tsx @@ -215,7 +215,7 @@ function Analytics() { - + ({ ...d, label: String(d.label) }))} @@ -227,7 +227,7 @@ function Analytics() { {data && activeTab === 'types' && ( - + )} diff --git a/src/frontend/app/components/[component_id]/page.tsx b/src/frontend/app/components/[component_id]/page.tsx index 5e344f70..02d7ee17 100644 --- a/src/frontend/app/components/[component_id]/page.tsx +++ b/src/frontend/app/components/[component_id]/page.tsx @@ -4,10 +4,10 @@ import type { CatalogComponent } from '@/generated/CatalogModels' import { primarySnapshot, type CatalogShallowRow } from '@/generated/catalogExtras' import type { SnapshotSummaryItem } from '@/generated/SnapshotModels' import { isPublished } from '@/components/components/componentDetailShared' -import Link from 'next/link' import ComponentAccessNotice from '@/components/components/ComponentAccessNotice' import ComponentSnapshotVersionList from '@/components/components/ComponentSnapshotVersionList' import { isTombstone } from '@/lib/backend' +import { newestVersionRow } from '@/lib/newestVersion' import { serverBackend } from '@/lib/serverBackend' import { redirect, notFound } from 'next/navigation' @@ -80,42 +80,46 @@ export default async function ComponentDetailPage({ /> ) } - const catalog = body as CatalogComponent + let catalog = body as CatalogComponent + const versionsKnown = snapshotsRes.ok + const snapshots: SnapshotSummaryItem[] = versionsKnown ? ((await snapshotsRes.json()) as SnapshotSummaryItem[]) : [] + // no current version: every version withdrawn, or none published yet. The page is then built on the + // newest version, with a banner, so that the controls of the element are there (8.193, reviewer F1); + // a caller who may not read that version (an outsider with bare rows) keeps the notice if (!catalog.snapshots?.length) { - // the author and the moderators of a piece nobody has published yet see - // its versions (draft, pending, rejected) and their buttons (spec 3.1.5, 7.0) - const inFlight: SnapshotSummaryItem[] = snapshotsRes.ok ? ((await snapshotsRes.json()) as SnapshotSummaryItem[]) : [] - return ( - <> - - {inFlight.length > 0 && ( -
- - - Edit details of the latest version - -
- )} - - ) + const newest = newestVersionRow(snapshots) + const again = newest + ? await serverBackend( + `/identities/${encodeURIComponent(component_id)}/compose?${new URLSearchParams({ snapshots: newest._id })}`) + : null + const shown = again?.ok ? ((await again.json()) as unknown) : null + if (shown && !isTombstone(shown) && (shown as CatalogComponent).snapshots?.length) { + catalog = shown as CatalogComponent + } else { + return ( + <> + + {snapshots.length > 0 && ( +
+ +
+ )} + + ) + } } const snapshot = primarySnapshot(catalog) - let snapshots: SnapshotSummaryItem[] = [] - if (snapshotsRes.ok) { - snapshots = (await snapshotsRes.json()) as SnapshotSummaryItem[] - } let childIdentities: CatalogShallowRow[] = [] if (childrenRes.ok) { const body = (await childrenRes.json()) as CatalogShallowRow[] @@ -126,12 +130,14 @@ export default async function ComponentDetailPage({ const liveSnapshotId = String(catalog.identity.current_snapshot_id ?? '') const activeSnapshotId = String(snapshot._id ?? liveSnapshotId) - const isViewingLive = activeSnapshotId === liveSnapshotId - const liveVersion = - snapshots.find((row) => row._id === liveSnapshotId)?.version ?? - (typeof snapshot.version === 'number' && isViewingLive - ? snapshot.version - : snapshots.find((row) => row.is_current)?.version ?? 0) + // no current version, however the version was opened (default or ?snapshots=): nothing to go back to + const isViewingLive = !!liveSnapshotId && activeSnapshotId === liveSnapshotId + const liveVersion = !liveSnapshotId + ? null + : snapshots.find((row) => row._id === liveSnapshotId)?.version ?? + (typeof snapshot.version === 'number' && isViewingLive + ? snapshot.version + : snapshots.find((row) => row.is_current)?.version ?? 0) const viewingVersion = typeof snapshot.version === 'number' ? snapshot.version @@ -141,6 +147,7 @@ export default async function ComponentDetailPage({ Grasshopper

Components for Rhino 8 and Grasshopper that read from and write to the catalog: fetch components, record - states and evidence, compute frames and descriptors. + snapshots and evidence, compute frames and descriptors.

diff --git a/src/frontend/app/layout.tsx b/src/frontend/app/layout.tsx index 9b06823b..ceeb823b 100644 --- a/src/frontend/app/layout.tsx +++ b/src/frontend/app/layout.tsx @@ -19,7 +19,7 @@ const inter = Inter({ subsets: ['latin'] }) export const metadata: Metadata = { title: 'CSC - Catalog of Second Chances', - description: 'A components and materials database.', + description: 'A digital database for reclaimed architectural components.', } // Beta/gh-interface flags come from the server's .env at request time. Without diff --git a/src/frontend/app/my-work/page.tsx b/src/frontend/app/my-work/page.tsx index 0e820d07..a200088d 100644 --- a/src/frontend/app/my-work/page.tsx +++ b/src/frontend/app/my-work/page.tsx @@ -29,6 +29,7 @@ import { submitRecords, submittableKeys, waitingLines, + WITHDRAWN_DRAFT_NOTE, type MyRecord, type Piece, type SubmitResult, @@ -323,6 +324,9 @@ function MyRecords({ enabled }: { enabled: boolean }) { {[row.piece, row.dataset].filter(Boolean).join(' / ')} + {row.status === 'draft' && row.identityWithdrawn && ( +

{WITHDRAWN_DRAFT_NOTE}

+ )} {row.status === 'rejected' && row.reason && (

Reason: {row.reason}

)} diff --git a/src/frontend/app/page.tsx b/src/frontend/app/page.tsx index 9cd596c4..b70d1c20 100644 --- a/src/frontend/app/page.tsx +++ b/src/frontend/app/page.tsx @@ -61,8 +61,8 @@ export default function Home() {

On the web

-

Browse and filter components, open an element with its geometry and records, and on site record - elements and evidence from a phone.

+

Browse and filter components, open a component with its geometry and records, and on site record + components and evidence from a phone.

In Grasshopper

diff --git a/src/frontend/app/reference/page.tsx b/src/frontend/app/reference/page.tsx index f7ea1ad2..e9e775b6 100644 --- a/src/frontend/app/reference/page.tsx +++ b/src/frontend/app/reference/page.tsx @@ -197,7 +197,7 @@ export default function ReferencePage() { ), example: ( - +

{EXAMPLE_ID_NOTE}

void disabled?: boolean compact?: boolean + /** Roles that cannot be taken away now, with the reason (the last moderator, 8.139 g). */ + locked?: Partial> }) { const toggle = (role: DatasetRole, checked: boolean) => { const next = new Set(value) @@ -39,7 +42,8 @@ export default function RoleCheckboxes({ id={`${idPrefix}-${role.value}`} checked={value.includes(role.value)} onCheckedChange={(checked) => toggle(role.value, checked === true)} - disabled={disabled} + disabled={disabled || (!!locked?.[role.value] && value.includes(role.value))} + title={value.includes(role.value) ? locked?.[role.value] : undefined} />
- - Back to live (v{liveVersion}) - + {liveVersion !== null && ( + + Back to live (v{liveVersion}) + + )} ) } diff --git a/src/frontend/components/components/ComponentLocateById.tsx b/src/frontend/components/components/ComponentLocateById.tsx index 46a2cbb9..2c622a60 100644 --- a/src/frontend/components/components/ComponentLocateById.tsx +++ b/src/frontend/components/components/ComponentLocateById.tsx @@ -76,7 +76,7 @@ const ComponentLocateById: React.FC = ({ presetReferenceID }) => { ? 'border-destructive' : 'border-border' const message = !referenceID - ? 'Scan or paste the id of the element you look for.' + ? 'Scan or paste the id of the component you look for.' : 'Tap to start the camera and scan tags until one matches.' return ( @@ -102,12 +102,12 @@ const ComponentLocateById: React.FC = ({ presetReferenceID }) => { {matched && (

- This is the element you look for. + This is the component you look for.

)} {status === 'bad' && (

- This is not the element you look for. + This is not the component you look for.

)} diff --git a/src/frontend/components/components/ComponentProvenanceCard.tsx b/src/frontend/components/components/ComponentProvenanceCard.tsx index b49cc497..7941be07 100644 --- a/src/frontend/components/components/ComponentProvenanceCard.tsx +++ b/src/frontend/components/components/ComponentProvenanceCard.tsx @@ -14,6 +14,7 @@ import { import type { CatalogShallowRow } from '@/generated/catalogExtras' import InheritedMark from '@/components/lineage/InheritedMark' import ProvenanceEditDialog from '@/components/lineage/ProvenanceEditDialog' +import { everPublished } from '@/lib/everPublished' import { useMe } from '@/lib/me' import ComponentLineageIdentityBadges from './ComponentLineageIdentityBadges' import { @@ -59,20 +60,24 @@ const formatDate = formatDateAtPrecision type ComponentProvenanceCardProps = { catalog: CatalogComponent childIdentities?: CatalogShallowRow[] + /** the version rows: published once is not the same as a current version (8.193) */ + snapshots?: readonly { status?: string | null }[] } export default function ComponentProvenanceCard({ catalog, childIdentities = [], + snapshots, }: ComponentProvenanceCardProps) { const { identity } = catalog const parentIds = parentIdentityIds(identity) const origin = identity.origin const { me, moderates } = useMe() const [editOpen, setEditOpen] = useState(false) - // moderator(D); the creator while it is unpublished (8.9) --- the backend decides + // moderator(D); the creator while nothing was ever published (8.9, 8.193) --- the backend decides const canEdit = !!me && (moderates(identity.dataset) - || (!identity.current_snapshot_id && me._id === identity.created_by_user_id)) + || (!everPublished({ currentSnapshotId: identity.current_snapshot_id, versions: snapshots }) + && me._id === identity.created_by_user_id)) const [parentStatuses, setParentStatuses] = useState>({}) const childBadges = childIdentities.flatMap((row) => { diff --git a/src/frontend/components/components/ComponentSnapshotVersionList.tsx b/src/frontend/components/components/ComponentSnapshotVersionList.tsx index 8ce13005..0a350fc1 100644 --- a/src/frontend/components/components/ComponentSnapshotVersionList.tsx +++ b/src/frontend/components/components/ComponentSnapshotVersionList.tsx @@ -15,6 +15,10 @@ type ComponentSnapshotVersionListProps = { liveSnapshotId: string /** The identity's dataset: decides who sees moderation buttons. */ dataset?: string | null + /** `has_open_snapshot` of the element (8.195) */ + hasOpenSnapshot?: boolean + /** the element is withdrawn (8.190) */ + identityWithdrawn?: boolean } function versionHref(identityId: string, row: SnapshotSummaryItem): string { @@ -38,6 +42,8 @@ export default function ComponentSnapshotVersionList({ activeSnapshotId, liveSnapshotId, dataset, + hasOpenSnapshot, + identityWithdrawn, }: ComponentSnapshotVersionListProps) { const hasPendingUpdate = snapshots.some( (row) => row.status === 'pending' && !row.is_current, @@ -52,7 +58,7 @@ export default function ComponentSnapshotVersionList({

- Snapshot versions + Snapshots

@@ -61,7 +67,7 @@ export default function ComponentSnapshotVersionList({ role="status" className="mb-3 rounded-md border border-amber-300 bg-amber-50 px-3 py-2 text-xs text-amber-950 dark:border-amber-700 dark:bg-amber-950/40 dark:text-amber-100" > - A newer snapshot is awaiting moderation. The current version shown + A newer snapshot is awaiting moderation. The current snapshot shown above remains unchanged until it is published. )} @@ -115,7 +121,7 @@ export default function ComponentSnapshotVersionList({ Geometry not processed @@ -124,13 +130,14 @@ export default function ComponentSnapshotVersionList({
since {formatDay(row.effective_from)}
- +
diff --git a/src/frontend/components/components/ComponentViewer.tsx b/src/frontend/components/components/ComponentViewer.tsx index efa8add1..caf1d6c0 100644 --- a/src/frontend/components/components/ComponentViewer.tsx +++ b/src/frontend/components/components/ComponentViewer.tsx @@ -538,7 +538,7 @@ async function loadExternalMeshes( mode: MeshFileLevel, snapshotRouting: SnapshotMeshRouting | null, ): Promise { - debugLog(`Loading ${mode} meshes for identity ${identityId}`) + debugLog(`Loading ${mode} meshes for component ${identityId}`) const hint = meshHintForCache(snapshotRouting) const cacheKey = `${identityId}:mesh:${mode}:${hint}` @@ -604,7 +604,7 @@ async function loadExternalPointClouds( snapshotRouting: SnapshotMeshRouting | null, pointCloudCount: number, ): Promise { - debugLog(`Loading original point clouds for identity ${identityId}`) + debugLog(`Loading original point clouds for component ${identityId}`) const hint = meshHintForCache(snapshotRouting) const cacheKey = `${identityId}:pc:${hint}:count${pointCloudCount}` @@ -1163,7 +1163,7 @@ function LayoutEntry({ label, status, onClear }: { label: string; status?: strin const LAYOUT_NOTES: Record = { hidden: 'This layout is not visible to you.', failed: 'This layout could not be loaded.', - other_version: 'This layout belongs to another version of the element and is not drawn here.', + other_version: 'This layout belongs to another snapshot of the component and is not drawn here.', no_bars: 'This layout has no bars to draw.', } diff --git a/src/frontend/components/components/detail/AddEvidenceButton.tsx b/src/frontend/components/components/detail/AddEvidenceButton.tsx index 1a55ae30..720c7fee 100644 --- a/src/frontend/components/components/detail/AddEvidenceButton.tsx +++ b/src/frontend/components/components/detail/AddEvidenceButton.tsx @@ -18,15 +18,18 @@ export default function AddEvidenceButton({ dataset, withdrawn, currentSnapshotId, + versions, }: { identityId: string dataset?: string | null withdrawn?: unknown currentSnapshotId?: string | null + /** the rows of the version list: published once is not the same as a current version (8.193) */ + versions?: readonly { status?: string | null }[] | null }) { const { me, isAdmin, rolesIn } = useMe() const href = addEvidenceHref(identityId, - canAddEvidence({ signedIn: !!me, isAdmin, roles: dataset ? rolesIn(dataset) : [], withdrawn, currentSnapshotId })) + canAddEvidence({ signedIn: !!me, isAdmin, roles: dataset ? rolesIn(dataset) : [], withdrawn, currentSnapshotId, versions })) if (!href) return null return ( {showCorrected && [...corrected].sort(newestFirst).map((record) => ( + shownIds={shownIds} identityWithdrawn={!!identity.withdrawn} /> ))} )} diff --git a/src/frontend/components/components/detail/ComponentSimilarCard.tsx b/src/frontend/components/components/detail/ComponentSimilarCard.tsx index 2db4b526..a89d72a6 100644 --- a/src/frontend/components/components/detail/ComponentSimilarCard.tsx +++ b/src/frontend/components/components/detail/ComponentSimilarCard.tsx @@ -34,9 +34,9 @@ import { } from '@/lib/similarPieces' import ComponentPreviewImage from '../ComponentPreviewImage' -const HELP = 'The elements whose shape is closest to this one, compared over the whole radial signature of ' - + 'each element (not the two-dimensional similarity map). Similar in outline and size: the signature ' - + 'measures distances from the centre of the element. Only elements in circulation that you may see are compared.' +const HELP = 'The components whose shape is closest to this one, compared over the whole radial signature of ' + + 'each component (not the two-dimensional similarity map). Similar in outline and size: the signature ' + + 'measures distances from the centre of the component. Only components in circulation that you may see are compared.' function Neighbour({ item }: { item: SimilarPiece }) { const row = item.piece @@ -110,12 +110,12 @@ export default function ComponentSimilarCard({ identityId }: { identityId: strin const label = toggleLabel(card.pieces.length, expanded) return ( -

- Similar elements - + Similar components +

    {shownPieces(card.pieces, expanded).map((item) => )} diff --git a/src/frontend/components/components/detail/HistoryList.tsx b/src/frontend/components/components/detail/HistoryList.tsx index c2f26f03..22bff86f 100644 --- a/src/frontend/components/components/detail/HistoryList.tsx +++ b/src/frontend/components/components/detail/HistoryList.tsx @@ -45,9 +45,9 @@ export type TimelineEvent = HistoryEvent & { } const SECTIONS: Record = { - before_cataloguing: 'Before the element was catalogued', + before_cataloguing: 'Before the component was catalogued', history: 'In the catalog', - after_leaving_circulation: 'After the element left circulation', + after_leaving_circulation: 'After the component left circulation', } function Related({ event }: { event: LineageEvent }) { @@ -99,7 +99,7 @@ function Row({ event }: { event: TimelineEvent | LineageEvent }) { icon = text = ( <> - State v{e.version}{e.name ? ` ${e.name}` : ''} + Snapshot v{e.version}{e.name ? ` ${e.name}` : ''} {e.status && e.status !== 'published' ? `, ${e.status}` : ''} {e.corrected ? ', corrected' : ''} {e.corrects ? ', a correction' : ''} @@ -118,7 +118,7 @@ function Row({ event }: { event: TimelineEvent | LineageEvent }) { {e.corrects ? ', a correction' : ''} {e.verification && e.verification !== 'unverified' ? `, ${vocabLabel(VERIFICATION_STATE_LABELS, e.verification).toLowerCase()}` : ''} - {e.resolution === 'approximate' ? ' (state approximate)' : ''} + {e.resolution === 'approximate' ? ' (snapshot approximate)' : ''} ) : <>Evidence record, withdrawn break @@ -155,7 +155,7 @@ export default function HistoryList({ events, lineage, layers }: {

    {SECTIONS[section.id]}

    - {section.id !== 'history' && outside the folded states} + {section.id !== 'history' && outside the folded snapshots}
      {section.rows.map((event, i) => ( diff --git a/src/frontend/components/components/history/SwimlaneGraph.tsx b/src/frontend/components/components/history/SwimlaneGraph.tsx index 10c413ef..30df3091 100644 --- a/src/frontend/components/components/history/SwimlaneGraph.tsx +++ b/src/frontend/components/components/history/SwimlaneGraph.tsx @@ -189,7 +189,7 @@ export default function SwimlaneGraph({ } if (target.openCorrected) setShowCorrected(true) if (!(await scrollToRecord(target.recordId))) { - toast.message('That record is not on this version of the page.') + toast.message('That record is not on this snapshot of the page.') } } @@ -291,13 +291,13 @@ export default function SwimlaneGraph({

      - Time is in sections and not to scale. Click a version to show it, a number to open its records. + Time is in sections and not to scale. Click a snapshot to show it, a number to open its records.

      -
        +
          {layout.lanes.map(({ lane }) => (
        • {lane.visible && lane.role !== 'piece' ? ( @@ -310,7 +310,7 @@ export default function SwimlaneGraph({ )} - {lane.role === 'parent' ? 'parent' : lane.role === 'child' ? 'child' : 'this element'} + {lane.role === 'parent' ? 'parent' : lane.role === 'child' ? 'child' : 'this component'} {lane.visible && lane.dataset ? ` - ${lane.dataset}` : ''}
        • @@ -341,7 +341,7 @@ export default function SwimlaneGraph({ {history.more > 0 && (

          +{history.more} more{' '} - {history.more === 1 ? 'element is' : 'elements are'} not drawn (twelve lanes at most). The JSON export lists what the lanes hold. + {history.more === 1 ? 'component is' : 'components are'} not drawn (twelve lanes at most). The JSON export lists what the lanes hold.

          )} {busy && busy.includes('|') &&

          Loading the records...

          } diff --git a/src/frontend/components/components/history/SwimlaneSvg.tsx b/src/frontend/components/components/history/SwimlaneSvg.tsx index de546ba9..10a4252b 100644 --- a/src/frontend/components/components/history/SwimlaneSvg.tsx +++ b/src/frontend/components/components/history/SwimlaneSvg.tsx @@ -123,8 +123,8 @@ function LegendRow({ colours, x, y }: { colours: Colours; x: number; y: number } ) return ( <> - {item(0, 'Start of the element', )} - {item(150, 'Version', )} + {item(0, 'Start of the component', )} + {item(150, 'Snapshot', )} {item(240, 'Replaced by a correction', )} {item(420, 'Evidence record', )} {item(560, 'Left circulation', )} @@ -177,7 +177,7 @@ export default function SwimlaneSvg({ height={height} viewBox={`0 0 ${width} ${height}`} role={interactive ? 'group' : 'img'} - aria-label={title ?? 'History of the element and its relatives'} + aria-label={title ?? 'History of the component and its relatives'} fontFamily={FONT} > {palette === 'print' && } @@ -308,7 +308,7 @@ export default function SwimlaneSvg({ {layout.more > 0 && ( - {`+${layout.more} more ${layout.more === 1 ? 'element' : 'elements'} not shown`} + {`+${layout.more} more ${layout.more === 1 ? 'component' : 'components'} not shown`} )} @@ -333,7 +333,7 @@ export default function SwimlaneSvg({ Legend - Dashed lines join an element and the elements it was cut into or assembled from, at the child's first version. + Dashed lines join a component and the components it was cut into or assembled from, at the child's first snapshot. The time axis is in sections by year and not to scale. diff --git a/src/frontend/components/components/map/LocationMapPageClient.tsx b/src/frontend/components/components/map/LocationMapPageClient.tsx index 9ae7a3f8..e0d8c243 100644 --- a/src/frontend/components/components/map/LocationMapPageClient.tsx +++ b/src/frontend/components/components/map/LocationMapPageClient.tsx @@ -55,9 +55,9 @@ import { cn } from '@/lib/utils' import LocationMapCanvas from './LocationMapCanvas' const MAP_HELP = - 'Every element you may see, as a point on the map. Current is where an element is now; Origin is the building it ' - + 'comes from, known for fewer elements. Elements at one place are grouped: click a group to zoom in. Click a ' - + 'element to preview it, or an empty spot to search near it. The filters are those of Browse.' + 'Every component you may see, as a point on the map. Current is where a component is now; Origin is the building it ' + + 'comes from, known for fewer components. Components at one place are grouped: click a group to zoom in. Click a ' + + 'component to preview it, or an empty spot to search near it. The filters are those of Browse.' /** The map and its preview: a click on a piece opens the shared preview panel. */ function MapWithPreview(props: Omit, 'onPick'>) { diff --git a/src/frontend/components/components/overview/ComponentOverviewColumns.tsx b/src/frontend/components/components/overview/ComponentOverviewColumns.tsx index 9afd9773..4a47d59b 100644 --- a/src/frontend/components/components/overview/ComponentOverviewColumns.tsx +++ b/src/frontend/components/components/overview/ComponentOverviewColumns.tsx @@ -80,7 +80,7 @@ function RowMenu({ row }: { row: CatalogShallowRow }) { void copy(row._id, 'Component id copied')}> Copy component id - void copy(snapshotId, 'Version id copied')}> + void copy(snapshotId, 'Snapshot id copied')}> Copy snapshot id void copy(generateGrasshopperPanelXML('ComponentID', row._id), 'Copied as a Grasshopper panel')}> @@ -234,7 +234,7 @@ const OPTIONAL: Record = { _id: { id: '_id', accessorKey: '_id', - header: () => , + header: () => , cell: ({ row }) => , }, catalog_number: { diff --git a/src/frontend/components/datasets/YourDatasets.tsx b/src/frontend/components/datasets/YourDatasets.tsx index f41b53fe..aa91fa25 100644 --- a/src/frontend/components/datasets/YourDatasets.tsx +++ b/src/frontend/components/datasets/YourDatasets.tsx @@ -62,7 +62,7 @@ export default function YourDatasets() {

          Loading...

          ) : rows.length === 0 ? (

          - You are not a member of a dataset yet. Start one for your own elements, or ask a moderator to add you + You are not a member of a dataset yet. Start one for your own components, or ask a moderator to add you to theirs.

          ) : ( diff --git a/src/frontend/components/evidence/EvidenceAttachments.tsx b/src/frontend/components/evidence/EvidenceAttachments.tsx index da31b1f7..1f1d5c3c 100644 --- a/src/frontend/components/evidence/EvidenceAttachments.tsx +++ b/src/frontend/components/evidence/EvidenceAttachments.tsx @@ -2,8 +2,9 @@ /** * The files of one evidence record (spec 3.3.4, decisions 7.3, 8.13): - * list, download (signed-in users only), add, remove. Before publish the - * author removes; after publish only moderator(D) removes, with a reason + * list, download (signed-in users only), add, remove. Who may add and remove + * is `attachmentButtons` (`lib/lifecycleRights.ts`): before publish the author + * removes; after publish only moderator(D) removes, with a reason * (`gdpr` also blanks the file name), and the entry stays as a tombstone. * Names are rendered as text, never as markup; downloads go through the * backend route only. @@ -20,6 +21,7 @@ import type { EvidenceView } from '@/generated' import { BackendError } from '@/lib/backend' import { attachmentUrl, removeAttachment, uploadAttachment, type AttachmentEntry } from '@/lib/evidence/api' import { ATTACHMENT_ACCEPT, MAX_ATTACHMENT_TEXT, fileProblem, prepareUpload } from '@/lib/evidence/photos' +import { attachmentButtons } from '@/lib/lifecycleRights' import { useMe } from '@/lib/me' import { formatDay } from '@/lib/utils' @@ -31,16 +33,19 @@ function sizeText(bytes: number): string { export default function EvidenceAttachments({ record, dataset, + identityWithdrawn = false, onChanged, uploadHelp, }: { record: EvidenceView dataset: string | null | undefined + /** the element is withdrawn: no new file on any of its records (8.190) */ + identityWithdrawn?: boolean onChanged: () => void uploadHelp?: string }) { const { data: session } = useSession() - const { me, moderates, rolesIn } = useMe() + const { me, isAdmin, moderates, rolesIn } = useMe() const input = useRef(null) const [busy, setBusy] = useState(false) const [removing, setRemoving] = useState(null) @@ -49,17 +54,11 @@ export default function EvidenceAttachments({ const entries = (record.attachments ?? []) as AttachmentEntry[] const isAuthor = !!me && record.recorded_by_user_id === me._id const isModerator = moderates(dataset) - const published = record.status === 'published' || record.status === 'withdrawn' - // as the routes decide (7.0): a draft: author or moderator; pending: - // moderator; after publish contributor(D) adds, moderator(D) removes - // the author of a pending correction also adds and removes files (RL4, 8.142 a) - const ownCorrection = isAuthor && Boolean(record.supersedes) && record.status === 'pending' - const canAdd = record.status !== 'withdrawn' && record.status !== 'rejected' && ( - record.status === 'draft' ? isAuthor || isModerator - : record.status === 'pending' ? isModerator || ownCorrection - : rolesIn(dataset).includes('contributor') - ) - const canRemove = published ? isModerator : record.status === 'pending' ? isModerator || ownCorrection : isAuthor || isModerator + // as the routes decide (7.0, 8.190, 8.193): `attachmentButtons` + const { add: canAdd, remove: canRemove } = attachmentButtons({ + isAuthor, isAdmin, isModerator, isContributor: rolesIn(dataset).includes('contributor'), + status: record.status, correction: Boolean(record.supersedes), identityWithdrawn, + }) const add = async (files: FileList | null) => { if (!files || files.length === 0) return @@ -158,7 +157,7 @@ export default function EvidenceAttachments({ open={removing !== null} onOpenChange={(open) => { if (!open) setRemoving(null) }} title={`Remove ${removing?.name || 'the file'}`} - description={published + description={record.status === 'published' || record.status === 'withdrawn' ? 'The file is deleted and its entry stays as a tombstone with your reason. Use the reason gdpr when it shows a person: the file name is blanked too.' : 'The file is deleted; the entry stays marked as removed.'} confirmLabel="Remove" diff --git a/src/frontend/components/evidence/EvidenceCard.tsx b/src/frontend/components/evidence/EvidenceCard.tsx index a9921109..4a93d67a 100644 --- a/src/frontend/components/evidence/EvidenceCard.tsx +++ b/src/frontend/components/evidence/EvidenceCard.tsx @@ -40,6 +40,7 @@ export default function EvidenceCard({ uploadHelp, menu = false, shownIds, + identityWithdrawn = false, }: { record: EvidenceView dataset: string | null | undefined @@ -50,6 +51,8 @@ export default function EvidenceCard({ menu?: boolean /** The ids of the cards the page lists (the paired record is linked only when it is one of them). */ shownIds?: readonly string[] + /** the element is withdrawn: no correction, no new file (8.190, I28) */ + identityWithdrawn?: boolean }) { const [open, setOpen] = useState(defaultOpen) const anchor = recordAnchor(String(record._id)) @@ -82,7 +85,8 @@ export default function EvidenceCard({
          {menu && (
          - +
          )}
      )} diff --git a/src/frontend/components/evidence/LayoutDetails.tsx b/src/frontend/components/evidence/LayoutDetails.tsx index 76791bd1..8a7bbff0 100644 --- a/src/frontend/components/evidence/LayoutDetails.tsx +++ b/src/frontend/components/evidence/LayoutDetails.tsx @@ -60,7 +60,8 @@ export default function LayoutDetails({ const note = typeof payload.accuracy_note === 'string' ? payload.accuracy_note.trim() : '' const bars = Array.isArray(payload.bars) ? payload.bars.length : 0 const open = emptyDocumentFields(payload) - const mayFill = record.status === 'published' && !record.superseded_by && moderates(dataset) && open.length > 0 + // a superseded record can be filled as well: the backend does not check it (#48 case 10) + const mayFill = record.status === 'published' && moderates(dataset) && open.length > 0 const [dialog, setDialog] = useState(false) const rows: [string, React.ReactNode][] = [] diff --git a/src/frontend/components/evidence/PositionPickerDialog.tsx b/src/frontend/components/evidence/PositionPickerDialog.tsx index b7668047..cab74c9b 100644 --- a/src/frontend/components/evidence/PositionPickerDialog.tsx +++ b/src/frontend/components/evidence/PositionPickerDialog.tsx @@ -224,11 +224,11 @@ function PickerBody({ const patchNote = proxyModel ? 'Edge distance measured to the proxy face.' : hit?.patch === 'face' - ? 'This version has no proxy: edge distance is measured to the outer boundary of the flat face you picked on.' + ? 'This snapshot has no proxy: edge distance is measured to the outer boundary of the flat face you picked on.' : hit?.patch === 'estimated-plane' - ? 'A point cloud has no faces and this version has no proxy: edge distance cannot be checked.' + ? 'A point cloud has no faces and this snapshot has no proxy: edge distance cannot be checked.' : hit?.kind === 'mesh' - ? 'The surface here is not a flat face and this version has no proxy: edge distance is not checked.' + ? 'The surface here is not a flat face and this snapshot has no proxy: edge distance is not checked.' : null return ( @@ -242,7 +242,7 @@ function PickerBody({ {mode === 'grid' ? 'Tap or click a face: that point becomes the centre of the grid. Turn the grid with the buttons, then set rows, columns and spacing.' : 'Tap or click the model. A drag still turns the view.'} - {' '}Stored coordinates of {version !== null ? `version ${version}` : 'this version'} (mm). + {' '}Stored coordinates of {version !== null ? `snapshot v${version}` : 'this snapshot'} (mm). diff --git a/src/frontend/components/evidence/PropertiesCard.tsx b/src/frontend/components/evidence/PropertiesCard.tsx index 97c437d4..e928dc46 100644 --- a/src/frontend/components/evidence/PropertiesCard.tsx +++ b/src/frontend/components/evidence/PropertiesCard.tsx @@ -141,7 +141,7 @@ export default function PropertiesCard({ const versionEntries = Object.entries((versionProperties ?? {}) as Record) const blocks: { title: string; entries: [string, FoldedProperty][]; outrankedFor: boolean }[] = [ { title: 'Condition', entries: versionEntries.filter(([quantity]) => quantity === 'condition_grade'), outrankedFor: false }, - { title: 'The element', entries: Object.entries((properties ?? {}) as Record), outrankedFor: true }, + { title: 'The component', entries: Object.entries((properties ?? {}) as Record), outrankedFor: true }, { title: versionLabel, entries: versionEntries.filter(([quantity]) => quantity !== 'condition_grade'), outrankedFor: false }, ].filter((block) => block.entries.length > 0) const derived = blocks.some((block) => block.title === 'Condition') ? null : conditionDerived @@ -171,7 +171,7 @@ export default function PropertiesCard({ )} {empty.kind === 'plain' && (

      - No published evidence yet: nothing is known about this element beyond what its record says. + No published evidence yet: nothing is known about this component beyond what its record says.

      )} {empty.kind === 'link' && ( @@ -184,7 +184,7 @@ export default function PropertiesCard({

      {block.title}

      - {!block.outrankedFor && block.title !== 'Condition' && this version} + {!block.outrankedFor && block.title !== 'Condition' && this snapshot}
        {block.entries.map(([quantity, property]) => ( diff --git a/src/frontend/components/evidence/form/ClaimEditor.tsx b/src/frontend/components/evidence/form/ClaimEditor.tsx index e7685191..37e9f4bb 100644 --- a/src/frontend/components/evidence/form/ClaimEditor.tsx +++ b/src/frontend/components/evidence/form/ClaimEditor.tsx @@ -50,7 +50,7 @@ export function SummaryEditor({ id={`${id}-quantity`} label="Property" help={method.summary_optional - ? 'Leave empty to record the document only: it documents the element and states no value.' + ? 'Leave empty to record the document only: it documents the component and states no value.' : helpFor('quantity')} required={!method.summary_optional} errors={errors} @@ -176,13 +176,13 @@ export function PiecesField({ return } if (pieces.includes(id)) { - setError('That element is already in the list.') + setError('That component is already in the list.') return } try { await backendJson(`/identities/${encodeURIComponent(id)}`) } catch (err) { - setError(err instanceof BackendError ? err.message : 'Could not find that element.') + setError(err instanceof BackendError ? err.message : 'Could not find that component.') return } setError(null) @@ -193,10 +193,10 @@ export function PiecesField({ return (
        - Elements this applies to + Components this applies to

        - One record is made for every element, each with the same claim. Add the others by id, link or scanned tag. + One record is made for every component, each with the same claim. Add the others by id, link or scanned tag.

          {pieces.map((id) => { @@ -205,11 +205,11 @@ export function PiecesField({
        • {row ? `#${row.catalog_number ?? '?'} ${row.name ?? ''}` : id} - {id === thisPiece && (this element)} + {id === thisPiece && (this component)} {id !== thisPiece && ( )} diff --git a/src/frontend/components/evidence/form/EvidenceForm.tsx b/src/frontend/components/evidence/form/EvidenceForm.tsx index f356b748..c6b0fcb8 100644 --- a/src/frontend/components/evidence/form/EvidenceForm.tsx +++ b/src/frontend/components/evidence/form/EvidenceForm.tsx @@ -105,6 +105,7 @@ import { prepareUpload } from '@/lib/evidence/photos' import { getAt, isBlank, parseNumber, setAt, type FormObject } from '@/lib/evidence/schema' import { useRegistry } from '@/lib/evidence/useRegistry' import { useMe } from '@/lib/me' +import { passportOfNewestVersion } from '@/lib/newestVersion' type Picker = | { mode: 'point'; recordKey: string } @@ -169,7 +170,12 @@ export default function EvidenceForm({ loadEvidenceOf(identityId, 'method=core_compression&status=all').catch(() => []), sourceId ? backendJson(`/evidence/${encodeURIComponent(sourceId)}`) : Promise.resolve(null), ]) - .then(([passport, materials, reb, core, record]) => { + .then(async ([first, materials, reb, core, record]) => { + // every version withdrawn: compose has no state, so the form starts from the newest + // version, which the page names as withdrawn (8.193) + const passport = first.snapshots?.length + ? first + : await passportOfNewestVersion(identityId, first, { publishedOnly: true }) if (cancelled) return setCatalog(passport) const material = materials.find((m) => m._id === passport.identity.material) @@ -205,11 +211,14 @@ export default function EvidenceForm({ const snapshot = catalog?.snapshots?.length ? primarySnapshot(catalog) : null const snapshotId = snapshot ? String(snapshot._id ?? '') : '' const dataset = catalog?.identity.dataset ?? null - const canContribute = rolesIn(dataset).includes('contributor') - || (editing && Boolean(dataset) && moderates(dataset)) // an edit is for the author of a draft or a moderator; the record decides const mayEdit = !editing || !corrected || canEditEvidence( corrected.status, corrected.recorded_by_user_id === me?._id, moderates(dataset)) + // the author of a draft keeps the right to edit it after losing the contributor role + // (`_unpublished_editor` asks for the author, not for a role; #48 case 9) + const canContribute = rolesIn(dataset).includes('contributor') + || (editing && Boolean(dataset) && moderates(dataset)) + || (editing && !!corrected && mayEdit && corrected.recorded_by_user_id === me?._id) useEffect(() => { if (!dataset || !me || sourceId) return @@ -541,7 +550,7 @@ export default function EvidenceForm({

          Add evidence

          #{identity.catalog_number} has no published state yet. Evidence is recorded about a state of the - element: come back once a moderator has published its first version. + component: come back once a moderator has published its first snapshot.

      ) @@ -652,7 +661,7 @@ export default function EvidenceForm({ : layout.fanOut === 'pieces' ? plural(state.pieces.length, 'claim') : `1 layout with ${plural(Array.isArray(state.records[0]?.payload.bars) ? (state.records[0].payload.bars as unknown[]).length : 0, 'bar')}` const files = state.files.length + (layout.fanOut === 'observations' ? state.photos.length : 0) - const version = snapshot.version ? `, version ${snapshot.version}` : '' + const version = snapshot.version ? `, snapshot v${snapshot.version}` : '' const withFiles = files > 0 ? `, with ${plural(files, 'file')}` : '' if (editing && corrected) return `Saves the changes to this ${corrected.status} record on ${title}${version}${withFiles}.` if (corrected) { @@ -677,10 +686,18 @@ export default function EvidenceForm({

      {title}{dataset ? ` (${dataset})` : ''} {snapshot.version ? ( - version {snapshot.version} + + snapshot v{snapshot.version}{snapshot.status === 'withdrawn' ? ' (withdrawn)' : ''} + ) : null} {modeChip && {modeChip}}

      + {snapshot.status === 'withdrawn' && ( +

      + Every snapshot of this component is withdrawn, so it has no current snapshot. The record is about the + newest one, snapshot v{snapshot.version}. +

      + )} {editing && corrected && (

      The record keeps its status{corrected.status === 'draft' ? ' and its files; you can add more files' : ' and its files'}. @@ -850,9 +867,9 @@ export default function EvidenceForm({ help={help('PositionInput', 'description')} />

      - A layout belongs to one version: the bars are in the stored coordinates (millimetres) of - {snapshot.version ? ` version ${snapshot.version}` : ' the version'} you see on the component - page. Another version needs a layout of its own. + A layout belongs to one snapshot: the bars are in the stored coordinates (millimetres) of + {snapshot.version ? ` snapshot v${snapshot.version}` : ' the snapshot'} you see on the component + page. Another snapshot needs a layout of its own.

      )} diff --git a/src/frontend/components/evidence/form/PositionField.tsx b/src/frontend/components/evidence/form/PositionField.tsx index 9546d5a0..053c9cbb 100644 --- a/src/frontend/components/evidence/form/PositionField.tsx +++ b/src/frontend/components/evidence/form/PositionField.tsx @@ -44,7 +44,7 @@ export default function PositionField({
      setParent({ ...parent, paired_rebound_id: next })} - placeholder={options.length ? 'Not paired' : 'No rebound record of this element fits'} + placeholder={options.length ? 'Not paired' : 'No rebound record of this component fits'} options={options} /> diff --git a/src/frontend/components/evidence/form/state.ts b/src/frontend/components/evidence/form/state.ts index 02dfddd9..3b7786ae 100644 --- a/src/frontend/components/evidence/form/state.ts +++ b/src/frontend/components/evidence/form/state.ts @@ -219,9 +219,21 @@ function actorsBody(state: FormState, ctx: BuildContext): Record Object.keys(actor).length > 0 && actor.kind !== undefined) } -function summaryBody(summary: SummaryState, quantity: QuantityInfo | undefined): Record | undefined { +/** + * The `summary` of a claim (a method whose result the client sends: `summary_from_client`). The + * server wants the kind of the result with it (`registry._headline`: a claim is `claimed`, else + * 422 `summary.kind`), so the method's `summary_kind` goes along. A method whose result the + * server derives gets no `kind` from the web: the server compares the sent result with the one + * it derives (`_same_result`), so a `kind` of ours has no place there. + */ +export function summaryBody( + summary: SummaryState, + quantity: QuantityInfo | undefined, + method?: Pick, +): Record | undefined { if (!summary.quantity) return undefined const body: Record = { quantity: summary.quantity } + if (method?.summary_from_client && method.summary_kind) body.kind = method.summary_kind const value = parseNumber(summary.value) if (quantity?.kind === 'scalar') { if (summary.value.trim() !== '') body.value = value ?? summary.value @@ -322,7 +334,7 @@ export function buildItems(state: FormState, ctx: BuildContext): EvidenceBulkIte identity_id: identityId, method: method.name as EvidenceBulkItem['method'], payload, - summary: summaryBody(state.summary, quantity), + summary: summaryBody(state.summary, quantity, method), })) as unknown as EvidenceBulkItem[] } diff --git a/src/frontend/components/idtransmission/ComponentIdTransmitter.tsx b/src/frontend/components/idtransmission/ComponentIdTransmitter.tsx index bd54fef1..43550d0e 100644 --- a/src/frontend/components/idtransmission/ComponentIdTransmitter.tsx +++ b/src/frontend/components/idtransmission/ComponentIdTransmitter.tsx @@ -115,7 +115,7 @@ const ComponentIdTransmitter: React.FC = () => { if (data.conflict === 'snapshot') { setIdBlocked(true) setIdCheckMessage( - 'This UUID is already a snapshot id. Use the physical identity id from the tag.', + 'This UUID is already a snapshot id. Use the component id from the tag.', ) } else { // Existing catalog identities are allowed; uniqueness is @@ -128,7 +128,7 @@ const ComponentIdTransmitter: React.FC = () => { if (res.status === 400) { setIdBlocked(true) - setIdCheckMessage('Enter a valid identity UUID.') + setIdCheckMessage('Enter a valid component id.') return } @@ -211,7 +211,7 @@ const ComponentIdTransmitter: React.FC = () => { ) { setStatus('error') setStatusMessage( - data.message || 'This UUID cannot be transmitted as a new identity id.', + data.message || 'This UUID cannot be transmitted as a new component id.', ) return } @@ -378,8 +378,8 @@ const ComponentIdTransmitter: React.FC = () => {
      { setInputId(e.target.value) @@ -442,7 +442,7 @@ const ComponentIdTransmitter: React.FC = () => { Pending ID already exists - You still have a pending identity id in the queue. Do you + You still have a pending component id in the queue. Do you really want to overwrite it? diff --git a/src/frontend/components/lineage/CirculationActions.tsx b/src/frontend/components/lineage/CirculationActions.tsx index d071736b..157086e2 100644 --- a/src/frontend/components/lineage/CirculationActions.tsx +++ b/src/frontend/components/lineage/CirculationActions.tsx @@ -44,7 +44,7 @@ const EXIT_HINTS: Record = { disposed: 'Landfill or incineration. Final.', returned: 'Back to its owner or supplier.', lost: 'Its whereabouts are unknown.', - split: 'Cut up without cataloguing the elements. Catalogued elements set this by themselves.', + split: 'Cut up into parts that are not catalogued. Catalogued components set this by themselves.', } function todayIso(): string { @@ -177,7 +177,7 @@ export function ReenterDialog({ identityId, exit, open, onOpenChange }: { Bring back into circulation - The earlier origin and exit are kept as a past cycle. The next recorded state starts + The earlier origin and exit are kept as a past cycle. The next snapshot starts on the new origin date. diff --git a/src/frontend/components/lineage/DeinstallActions.tsx b/src/frontend/components/lineage/DeinstallActions.tsx index 0aaf2867..fe26f6fe 100644 --- a/src/frontend/components/lineage/DeinstallActions.tsx +++ b/src/frontend/components/lineage/DeinstallActions.tsx @@ -99,8 +99,8 @@ export function DeinstallDialog({ identity, open, onOpenChange }: { Record deinstallation - The element is out of its works. Its reservation stays, and no new state is created; - record one if the element changed. Elements drawn from it that take over its origin follow. + The component is out of its works. Its reservation stays, and no new snapshot is created; + record one if the component changed. Elements drawn from it that take over its origin follow.
      @@ -137,7 +137,7 @@ export function DeinstallDialog({ identity, open, onOpenChange }: { export async function undoDeinstall(identityId: string, refresh: () => void): Promise { try { await backendJson(`/identities/${identityId}/undo-deinstall`, { method: 'POST' }) - toast.success('Deinstallation undone: the element is in place again') + toast.success('Deinstallation undone: the component is in place again') refresh() } catch (err) { toast.error(err instanceof Error ? err.message : 'Undo failed') diff --git a/src/frontend/components/lineage/ProvenanceEditDialog.tsx b/src/frontend/components/lineage/ProvenanceEditDialog.tsx index b66112d7..574d825d 100644 --- a/src/frontend/components/lineage/ProvenanceEditDialog.tsx +++ b/src/frontend/components/lineage/ProvenanceEditDialog.tsx @@ -270,7 +270,7 @@ export default function ProvenanceEditDialog({ identity, open, onOpenChange }: P {hasParents ? "Ticked units follow the parents and change with them. Untick one to make it this component's own." - : 'Elements cut from this component take these values over until they state their own.'} + : 'Components cut from this component take these values over until they state their own.'} @@ -377,7 +377,7 @@ export default function ProvenanceEditDialog({ identity, open, onOpenChange }: P

      Connection features

      - Anchors, dowels, plates or holes on this element. Its own: never taken over by elements cut from it. + Anchors, dowels, plates or holes on this component. Its own: never taken over by components cut from it.