Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ version may change things that need attention when updating, and these notes say

### For curators

- **Read an export into an archive.** "Read an export into this archive" on the Export page (admins) takes the ZIP file of a Commonage
export, from this archive or another, and makes a draft of each item, with its photos, tags, collection, date, "What visitors
get" and "Public from". A dry run comes first. What a contributor or visitor gave to the other archive stays there: names,
email addresses, consent texts, visitor notes, internal notes and who gave an item are never read. Items that were rejected or
withdrawn, or whose contributor did not agree to sharing, are left out and listed with the reason. An item that is already
here (same collection, title and date) is never changed, and is not given photos it lacks. A photo that cannot be stored is counted and the item stays a draft with the others. Reads export format versions 4 to 8.
- A run that keeps failing (a full disk, a lost database) or that meets a shutdown stops and says how many items it did not try; each draft that lacks photos has a line in the activity log. A very large import may outlast the browser's wait; its result is in the activity log.
- A published item can have an **embargo**: set "Public from" on the item, and until the start of that day (in the archive's time
zone) it is as hidden as a draft, everywhere, including its pictures. Lists, feeds and the start page put the item where it
belongs on the day it opens. Exports of published items leave out items still under embargo (export format version 8).
Expand Down
26 changes: 26 additions & 0 deletions docs/curator-handbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,32 @@ First you see a dry run. It changes nothing and lists unreadable dates, collecti
and rows that would be there twice. Fix the spreadsheet and check again, or import the rows that are in order and deal with the
rest later. Everything imported is a draft. If it breaks off, run it again: what is already there is left out.

## Reading an export

Admins can read the ZIP file of a Commonage export into an archive, to merge two archives or to start a new one from another:
**Read an export into this archive** on the Export page. A dry run comes first and changes nothing.

What arrives: the title, description, date, tags, collection, rights, "What visitors get" and "Public from" of each item, and its
photos. Everything arrives as a **draft**, whatever it was in the other archive, so you decide what to publish. A collection
that does not exist here is created (at most 50 in one go; import again for the rest). A tag that exists here keeps the kind it
has here.

What does not arrive, and why: the names, email addresses and consent texts of contributors, notes from visitors, internal
notes and who gave an item belong to the other archive and its promises. Items that were rejected or withdrawn there, and items
whose contributor did not agree to sharing, are left out and listed. Items in the other archive's bin are not in its export, so
they are not seen. An item that is already here (same collection, title and date) is not changed, and a photo that is already
here is not added a second time. A credit or rights holder that a curator typed into an item travels with it, so check them before you publish.
Run the same export again after a break-off: what is there is left out. That also holds for an item that arrived without all
its photos (a photo could not be stored, which the page after the import says): it stays a draft with the photos
that did arrive, and the import never adds to an item that is already here. Add the missing photos by hand, or put the draft in
the bin and run the import again. The activity log has a line for each draft that did not get all its photos.

A very large import can take longer than your browser or the server in front of it waits, and the page may then show an error or
nothing at all while the import goes on. Do not start it again: wait, and look at the activity log, where the run's line ("Imported
items from a Commonage export") appears with the number of items and photos when it is done. If the disk or the database keeps
failing, or the server is shut down, the import stops early after the items it has done and the page says how many it did not try;
choose the same file again for the rest.

## A box full of photos

**Add many photos** on the item list makes one draft from each photo. Enter what they share first: the collection, and if
Expand Down
25 changes: 25 additions & 0 deletions docs/handbuch-kuratoren.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,31 @@ bestätigen. Jeder geänderte Eintrag bekommt eine Zeile in seinem Verlauf.
Beim Veröffentlichen von vielen werden nur Entwürfe mit Titel genommen. Über Beiträge wird einzeln entschieden. Rückgängig
machen lässt sich eine Änderung an vielen nicht, also probieren Sie sie im Zweifel erst an wenigen aus.

## Einen Export einlesen

Admins können die ZIP-Datei eines Commonage-Exports in ein Archiv einlesen, um zwei Archive zusammenzuführen oder ein neues aus
einem anderen zu beginnen: **Einen Export in dieses Archiv einlesen** auf der Seite Export. Zuerst kommt ein Probelauf, der nichts
ändert.

Was ankommt: Titel, Beschreibung, Datum, Schlagwörter, Sammlung, Rechte, "Was Besucher bekommen" und "Öffentlich ab" jedes Eintrags
und seine Fotos. Alles kommt als **Entwurf** an, was es im anderen Archiv auch war; was veröffentlicht wird, entscheiden Sie. Eine
Sammlung, die es hier nicht gibt, wird angelegt (höchstens 50 auf einmal; importieren Sie erneut für den Rest). Ein Schlagwort,
das es hier gibt, behält die Art, die es hier hat.

Was nicht ankommt, und warum: Namen, E-Mail-Adressen und Einwilligungstexte der Beitragenden, Hinweise von Besuchern, interne
Notizen und wer einen Eintrag gegeben hat gehören dem anderen Archiv und dem, was dort versprochen wurde. Abgelehnte oder
zurückgezogene Einträge und solche, bei denen die Person der Weitergabe nicht zugestimmt hat, werden ausgelassen und aufgelistet.
Einträge im Papierkorb des anderen Archivs stehen nicht in dessen Export und werden deshalb nicht gesehen. Ein Eintrag, der schon
hier ist (gleiche Sammlung, gleicher Titel, gleiches Datum), wird nicht geändert, und ein Foto, das schon hier ist, wird nicht
noch einmal hinzugefügt. Starten Sie denselben Export nach einem Abbruch erneut: Was da ist, wird ausgelassen. Für jeden Entwurf, der
nicht alle seine Fotos bekommen hat, steht eine Zeile im Aktivitätsprotokoll.

Bei einem sehr großen Import kann der Browser oder der Server davor länger warten, als er will, und die Seite zeigt dann einen Fehler
oder nichts, während der Import weiterläuft. Starten Sie ihn nicht noch einmal: Warten Sie und sehen Sie ins Aktivitätsprotokoll, wo
die Zeile des Laufs ("Objekte aus einem Commonage-Export eingelesen") mit der Zahl der Einträge und Fotos erscheint, wenn er fertig
ist. Fällt der Datenträger oder die Datenbank immer wieder aus oder wird der Server heruntergefahren, endet der Import vorzeitig nach
den Einträgen, die er geschafft hat, und die Seite nennt, wie viele er nicht versucht hat; wählen Sie dieselbe Datei erneut für den Rest.

## Eine Tabelle voller Einträge

Liegt das Archiv schon in einer Tabelle vor, macht **Tabelle importieren** unter Archiv verwalten aus jeder Zeile einen Entwurf.
Expand Down
27 changes: 27 additions & 0 deletions docs/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,33 @@ or email address, including items in the bin. On each item, curators can:

Backups still contain removed data until they are replaced. Delete backups you no longer need.

## Reading an export

Admins can read the ZIP file of a Commonage export on the page **Read an export into this archive** (linked from Export). The
file is kept in `import-staging` on the media volume until the import is done, or a day. It shares the one-at-a-time lock with
the spreadsheet import and runs inside one web request, so the reverse proxy needs the same long timeout. Limits: a ZIP of at most
4 GB; `archive.json` at most 256 MB when unpacked, counted as it is read; at most 20,000 items, 5,000 collections, 50,000 tags and
500 files per item and 100,000 files in all; at most 8 GB of files in all; at most 50 new collections per run; the dry run keeps
at most 10,000 lines and counts the rest. The format versions 4 to 8 are read. Every
item is a draft, and the activity log records the run ("Imported items from a Commonage export", with counts only) and each
new collection, never a title of the other archive's contributors or their details. The database is only added to: nothing is
changed or removed, so a run that breaks off can be run again. A file that cannot be stored (a full disk, a broken ZIP entry) is
counted and shown, never explained with the system's own error text; its item stays a draft with the photos that did arrive and the
activity log has the line for those. The import never adds to an item that is already there, so such an item is not completed by
running again: add the photos by hand, or put the draft in the bin and run the import again. Items from the export carry the
credit and rights holder a curator typed in. The run does not stop when the browser tab is closed. The ZIP file waits in a folder
only the account running the app can read (on Linux and macOS).

How a run fails: only a failed file or save (`IOException`, the ZIP reader's errors, `DbUpdateException`, `NpgsqlException`) is
counted and survived; the warning in the application log names only the exception type and the item's number in the export, never a
file name or message. After 5 failures in a row (a full disk or a lost database) the run stops and creates no further items; it
also stops between items when the app is shutting down. The page then says how many items were not tried, and the same file can be
chosen again for the rest. Any other exception ends the run, but the lock is released, the staged copy removed and the run's line in
the activity log ("items / photos") and the "Added photos" lines are written first. A photo whose save fails has its stored original
removed again. Each draft that lacks photos has a line "Could not add every photo of this item while importing" in the activity
log. A very large import can outlast the browser's or the reverse proxy's wait, so the page may time out while the import goes on;
the result is the line in the activity log.

## Export

"Manage archive" → "Export" (admins) downloads the whole archive as one ZIP file. It needs no Commonage to read, so
Expand Down
1 change: 1 addition & 0 deletions docs/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ vulnerability, see [SECURITY.md](../SECURITY.md).
| Staff names and last login | `StaffProfiles` holds an optional display name and the time of the last login per account, written after a successful login (password, authenticator code or recovery code). Read only on the admin-only Accounts pages, never on a public page, feed or link preview, and not in the export or the activity log (which keeps the email address). Changing a name is logged. The row goes with the account (cascade). `AccountTests`. |
| Helpers | The `Helper` role (policy `Describe`) reaches only the item list, the item form, "Add many photos", the preview and the generated pictures under `/admin/media` (not the original). Everything else under `/Admin` needs `ManageArchive` (curator or admin) or `Administer`. A helper only gets draft items, in the list, the form, the preview and the pictures, never published, submitted, rejected or withdrawn ones: what visitors see changes only through a curator, and no contribution or contributor name or email reaches a helper (the contribution is not even loaded). The start page counts, the "already in the archive" file check and the reference-number check show a helper drafts only. Publishing, unpublishing, accepting, rejecting, deleting, withdrawing and removing a photo are refused with 403 on the server, not only hidden. Accepted: a helper can read "received from" and the internal notes of the items they open; the handbook says so. `HelperTests` (including a test that lists every `/Admin` address a helper can reach), `AccountTests`. |
| Import | Only curators (the `/Admin` policy). The sheet and ZIP are kept in `import-staging` on the media volume, which is never served by path, for a day at most. A sheet is read as strict UTF-8, at most 20 MB and 100,000 rows; a ZIP at most 4 GB and 200,000 entries; every entry is counted as it is unpacked into a temporary file, and a name inside it is never used in a path. A folder to import from is chosen from a listing of `import/`, links and hidden files are skipped. Files go through the same checks as an upload. One import at a time. Everything imported is a draft; the activity log records each item and the import, never the spreadsheet or the contributors' details. `ImportTests`. |
| Reading an export | Admins only (`Administer`), the dry run is `private, no-store`. Same staging folder, one-at-a-time lock and file checks as the spreadsheet import; the ZIP is at most 4 GB and 200,000 entries, `archive.json` at most 256 MB counted as it is unpacked (a ZIP entry's declared size is not trusted), parsed with a depth limit and capped lists (20,000 items, 5,000 collections, 50,000 tags, 500 files per item, 100,000 files in all), at most 8 GB of files in all, 50 new collections per run and 10,000 recorded lines in the dry run (the rest is counted). A file is taken only under the exact path `files/<item>/<file>-<name>`, unique, never by name and never as a path on disk; its type and size are found from the bytes and its sha256 must match. Unknown values are lines in the dry run, not exceptions. **Decision on consent:** a contributor's name, email address, consent text, rights statement and reference code, visitor notes, internal notes and received-from are never deserialised or stored (`ExportImportTable` decides every property of the export, and `ExportImportTests` fails when the exporter gains one without a decision); only whether the contributor agreed to sharing is read, and an item with a contribution that does not say yes (no, null or no answer at all), or one rejected or withdrawn, is left out. The ZIP is staged in a folder and file only the app's account can read (Linux and macOS), and a file that cannot be stored costs only that file, counted without the error text; the run is not cancelled by closing the tab. Everything arrives as a draft, whatever its status, and the code only inserts (a test reads the source for publishing, removing and unfiltered queries). `ExportImportTests`. |
| Earlier texts | `ItemRevisions` keeps what a title, description, date, credit, original location or reference number said before a change, with the account that changed it (its name at the time) and when. The fields are a fixed list (`RevisionField`): never a contributor's name or email, the internal notes or where an item was received from, so removing a contributor's details never has to touch it. Who changed it is forgotten on the activity log's schedule (`ActivityLogKeptYears`); the text itself stays with the item. Shown on the item's admin page only; a curator may restore, a helper only reads. The rows go with their item (cascade, hidden while it is in the bin) and are not exported. `RevisionTests`, `ExportTests`. |
| Recordings | Only curators can add a recording (MP3, M4A, WAV, FLAC, recognised by their first bytes); contribution links refuse them. Visitors hear only a copy made by the app itself (`AudioTools`, no outside program): the sound is copied byte for byte, and ID3v2/ID3v1/APE tags (MP3), `udta`, `meta`, `uuid` and padding boxes and the dates in the headers (M4A), every chunk except `fmt `, `fact` and `data` (WAV), and every block except stream info and the seek table (FLAC) are left out. A file that is not built as its type says (impossible sizes, missing parts, fragmented M4A) fails and has no copy, so nothing is ever served untouched. The parser is managed code reading sizes against the file's length, with the header of an M4A limited to 64 MB; it runs on the single preview queue and a failure marks only that file. Served for published items only, from `/media/{id}/audio` with range requests, with its own copy (`audio/…` key); the original is only at `/admin/media/{id}/original` for curators. Accepted: the sound itself may contain a voice that identifies someone, which is what an oral history is; curators decide what to publish. `AudioTests`. |
| PDF files | Only curators can add a PDF; contribution links refuse it. A PDF is recognised by `%PDF-` and read by poppler (`pdfinfo`, `pdftoppm`), a large C++ parser, so it runs as separate processes, never inside the app: each call has a time limit (`Uploads:PdfTimeoutSeconds`, 60) and is killed with its children when it takes longer, the size of the drawn picture is set by us with `-scale-to` whatever size the page claims, at most 300 pages are drawn, and no part of the file or its name reaches a command line (arguments are passed as a list, the file is copied to a random name in an owner-only temporary folder that is removed afterwards). Pages are served only for published items; the PDF stays private. Accepted: a hostile PDF made by a curator could still exploit poppler, which runs with the app's rights in the container; build with `WITH_PDF=false` to remove it. `poppler-utils` comes from the distribution at build time and is not pinned to a version, so a rebuild of the same commit can ship another poppler (accepted; the base image digest is pinned). The text of a PDF (`pdftotext`, same limits, control characters removed, at most 200,000 characters) is only matched by search, never shown, and it is in the index only while the item is not in the bin and the PDF is not in the bin; a draft is found only by curators, as before. The preview queue is single, so a very long PDF delays other previews (at most 60 s per page); copies of a PDF left by a stopped app are removed at the next start. |
Expand Down
12 changes: 7 additions & 5 deletions src/Commonage.Web/Audit/AuditLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,29 @@ public void RecordRevision(ArchiveItem item, RevisionField field, string? oldVal
});
}

public void Record(AuditAction action, string? subject, ArchiveItem? item = null)
public AuditEntry Record(AuditAction action, string? subject, ArchiveItem? item = null)
{
var user = httpContextAccessor.HttpContext?.User;
var signedIn = user?.Identity?.IsAuthenticated == true;
Add(action, subject, item, signedIn ? user!.FindFirstValue(ClaimTypes.NameIdentifier) : null, signedIn ? user!.Identity!.Name : null);
return Add(action, subject, item, signedIn ? user!.FindFirstValue(ClaimTypes.NameIdentifier) : null, signedIn ? user!.Identity!.Name : null);
}

/// <summary>For what an account does while it logs in, before the request knows who it is.</summary>
public void RecordFor(Microsoft.AspNetCore.Identity.IdentityUser account, AuditAction action, string? subject) =>
Add(action, subject, null, account.Id, account.UserName);

private void Add(AuditAction action, string? subject, ArchiveItem? item, string? userId, string? userName)
private AuditEntry Add(AuditAction action, string? subject, ArchiveItem? item, string? userId, string? userName)
{
db.AuditEntries.Add(new AuditEntry
var entry = new AuditEntry
{
At = clock.GetUtcNow().UtcDateTime,
UserId = userId,
UserName = userName,
Action = action,
ArchiveItem = item,
Subject = subject is { Length: > AuditEntry.SubjectMaxLength } ? subject[..AuditEntry.SubjectMaxLength] : subject,
});
};
db.AuditEntries.Add(entry);
return entry;
}
}
Loading