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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ version may change things that need attention when updating, and these notes say

### For curators

- The page of an item shows its **earlier texts**: when the title, description, date, credit, original location or reference
number was changed, by whom, and what it said before. A curator can put an earlier text back with one button; the text it
replaces is kept in turn. Texts from before this version have no history, and the history is not part of the export.
- AVIF and GIF photos can be uploaded, also through contribution links and as the logo. A GIF becomes one still picture:
the first frame. The original file is kept as it was sent.
- PDF files can be uploaded by curators (not through contribution links). The first page becomes the file's cover and
Expand Down
5 changes: 5 additions & 0 deletions docs/curator-handbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ For the people who look after what an archive holds. You need no technical knowl
- **Tags:** the places, people and topics someone might look for. Before adding a new one, check whether it already
exists under a slightly different name.

**Going back to an earlier text.** Under the form, "Earlier texts" lists each change to the title, description, date, credit,
original location and reference number: when, by whom, and what it said before ("Show the text before this change"). "Restore
this text" puts it back, and the text it replaces is kept in turn, so you can change your mind. A helper can read the list
but not restore. Nothing is listed for changes made before this version.

## Tidying up tags

**Tags** lists every tag with how many items have it. Open one to:
Expand Down
5 changes: 5 additions & 0 deletions docs/handbuch-kuratoren.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ Für alle, die sich um den Bestand eines Archivs kümmern. Technische Kenntnisse
- **Schlagwörter:** die Orte, Personen und Themen, nach denen jemand suchen könnte. Prüfen Sie vor einem neuen Schlagwort, ob
es schon unter einem ähnlichen Namen existiert.

**Zu einem früheren Text zurückkehren.** Unter dem Formular listet „Frühere Texte“ jede Änderung an Titel, Beschreibung, Datierung,
Nennung, ursprünglichem Ort und Referenznummer: wann, von wem und was vorher dastand („Den Text vor dieser Änderung zeigen“). „Diesen
Text wiederherstellen“ setzt ihn zurück, und der ersetzte Text bleibt seinerseits erhalten, Sie können es sich also anders überlegen.
Helfer können die Liste lesen, aber nichts wiederherstellen. Für Änderungen vor dieser Version steht nichts in der Liste.

## Schlagwörter aufräumen

**Schlagwörter** listet jedes Schlagwort auf, mit der Zahl der Einträge, die es haben. Öffnen Sie eines, um:
Expand Down
3 changes: 3 additions & 0 deletions docs/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ their own email, a message, or in person), and the person chooses their own pass
and for seven days. If someone forgets their password, an admin creates a new setup link; earlier links stop
working then.

Earlier texts of items (table `ItemRevisions`) are kept as long as the item is, and go when it is deleted for good. They are not
part of the export, which holds what is true now; a restore from a backup brings them back with the rest of the database.

An account can have a display name, and Commonage remembers when it last logged in (table `StaffProfiles`). Both are shown to
admins on the Accounts pages only, and are not part of the export, which holds no accounts. The activity log names the account
by the email address it had when something was done, so it stays true after a rename or a deleted account.
Expand Down
4 changes: 4 additions & 0 deletions docs/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,10 @@ shows the years of its published items. M19 is complete.

**M26 Description history**

- *Built (part 1):* `ItemRevisions` holds one row per changed field (title, description, date, credit, original location,
reference number) with the text before, the account's name at the time and when; written by `AuditLog.RecordRevision` in the
save of the change. "Restore this text" (curators) puts it back and keeps the replaced text. The item's admin page lists
them. Left out of the export, with a test. Not yet: tags, a side-by-side comparison, a history page across items.
- A revision holds the changed fields only, written in the same save as the activity log. A curator can restore one. No
contributor details in revisions, and the personal-data tools reach them. The export leaves them out, with the reason.

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`. |
| 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. |
| Uploads | Files are recognised by their content (magic bytes), never by name or browser type, and stored under random names outside the web root. Originals are never changed or served to visitors. Previews are made by libvips, rotated upright and stripped of all metadata. Images over 250 megapixels get no preview (decompression bombs), also for GIF and AVIF (`Images_with_more_pixels_than_the_limit_get_no_preview`). GIF and AVIF (libheif with an AV1 decoder, from M23) are further decoders reachable from a contribution link; a GIF is read as its first frame only. There is no time limit on a decode, so a very large AVIF costs memory and time on a small server; the pixel limit and the three-attempt guard are the protection. Size limits per file and per request. A file that the preview maker fails on, in whatever way, costs only its own preview, and one that takes the app down is given up after three attempts instead of at every start (`PreviewFailureTests`). |
Expand Down
16 changes: 16 additions & 0 deletions src/Commonage.Web/Audit/AuditLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@ private async Task RecordOncePerSittingAsync(AuditAction action, ArchiveItem ite
Record(action, item.Title, item);
}

/// <summary>Keeps what a field said before it was changed, in the same save as the change itself.</summary>
public void RecordRevision(ArchiveItem item, RevisionField field, string? oldValue)
{
var user = httpContextAccessor.HttpContext?.User;
var signedIn = user?.Identity?.IsAuthenticated == true;
db.ItemRevisions.Add(new ItemRevision
{
ArchiveItem = item,
At = clock.GetUtcNow().UtcDateTime,
UserId = signedIn ? user!.FindFirstValue(ClaimTypes.NameIdentifier) : null,
UserName = signedIn ? user!.Identity!.Name : null,
Field = field,
OldValue = oldValue,
});
}

public void Record(AuditAction action, string? subject, ArchiveItem? item = null)
{
var user = httpContextAccessor.HttpContext?.User;
Expand Down
3 changes: 2 additions & 1 deletion src/Commonage.Web/Audit/AuditText.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static class AuditText
AuditAction.ItemChanged => localizer["Changed the item"],
AuditAction.ItemPublished => localizer["Published the item"],
AuditAction.ItemUnpublished => localizer["Unpublished the item"],
AuditAction.ItemFieldRestored => localizer["Restored an earlier text of the item"],
AuditAction.ItemDeleted => localizer["Deleted the item for good"],
AuditAction.ItemMovedToBin => localizer["Moved the item to the bin"],
AuditAction.ItemRestored => localizer["Restored the item from the bin"],
Expand Down Expand Up @@ -81,7 +82,7 @@ public static class AuditText

public static AuditKind KindOf(AuditAction action) => action switch
{
AuditAction.ItemCreated or AuditAction.ItemChanged or AuditAction.ItemPublished or AuditAction.ItemUnpublished
AuditAction.ItemCreated or AuditAction.ItemChanged or AuditAction.ItemFieldRestored or AuditAction.ItemPublished or AuditAction.ItemUnpublished
or AuditAction.ItemDeleted or AuditAction.ItemMovedToBin or AuditAction.ItemRestored or AuditAction.ItemPurged
or AuditAction.ItemMovedToBinAfterKeptTime or AuditAction.ItemsImported => AuditKind.Items,
AuditAction.PhotosAdded or AuditAction.PhotosArranged or AuditAction.PhotoDeleted or AuditAction.PhotoMovedToBin
Expand Down
3 changes: 3 additions & 0 deletions src/Commonage.Web/Data/ArchiveRetention.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public async Task ApplyAsync(CancellationToken cancellationToken = default)
{
var cutoff = now.AddYears(-years);
var deleted = await db.AuditEntries.Where(e => e.At < cutoff).ExecuteDeleteAsync(cancellationToken);
// The earlier texts stay with their item, but who changed them is forgotten on the same schedule as the log.
await db.ItemRevisions.IgnoreQueryFilters().Where(r => r.At < cutoff && (r.UserId != null || r.UserName != null))
.ExecuteUpdateAsync(s => s.SetProperty(r => r.UserId, (string?)null).SetProperty(r => r.UserName, (string?)null), cancellationToken);
// The log says that it was shortened, and that entry is the newest, so it stays for the whole time again.
if (deleted > 0)
{
Expand Down
14 changes: 14 additions & 0 deletions src/Commonage.Web/Data/CommonageDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class CommonageDbContext(DbContextOptions<CommonageDbContext> options)
public DbSet<Contribution> Contributions => Set<Contribution>();
public DbSet<VisitorNote> VisitorNotes => Set<VisitorNote>();
public DbSet<AuditEntry> AuditEntries => Set<AuditEntry>();
public DbSet<ItemRevision> ItemRevisions => Set<ItemRevision>();
public DbSet<ArchiveSettings> ArchiveSettings => Set<ArchiveSettings>();
public DbSet<ArchiveText> ArchiveTexts => Set<ArchiveText>();

Expand Down Expand Up @@ -195,6 +196,19 @@ protected override void OnModelCreating(ModelBuilder builder)
text.Property(t => t.Text).HasMaxLength(ArchiveText.MaxLength);
});

builder.Entity<ItemRevision>(revision =>
{
// Goes and comes back with its item, like the item's contribution.
revision.HasQueryFilter(r => r.ArchiveItem.DeletedAt == null);
revision.Property(r => r.UserId).HasMaxLength(450);
revision.Property(r => r.UserName).HasMaxLength(256);
revision.Property(r => r.Field).HasConversion<string>().HasMaxLength(30);
revision.HasIndex(r => new { r.ArchiveItemId, r.At });
revision.HasOne(r => r.ArchiveItem)
.WithMany()
.OnDelete(DeleteBehavior.Cascade);
});

builder.Entity<AuditEntry>(entry =>
{
entry.Property(e => e.UserId).HasMaxLength(450);
Expand Down
Loading
Loading