From 4f7677f38bac45f3f2d2cebaef8fb59fb40b81c1 Mon Sep 17 00:00:00 2001 From: "Seb H." <138793908+SebHenn@users.noreply.github.com> Date: Sun, 15 Nov 2026 20:57:31 +0100 Subject: [PATCH] M26, first part: earlier texts of an item Co-Authored-By: Claude Sonnet 5.5 Signed-off-by: Seb H. <138793908+SebHenn@users.noreply.github.com> --- CHANGELOG.md | 3 + docs/curator-handbook.md | 5 + docs/handbuch-kuratoren.md | 5 + docs/operations.md | 3 + docs/roadmap.md | 4 + docs/security.md | 1 + src/Commonage.Web/Audit/AuditLog.cs | 16 + src/Commonage.Web/Audit/AuditText.cs | 3 +- src/Commonage.Web/Data/ArchiveRetention.cs | 3 + src/Commonage.Web/Data/CommonageDbContext.cs | 14 + ...0261115194321_AddItemRevisions.Designer.cs | 1108 +++++++++++++++++ .../20261115194321_AddItemRevisions.cs | 52 + .../CommonageDbContextModelSnapshot.cs | 48 + src/Commonage.Web/Domain/AuditEntry.cs | 1 + src/Commonage.Web/Domain/ItemRevision.cs | 70 ++ .../Pages/Admin/Items/Bulk.cshtml.cs | 6 +- .../Pages/Admin/Items/Edit.cshtml | 35 + .../Pages/Admin/Items/Edit.cshtml.cs | 39 + .../Resources/SharedResource.de.resx | 8 + .../Resources/SharedResource.resx | 8 + tests/Commonage.Tests/ExportTests.cs | 19 + tests/Commonage.Tests/RetentionTests.cs | 21 + tests/Commonage.Tests/RevisionTests.cs | 141 +++ 23 files changed, 1611 insertions(+), 2 deletions(-) create mode 100644 src/Commonage.Web/Data/Migrations/20261115194321_AddItemRevisions.Designer.cs create mode 100644 src/Commonage.Web/Data/Migrations/20261115194321_AddItemRevisions.cs create mode 100644 src/Commonage.Web/Domain/ItemRevision.cs create mode 100644 tests/Commonage.Tests/RevisionTests.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index 26ae576..b9b97a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/docs/curator-handbook.md b/docs/curator-handbook.md index cf04a1b..353ea60 100644 --- a/docs/curator-handbook.md +++ b/docs/curator-handbook.md @@ -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: diff --git a/docs/handbuch-kuratoren.md b/docs/handbuch-kuratoren.md index f90a7d6..5788c2a 100644 --- a/docs/handbuch-kuratoren.md +++ b/docs/handbuch-kuratoren.md @@ -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: diff --git a/docs/operations.md b/docs/operations.md index 871c325..b299d40 100644 --- a/docs/operations.md +++ b/docs/operations.md @@ -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. diff --git a/docs/roadmap.md b/docs/roadmap.md index 7b544cd..b64248f 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -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. diff --git a/docs/security.md b/docs/security.md index d84c3e1..61ac576 100644 --- a/docs/security.md +++ b/docs/security.md @@ -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`). | diff --git a/src/Commonage.Web/Audit/AuditLog.cs b/src/Commonage.Web/Audit/AuditLog.cs index 90094fc..470af55 100644 --- a/src/Commonage.Web/Audit/AuditLog.cs +++ b/src/Commonage.Web/Audit/AuditLog.cs @@ -27,6 +27,22 @@ private async Task RecordOncePerSittingAsync(AuditAction action, ArchiveItem ite Record(action, item.Title, item); } + /// Keeps what a field said before it was changed, in the same save as the change itself. + 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; diff --git a/src/Commonage.Web/Audit/AuditText.cs b/src/Commonage.Web/Audit/AuditText.cs index a123165..99d418c 100644 --- a/src/Commonage.Web/Audit/AuditText.cs +++ b/src/Commonage.Web/Audit/AuditText.cs @@ -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"], @@ -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 diff --git a/src/Commonage.Web/Data/ArchiveRetention.cs b/src/Commonage.Web/Data/ArchiveRetention.cs index 65eefac..3afe57c 100644 --- a/src/Commonage.Web/Data/ArchiveRetention.cs +++ b/src/Commonage.Web/Data/ArchiveRetention.cs @@ -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) { diff --git a/src/Commonage.Web/Data/CommonageDbContext.cs b/src/Commonage.Web/Data/CommonageDbContext.cs index 8fbcc5f..9e127ed 100644 --- a/src/Commonage.Web/Data/CommonageDbContext.cs +++ b/src/Commonage.Web/Data/CommonageDbContext.cs @@ -20,6 +20,7 @@ public class CommonageDbContext(DbContextOptions options) public DbSet Contributions => Set(); public DbSet VisitorNotes => Set(); public DbSet AuditEntries => Set(); + public DbSet ItemRevisions => Set(); public DbSet ArchiveSettings => Set(); public DbSet ArchiveTexts => Set(); @@ -195,6 +196,19 @@ protected override void OnModelCreating(ModelBuilder builder) text.Property(t => t.Text).HasMaxLength(ArchiveText.MaxLength); }); + builder.Entity(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().HasMaxLength(30); + revision.HasIndex(r => new { r.ArchiveItemId, r.At }); + revision.HasOne(r => r.ArchiveItem) + .WithMany() + .OnDelete(DeleteBehavior.Cascade); + }); + builder.Entity(entry => { entry.Property(e => e.UserId).HasMaxLength(450); diff --git a/src/Commonage.Web/Data/Migrations/20261115194321_AddItemRevisions.Designer.cs b/src/Commonage.Web/Data/Migrations/20261115194321_AddItemRevisions.Designer.cs new file mode 100644 index 0000000..b23c050 --- /dev/null +++ b/src/Commonage.Web/Data/Migrations/20261115194321_AddItemRevisions.Designer.cs @@ -0,0 +1,1108 @@ +// +using System; +using Commonage.Web.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using NpgsqlTypes; + +#nullable disable + +namespace Commonage.Web.Data.Migrations +{ + [DbContext(typeof(CommonageDbContext))] + [Migration("20261115194321_AddItemRevisions")] + partial class AddItemRevisions + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "10.0.14") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("ArchiveItemTag", b => + { + b.Property("ItemsId") + .HasColumnType("integer"); + + b.Property("TagsId") + .HasColumnType("integer"); + + b.HasKey("ItemsId", "TagsId"); + + b.HasIndex("TagsId"); + + b.ToTable("ArchiveItemTag"); + }); + + modelBuilder.Entity("Commonage.Web.Domain.ArchiveItem", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CollectionId") + .HasColumnType("integer"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Credit") + .HasMaxLength(300) + .HasColumnType("character varying(300)"); + + b.Property("DateFrom") + .HasColumnType("date"); + + b.Property("DateText") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("DateTo") + .HasColumnType("date"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .HasMaxLength(20000) + .HasColumnType("character varying(20000)"); + + b.Property("HelpWanted") + .HasColumnType("boolean"); + + b.Property("InternalNotes") + .HasMaxLength(20000) + .HasColumnType("character varying(20000)"); + + b.Property("NeedsTranscription") + .HasColumnType("boolean"); + + b.Property("OriginalLocation") + .HasMaxLength(300) + .HasColumnType("character varying(300)"); + + b.Property("PublishedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("ReceivedFrom") + .HasMaxLength(300) + .HasColumnType("character varying(300)"); + + b.Property("ReceivedOn") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("ReferenceNumber") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("RejectedOrWithdrawnAt") + .HasColumnType("timestamp with time zone"); + + b.Property("RightsHolder") + .HasMaxLength(300) + .HasColumnType("character varying(300)"); + + b.Property("RightsUri") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("SearchVector") + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("tsvector") + .HasComputedColumnSql("setweight(to_tsvector('simple', commonage_fold(coalesce(\"Title\", ''))), 'A') || setweight(to_tsvector('simple', commonage_fold(coalesce(\"TagNames\", '') || ' ' || coalesce(\"DateText\", ''))), 'B') || setweight(to_tsvector('simple', commonage_fold(coalesce(\"Description\", ''))), 'C')", true); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("TagNames") + .HasColumnType("text"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(300) + .HasColumnType("character varying(300)"); + + b.Property("UpdatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Version") + .IsConcurrencyToken() + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("xid") + .HasColumnName("xmin"); + + b.HasKey("Id"); + + b.HasIndex("CollectionId"); + + b.HasIndex("DateFrom"); + + b.HasIndex("DateTo"); + + b.HasIndex("ReferenceNumber") + .IsUnique(); + + b.HasIndex("SearchVector"); + + NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("SearchVector"), "GIN"); + + b.HasIndex("Status"); + + b.ToTable("ArchiveItems"); + }); + + modelBuilder.Entity("Commonage.Web.Domain.ArchiveSettings", b => + { + b.Property("Id") + .HasColumnType("integer"); + + b.Property("AccentColor") + .HasMaxLength(7) + .HasColumnType("character varying(7)"); + + b.Property("AcceptVisitorNotes") + .HasColumnType("boolean"); + + b.Property("ActivityLogKeptYears") + .HasColumnType("integer"); + + b.Property("AllowSearchEngines") + .HasColumnType("boolean"); + + b.Property("ContentLanguage") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("DefaultLanguage") + .IsRequired() + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("DefaultRightsUri") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("ImprintNotNeeded") + .HasColumnType("boolean"); + + b.Property("LargePhotos") + .HasColumnType("boolean"); + + b.Property("LogoId") + .HasColumnType("uuid"); + + b.Property("OtherContentLanguages") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("PrivacyReviewed") + .HasColumnType("boolean"); + + b.Property("RejectedKeptMonths") + .HasColumnType("integer"); + + b.Property("RequireTwoFactor") + .HasColumnType("boolean"); + + b.Property("RestoreTestedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("TimeZone") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.HasKey("Id"); + + b.ToTable("ArchiveSettings"); + }); + + modelBuilder.Entity("Commonage.Web.Domain.ArchiveText", b => + { + b.Property("Language") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("Kind") + .HasMaxLength(30) + .HasColumnType("character varying(30)"); + + b.Property("Text") + .IsRequired() + .HasMaxLength(20000) + .HasColumnType("character varying(20000)"); + + b.HasKey("Language", "Kind"); + + b.ToTable("ArchiveTexts"); + }); + + modelBuilder.Entity("Commonage.Web.Domain.AuditEntry", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Action") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("ArchiveItemId") + .HasColumnType("integer"); + + b.Property("At") + .HasColumnType("timestamp with time zone"); + + b.Property("Subject") + .HasMaxLength(300) + .HasColumnType("character varying(300)"); + + b.Property("UserId") + .HasMaxLength(450) + .HasColumnType("character varying(450)"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("ArchiveItemId"); + + b.HasIndex("At"); + + b.ToTable("AuditEntries"); + }); + + modelBuilder.Entity("Commonage.Web.Domain.Collection", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CoverMediaFileId") + .HasColumnType("integer"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Description") + .HasMaxLength(4000) + .HasColumnType("character varying(4000)"); + + b.Property("Position") + .HasColumnType("integer"); + + b.Property("Sort") + .HasColumnType("integer"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.HasKey("Id"); + + b.HasIndex("CoverMediaFileId"); + + b.HasIndex("Position"); + + b.ToTable("Collections"); + }); + + modelBuilder.Entity("Commonage.Web.Domain.Contribution", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ArchiveItemId") + .HasColumnType("integer"); + + b.Property("ConsentCoversSharing") + .HasColumnType("boolean"); + + b.Property("ConsentText") + .IsRequired() + .HasMaxLength(4000) + .HasColumnType("character varying(4000)"); + + b.Property("ContributionLinkId") + .HasColumnType("integer"); + + b.Property("ContributorEmail") + .HasMaxLength(254) + .HasColumnType("character varying(254)"); + + b.Property("ContributorName") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("PersonalDetailsRemovedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("ReferenceCode") + .HasMaxLength(9) + .HasColumnType("character varying(9)"); + + b.Property("Reuse") + .HasColumnType("integer"); + + b.Property("ReviewedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Rights") + .HasColumnType("integer"); + + b.Property("RightsHolder") + .HasMaxLength(300) + .HasColumnType("character varying(300)"); + + b.Property("SendingFingerprint") + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("ShowName") + .HasColumnType("boolean"); + + b.Property("SubmittedAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("ArchiveItemId") + .IsUnique(); + + b.HasIndex("ContributionLinkId"); + + b.HasIndex("ReferenceCode") + .IsUnique(); + + b.HasIndex("SendingFingerprint") + .IsUnique(); + + b.ToTable("Contributions"); + }); + + modelBuilder.Entity("Commonage.Web.Domain.ContributionLink", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CollectionId") + .HasColumnType("integer"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Introduction") + .HasMaxLength(4000) + .HasColumnType("character varying(4000)"); + + b.Property("InviteOnCollectionPage") + .HasColumnType("boolean"); + + b.Property("IsActive") + .HasColumnType("boolean"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("Token") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("character varying(32)"); + + b.HasKey("Id"); + + b.HasIndex("CollectionId"); + + b.HasIndex("Token") + .IsUnique(); + + b.ToTable("ContributionLinks"); + }); + + modelBuilder.Entity("Commonage.Web.Domain.ItemFileText", b => + { + b.Property("ArchiveItemId") + .HasColumnType("integer"); + + b.Property("SearchVector") + .ValueGeneratedOnAddOrUpdate() + .HasColumnType("tsvector") + .HasComputedColumnSql("setweight(to_tsvector('simple', commonage_fold(coalesce(\"Text\", ''))), 'D')", true); + + b.Property("Text") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("ArchiveItemId"); + + b.HasIndex("SearchVector"); + + NpgsqlIndexBuilderExtensions.HasMethod(b.HasIndex("SearchVector"), "GIN"); + + b.ToTable("ItemFileTexts"); + }); + + modelBuilder.Entity("Commonage.Web.Domain.ItemRevision", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ArchiveItemId") + .HasColumnType("integer"); + + b.Property("At") + .HasColumnType("timestamp with time zone"); + + b.Property("Field") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("character varying(30)"); + + b.Property("OldValue") + .HasColumnType("text"); + + b.Property("UserId") + .HasMaxLength(450) + .HasColumnType("character varying(450)"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("ArchiveItemId", "At"); + + b.ToTable("ItemRevisions"); + }); + + modelBuilder.Entity("Commonage.Web.Domain.MediaFile", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AltText") + .HasMaxLength(1000) + .HasColumnType("character varying(1000)"); + + b.Property("ArchiveItemId") + .HasColumnType("integer"); + + b.Property("Caption") + .HasColumnType("text"); + + b.Property("ContentType") + .IsRequired() + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("DeletedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("DerivativeVersion") + .HasColumnType("integer"); + + b.Property("ExtractedText") + .HasColumnType("text"); + + b.Property("HasLarge") + .HasColumnType("boolean"); + + b.Property("OriginalFileName") + .IsRequired() + .HasMaxLength(255) + .HasColumnType("character varying(255)"); + + b.Property("PageCount") + .HasColumnType("integer"); + + b.Property("Position") + .HasColumnType("integer"); + + b.Property("PreviewHeight") + .HasColumnType("integer"); + + b.Property("PreviewWidth") + .HasColumnType("integer"); + + b.Property("ProcessingAttempts") + .HasColumnType("integer"); + + b.Property("ProcessingError") + .HasMaxLength(1000) + .HasColumnType("character varying(1000)"); + + b.Property("RenderedRotation") + .HasColumnType("integer"); + + b.Property("Rotation") + .HasColumnType("integer"); + + b.Property("Sha256") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("character(64)") + .IsFixedLength(); + + b.Property("SizeBytes") + .HasColumnType("bigint"); + + b.Property("Status") + .HasColumnType("integer"); + + b.Property("StorageId") + .HasColumnType("uuid"); + + b.Property("UploadedAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("ArchiveItemId"); + + b.HasIndex("Sha256"); + + b.HasIndex("Status"); + + b.HasIndex("StorageId") + .IsUnique(); + + b.ToTable("MediaFiles"); + }); + + modelBuilder.Entity("Commonage.Web.Domain.StaffProfile", b => + { + b.Property("UserId") + .HasColumnType("text"); + + b.Property("DisplayName") + .HasMaxLength(100) + .HasColumnType("character varying(100)"); + + b.Property("LastLoginAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("UserId"); + + b.ToTable("StaffProfiles"); + }); + + modelBuilder.Entity("Commonage.Web.Domain.Tag", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Kind") + .HasColumnType("integer"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.Property("NormalizedName") + .IsRequired() + .HasMaxLength(50) + .HasColumnType("character varying(50)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique(); + + b.ToTable("Tags"); + }); + + modelBuilder.Entity("Commonage.Web.Domain.VisitorNote", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ArchiveItemId") + .HasColumnType("integer"); + + b.Property("Email") + .HasMaxLength(254) + .HasColumnType("character varying(254)"); + + b.Property("HandledAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Kind") + .HasColumnType("integer"); + + b.Property("Message") + .IsRequired() + .HasMaxLength(4000) + .HasColumnType("character varying(4000)"); + + b.Property("Name") + .HasMaxLength(200) + .HasColumnType("character varying(200)"); + + b.Property("PersonalDetailsRemovedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("ReceivedAt") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("ArchiveItemId"); + + b.HasIndex("HandledAt"); + + b.ToTable("VisitorNotes"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.DataProtection.EntityFrameworkCore.DataProtectionKey", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("FriendlyName") + .HasColumnType("text"); + + b.Property("Xml") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("DataProtectionKeys"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AspNetRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("RoleId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b => + { + b.Property("Id") + .HasColumnType("text"); + + b.Property("AccessFailedCount") + .HasColumnType("integer"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("boolean"); + + b.Property("LockoutEnabled") + .HasColumnType("boolean"); + + b.Property("LockoutEnd") + .HasColumnType("timestamp with time zone"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("PasswordHash") + .HasColumnType("text"); + + b.Property("PhoneNumber") + .HasColumnType("text"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("boolean"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.ToTable("AspNetUsers", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("ProviderKey") + .HasColumnType("text"); + + b.Property("ProviderDisplayName") + .HasColumnType("text"); + + b.Property("UserId") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("text"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("text"); + + b.Property("LoginProvider") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + b.Property("Value") + .HasColumnType("text"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens", (string)null); + }); + + modelBuilder.Entity("ArchiveItemTag", b => + { + b.HasOne("Commonage.Web.Domain.ArchiveItem", null) + .WithMany() + .HasForeignKey("ItemsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Commonage.Web.Domain.Tag", null) + .WithMany() + .HasForeignKey("TagsId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Commonage.Web.Domain.ArchiveItem", b => + { + b.HasOne("Commonage.Web.Domain.Collection", "Collection") + .WithMany("Items") + .HasForeignKey("CollectionId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Collection"); + }); + + modelBuilder.Entity("Commonage.Web.Domain.AuditEntry", b => + { + b.HasOne("Commonage.Web.Domain.ArchiveItem", "ArchiveItem") + .WithMany() + .HasForeignKey("ArchiveItemId") + .OnDelete(DeleteBehavior.SetNull); + + b.Navigation("ArchiveItem"); + }); + + modelBuilder.Entity("Commonage.Web.Domain.Collection", b => + { + b.HasOne("Commonage.Web.Domain.MediaFile", null) + .WithMany() + .HasForeignKey("CoverMediaFileId") + .OnDelete(DeleteBehavior.SetNull); + }); + + modelBuilder.Entity("Commonage.Web.Domain.Contribution", b => + { + b.HasOne("Commonage.Web.Domain.ArchiveItem", "ArchiveItem") + .WithOne("Contribution") + .HasForeignKey("Commonage.Web.Domain.Contribution", "ArchiveItemId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Commonage.Web.Domain.ContributionLink", "ContributionLink") + .WithMany("Contributions") + .HasForeignKey("ContributionLinkId") + .OnDelete(DeleteBehavior.SetNull); + + b.Navigation("ArchiveItem"); + + b.Navigation("ContributionLink"); + }); + + modelBuilder.Entity("Commonage.Web.Domain.ContributionLink", b => + { + b.HasOne("Commonage.Web.Domain.Collection", "Collection") + .WithMany() + .HasForeignKey("CollectionId") + .OnDelete(DeleteBehavior.Restrict) + .IsRequired(); + + b.Navigation("Collection"); + }); + + modelBuilder.Entity("Commonage.Web.Domain.ItemFileText", b => + { + b.HasOne("Commonage.Web.Domain.ArchiveItem", "ArchiveItem") + .WithOne("FileText") + .HasForeignKey("Commonage.Web.Domain.ItemFileText", "ArchiveItemId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ArchiveItem"); + }); + + modelBuilder.Entity("Commonage.Web.Domain.ItemRevision", b => + { + b.HasOne("Commonage.Web.Domain.ArchiveItem", "ArchiveItem") + .WithMany() + .HasForeignKey("ArchiveItemId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ArchiveItem"); + }); + + modelBuilder.Entity("Commonage.Web.Domain.MediaFile", b => + { + b.HasOne("Commonage.Web.Domain.ArchiveItem", "ArchiveItem") + .WithMany("MediaFiles") + .HasForeignKey("ArchiveItemId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ArchiveItem"); + }); + + modelBuilder.Entity("Commonage.Web.Domain.StaffProfile", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithOne() + .HasForeignKey("Commonage.Web.Domain.StaffProfile", "UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Commonage.Web.Domain.VisitorNote", b => + { + b.HasOne("Commonage.Web.Domain.ArchiveItem", "ArchiveItem") + .WithMany() + .HasForeignKey("ArchiveItemId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ArchiveItem"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Commonage.Web.Domain.ArchiveItem", b => + { + b.Navigation("Contribution"); + + b.Navigation("FileText"); + + b.Navigation("MediaFiles"); + }); + + modelBuilder.Entity("Commonage.Web.Domain.Collection", b => + { + b.Navigation("Items"); + }); + + modelBuilder.Entity("Commonage.Web.Domain.ContributionLink", b => + { + b.Navigation("Contributions"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Commonage.Web/Data/Migrations/20261115194321_AddItemRevisions.cs b/src/Commonage.Web/Data/Migrations/20261115194321_AddItemRevisions.cs new file mode 100644 index 0000000..e0ba513 --- /dev/null +++ b/src/Commonage.Web/Data/Migrations/20261115194321_AddItemRevisions.cs @@ -0,0 +1,52 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Commonage.Web.Data.Migrations +{ + /// + public partial class AddItemRevisions : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "ItemRevisions", + columns: table => new + { + Id = table.Column(type: "bigint", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + ArchiveItemId = table.Column(type: "integer", nullable: false), + At = table.Column(type: "timestamp with time zone", nullable: false), + UserId = table.Column(type: "character varying(450)", maxLength: 450, nullable: true), + UserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + Field = table.Column(type: "character varying(30)", maxLength: 30, nullable: false), + OldValue = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_ItemRevisions", x => x.Id); + table.ForeignKey( + name: "FK_ItemRevisions_ArchiveItems_ArchiveItemId", + column: x => x.ArchiveItemId, + principalTable: "ArchiveItems", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ItemRevisions_ArchiveItemId_At", + table: "ItemRevisions", + columns: new[] { "ArchiveItemId", "At" }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ItemRevisions"); + } + } +} diff --git a/src/Commonage.Web/Data/Migrations/CommonageDbContextModelSnapshot.cs b/src/Commonage.Web/Data/Migrations/CommonageDbContextModelSnapshot.cs index b840a2d..fcfe477 100644 --- a/src/Commonage.Web/Data/Migrations/CommonageDbContextModelSnapshot.cs +++ b/src/Commonage.Web/Data/Migrations/CommonageDbContextModelSnapshot.cs @@ -464,6 +464,43 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("ItemFileTexts"); }); + modelBuilder.Entity("Commonage.Web.Domain.ItemRevision", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ArchiveItemId") + .HasColumnType("integer"); + + b.Property("At") + .HasColumnType("timestamp with time zone"); + + b.Property("Field") + .IsRequired() + .HasMaxLength(30) + .HasColumnType("character varying(30)"); + + b.Property("OldValue") + .HasColumnType("text"); + + b.Property("UserId") + .HasMaxLength(450) + .HasColumnType("character varying(450)"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("ArchiveItemId", "At"); + + b.ToTable("ItemRevisions"); + }); + modelBuilder.Entity("Commonage.Web.Domain.MediaFile", b => { b.Property("Id") @@ -951,6 +988,17 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.Navigation("ArchiveItem"); }); + modelBuilder.Entity("Commonage.Web.Domain.ItemRevision", b => + { + b.HasOne("Commonage.Web.Domain.ArchiveItem", "ArchiveItem") + .WithMany() + .HasForeignKey("ArchiveItemId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ArchiveItem"); + }); + modelBuilder.Entity("Commonage.Web.Domain.MediaFile", b => { b.HasOne("Commonage.Web.Domain.ArchiveItem", "ArchiveItem") diff --git a/src/Commonage.Web/Domain/AuditEntry.cs b/src/Commonage.Web/Domain/AuditEntry.cs index 28834dc..4543802 100644 --- a/src/Commonage.Web/Domain/AuditEntry.cs +++ b/src/Commonage.Web/Domain/AuditEntry.cs @@ -59,6 +59,7 @@ public enum AuditAction VisitorNoteDeleted, ItemsImported, AccountNameChanged, + ItemFieldRestored, } /// diff --git a/src/Commonage.Web/Domain/ItemRevision.cs b/src/Commonage.Web/Domain/ItemRevision.cs new file mode 100644 index 0000000..a66c173 --- /dev/null +++ b/src/Commonage.Web/Domain/ItemRevision.cs @@ -0,0 +1,70 @@ +namespace Commonage.Web.Domain; + +/// The descriptive fields whose earlier text is kept. Stored by name. Never a contributor's details or the internal notes. +public enum RevisionField +{ + Title, + Description, + Date, + Credit, + OriginalLocation, + ReferenceNumber, +} + +/// +/// What one field said before a curator or helper changed it. Only changed fields get a row. The row goes with its item +/// (and with the bin's 30 days), and holds no contributor details: the fields it can hold are listed in . +/// +public class ItemRevision +{ + public long Id { get; set; } + public int ArchiveItemId { get; set; } + public ArchiveItem ArchiveItem { get; set; } = null!; + public DateTime At { get; set; } + + /// The account that changed it, and its name at the time, as in the activity log. + public string? UserId { get; set; } + public string? UserName { get; set; } + + public RevisionField Field { get; set; } + + /// The text before the change; null if the field was empty. + public string? OldValue { get; set; } +} + +/// Reads and writes the fields that keep their earlier text. +public static class RevisionFields +{ + public static string? Get(ArchiveItem item, RevisionField field) => field switch + { + RevisionField.Title => item.Title, + RevisionField.Description => item.Description, + RevisionField.Date => item.DateText, + RevisionField.Credit => item.Credit, + RevisionField.OriginalLocation => item.OriginalLocation, + RevisionField.ReferenceNumber => item.ReferenceNumber, + _ => null, + }; + + /// Puts a text back. False if the item would not accept it (an empty title, a date that no longer reads). + public static bool TrySet(ArchiveItem item, RevisionField field, string? value) + { + value = string.IsNullOrWhiteSpace(value) ? null : value; + switch (field) + { + case RevisionField.Title: + if (value is null) + return false; + item.Title = value; + return true; + case RevisionField.Description: item.Description = value; return true; + case RevisionField.Date: return item.TrySetDate(value); + case RevisionField.Credit: item.Credit = value; return true; + case RevisionField.OriginalLocation: item.OriginalLocation = value; return true; + case RevisionField.ReferenceNumber: item.ReferenceNumber = value; return true; + default: return false; + } + } + + public static bool Differ(string? before, string? after) => (before ?? "") != (after ?? ""); +} diff --git a/src/Commonage.Web/Pages/Admin/Items/Bulk.cshtml.cs b/src/Commonage.Web/Pages/Admin/Items/Bulk.cshtml.cs index 715b940..e29b70e 100644 --- a/src/Commonage.Web/Pages/Admin/Items/Bulk.cshtml.cs +++ b/src/Commonage.Web/Pages/Admin/Items/Bulk.cshtml.cs @@ -202,7 +202,11 @@ private bool Apply(ArchiveItem item, List tags, DateTime now) case BulkAction.SetDate: if (item.DateText == Date!.Trim()) return false; - return item.TrySetDate(Date); + var earlier = item.DateText; + if (!item.TrySetDate(Date)) + return false; + audit.RecordRevision(item, RevisionField.Date, earlier); + return true; case BulkAction.MoveToCollection: if (item.CollectionId == CollectionId) return false; diff --git a/src/Commonage.Web/Pages/Admin/Items/Edit.cshtml b/src/Commonage.Web/Pages/Admin/Items/Edit.cshtml index 5f97e81..b67f6a3 100644 --- a/src/Commonage.Web/Pages/Admin/Items/Edit.cshtml +++ b/src/Commonage.Web/Pages/Admin/Items/Edit.cshtml @@ -316,6 +316,41 @@ @if (Model.ItemId is not null) { + @if (Model.Revisions.Count > 0) + { +
+

@T["Earlier texts"]

+
    + @foreach (var revision in Model.Revisions) + { +
  • + + · @(revision.Field switch + { + RevisionField.Title => T["Title"], + RevisionField.Description => T["Description"], + RevisionField.Date => T["Date"], + RevisionField.Credit => T["Credit"], + RevisionField.OriginalLocation => T["Original location"], + _ => T["Reference number"], + }) + · @(revision.UserName ?? T["Unknown"].Value) +
    + @T["Show the text before this change"] +

    @(string.IsNullOrEmpty(revision.OldValue) ? T["Empty"].Value : revision.OldValue)

    +
    + @if (mayManage) + { +
    + +
    + } +
  • + } +
+
+ } + @if (Model.History.Count > 0) {
diff --git a/src/Commonage.Web/Pages/Admin/Items/Edit.cshtml.cs b/src/Commonage.Web/Pages/Admin/Items/Edit.cshtml.cs index f3207c7..693fb02 100644 --- a/src/Commonage.Web/Pages/Admin/Items/Edit.cshtml.cs +++ b/src/Commonage.Web/Pages/Admin/Items/Edit.cshtml.cs @@ -61,6 +61,7 @@ public class EditModel( /// The latest entries of the activity log about this item, newest first. public IReadOnlyList History { get; private set; } = []; + public IReadOnlyList Revisions { get; private set; } = []; /// When the disk is nearly full, curators are told so instead of being offered the upload form. public bool CanUpload => health.CanAcceptUploads(); @@ -319,6 +320,7 @@ public async Task OnPostAsync(int? id, string? command, string? t db.ArchiveItems.Add(item); } + var before = isNew ? null : Enum.GetValues().ToDictionary(f => f, f => RevisionFields.Get(item, f)); item.Title = Input.Title.Trim(); item.Description = string.IsNullOrWhiteSpace(Input.Description) ? null : Input.Description.Trim(); item.CollectionId = Input.CollectionId!.Value; @@ -330,6 +332,9 @@ public async Task OnPostAsync(int? id, string? command, string? t item.Credit = Clean(Input.Credit); item.ReferenceNumber = Clean(Input.ReferenceNumber); item.OriginalLocation = Clean(Input.OriginalLocation); + foreach (var (field, old) in before ?? []) + if (RevisionFields.Differ(old, RevisionFields.Get(item, field))) + audit.RecordRevision(item, field, old); item.ReceivedFrom = Clean(Input.ReceivedFrom); item.ReceivedOn = Clean(Input.ReceivedOn); item.InternalNotes = Clean(Input.InternalNotes); @@ -592,6 +597,35 @@ public async Task OnPostDeleteAsync(int id, CancellationToken can } /// Hides a contribution for good because the contributor withdrew their consent. + /// Puts a field back to what it said before a change. The text it has now is kept as a revision in turn. + public async Task OnPostRestoreTextAsync(int id, long revisionId, CancellationToken cancellationToken) + { + if (!User.MayManage()) + return Forbid(); + + var revision = await db.ItemRevisions.Include(r => r.ArchiveItem).FirstOrDefaultAsync(r => r.Id == revisionId && r.ArchiveItemId == id, cancellationToken); + if (revision is null) + return NotFound(); + var item = revision.ArchiveItem; + if (item.Status == ItemStatus.Withdrawn) + return BadRequest(); + + var current = RevisionFields.Get(item, revision.Field); + if (!RevisionFields.TrySet(item, revision.Field, revision.OldValue)) + { + TempData["Error"] = localizer["This text cannot be put back: the field would be empty or no longer reads as valid."].Value; + return BackToItem(id); + } + if (RevisionFields.Differ(current, RevisionFields.Get(item, revision.Field))) + audit.RecordRevision(item, revision.Field, current); + item.UpdatedAt = DateTime.UtcNow; + audit.Record(AuditAction.ItemFieldRestored, item.Title, item); + await db.SaveChangesAsync(cancellationToken); + + TempData["Message"] = localizer["The earlier text is back."].Value; + return BackToItem(id); + } + public async Task OnPostWithdrawAsync(int id, CancellationToken cancellationToken) { if (!User.MayManage()) @@ -704,6 +738,11 @@ private async Task ShowStateAsync(ArchiveItem? item) OpenNotes = await db.VisitorNotes.CountAsync(n => n.ArchiveItemId == item.Id && n.HandledAt == null); MediaFiles = await db.MediaFiles.Where(f => f.ArchiveItemId == item.Id).OrderBy(f => f.Position).ThenBy(f => f.Id).ToListAsync(); IdenticalFiles = await FindIdenticalFilesAsync(MediaFiles); + Revisions = await db.ItemRevisions + .Where(r => r.ArchiveItemId == item.Id) + .OrderByDescending(r => r.At).ThenByDescending(r => r.Id) + .Take(HistoryLength) + .ToListAsync(); History = await db.AuditEntries .Where(e => e.ArchiveItemId == item.Id) .OrderByDescending(e => e.At).ThenByDescending(e => e.Id) diff --git a/src/Commonage.Web/Resources/SharedResource.de.resx b/src/Commonage.Web/Resources/SharedResource.de.resx index 532caf0..aa49f8a 100644 --- a/src/Commonage.Web/Resources/SharedResource.de.resx +++ b/src/Commonage.Web/Resources/SharedResource.de.resx @@ -997,4 +997,12 @@ Aufnahme {0} von {1} Eine Aufnahme braucht vor der Veröffentlichung ihre Abschrift in der Beschreibung, oder setzen Sie den Haken, dass eine Abschrift folgt. Ausgelassen, weil eine Aufnahme noch keine Abschrift hat: {0}. + Einen früheren Text des Eintrags wiederhergestellt + Frühere Texte + Den Text vor dieser Änderung zeigen + Leer + Diesen Text wiederherstellen + Der frühere Text ist wieder da. + Ursprünglicher Ort + Dieser Text kann nicht zurückgesetzt werden: Das Feld wäre leer oder ließe sich nicht mehr lesen. diff --git a/src/Commonage.Web/Resources/SharedResource.resx b/src/Commonage.Web/Resources/SharedResource.resx index 259ccb5..4e9e941 100644 --- a/src/Commonage.Web/Resources/SharedResource.resx +++ b/src/Commonage.Web/Resources/SharedResource.resx @@ -232,12 +232,14 @@ Each row of a spreadsheet becomes a draft, and the files it names are added to it as photos. Nothing is published, and nothing is imported before you have seen a dry run that lists what is wrong. Each tag can say whether it names a place, a person or a topic. Visitors find all places and all people on pages of their own. Renaming or merging a tag changes it on every item at once. Earlier + Earlier texts Earlier: {0} Edit collection Edit contribution link Edit: {0} Email Email address + Empty Enable account Enabled the account Encrypted with COMMONAGE_LOGIN_KEY @@ -485,6 +487,7 @@ Or type this key into the app: Order of the items Original + Original location Other items in {0} Our archive needs no imprint. Page not found @@ -597,7 +600,9 @@ Request to take it down Restore Restore last tested + Restore this text Restored a photo from the bin + Restored an earlier text of the item Restored the item from the bin Results Reviews contributions, describes, publishes and deletes items, manages collections and contribution links. @@ -652,6 +657,7 @@ Show all tags Show everything Show my name with what I send in + Show the text before this change Showing the newest {0}. Shown to admins on this page and in the list of accounts. Never to visitors. Six digits. Without your phone, type one of your recovery codes instead. Each one works once. @@ -737,6 +743,7 @@ The disk is nearly full, so no photos can be added at the moment. Tell the person who runs the server. The disk is nearly full, so the archive has stopped accepting uploads and contributions. Free disk space (GB): {0}. Whoever runs the server should make room. The dry run + The earlier text is back. The email address can be at most {1} characters long. The email address or password is incorrect. The files for this import are no longer there. Please choose them again. @@ -841,6 +848,7 @@ This reference number is already used by: {0} This site only sets the cookies it needs: one for the chosen language, one to protect forms, and one to keep curators logged in. There are no analytics and no third-party services. Visitors' addresses are held in memory for a short time, to limit abuse of forms and logins.Part of the privacy text an archive starts with. Please have a second translator review it. This text can be at most {1} characters long. + This text cannot be put back: the field would be empty or no longer reads as valid. This text was started on this device earlier. If it is not yours, clear it. Through the decades Tick all on this page diff --git a/tests/Commonage.Tests/ExportTests.cs b/tests/Commonage.Tests/ExportTests.cs index 743f1f2..1c72d92 100644 --- a/tests/Commonage.Tests/ExportTests.cs +++ b/tests/Commonage.Tests/ExportTests.cs @@ -168,6 +168,25 @@ public async Task Items_in_the_bin_are_not_exported() Assert.DoesNotContain(binned.Title, Encoding.UTF8.GetString(Read(zip, "archive.json"))); } + /// The earlier texts of an item are left out on purpose: the archive moves with what is true now. + [Fact] + public async Task Earlier_texts_are_not_exported() + { + var item = await app.CreateContributionAsync(ItemStatus.Published); + var earlier = $"EARLIER-{Guid.NewGuid():N}"; + await app.WithDbAsync(async db => + { + db.ItemRevisions.Add(new ItemRevision { ArchiveItemId = item.Id, At = DateTime.UtcNow, Field = RevisionField.Description, OldValue = earlier }); + return await db.SaveChangesAsync(); + }); + using var admin = app.CreateClient(); + await Browser.LogInAsCuratorAsync(admin); + + using var zip = await ExportAsync(admin, publishedOnly: false, includePersonalData: true); + + Assert.DoesNotContain(earlier, Encoding.UTF8.GetString(Read(zip, "archive.json"))); + } + [Fact] public async Task A_published_only_export_leaves_out_drafts_and_contributions() { diff --git a/tests/Commonage.Tests/RetentionTests.cs b/tests/Commonage.Tests/RetentionTests.cs index 75103be..f02ac78 100644 --- a/tests/Commonage.Tests/RetentionTests.cs +++ b/tests/Commonage.Tests/RetentionTests.cs @@ -203,6 +203,27 @@ await archive.WithDbAsync(async db => Assert.Contains("Deleted activity log entries older than the archive keeps them", await admin.GetStringAsync("/Admin/Activity")); } + [Fact] + public async Task Who_changed_an_earlier_text_is_forgotten_with_the_log_but_the_text_stays() + { + await using var archive = await app.NewArchiveAsync(); + using var admin = await AdminAsync(archive); + await SaveSettingsAsync(admin, new() { ["Input.ActivityLogKeptYears"] = "1" }); + var item = await archive.CreateContributionAsync(ItemStatus.Draft); + await archive.WithDbAsync(async db => + { + db.ItemRevisions.Add(new ItemRevision { ArchiveItemId = item.Id, At = DateTime.UtcNow.AddYears(-2), UserId = "a", UserName = "old@example.org", Field = RevisionField.Description, OldValue = "Old words" }); + db.ItemRevisions.Add(new ItemRevision { ArchiveItemId = item.Id, At = DateTime.UtcNow.AddMonths(-1), UserId = "b", UserName = "new@example.org", Field = RevisionField.Description, OldValue = "Newer words" }); + return await db.SaveChangesAsync(); + }); + + await ApplyAsync(archive); + + var revisions = await archive.WithDbAsync(db => db.ItemRevisions.OrderBy(r => r.At).ToListAsync()); + Assert.Equal(["Old words", "Newer words"], revisions.Select(r => r.OldValue)); + Assert.Equal([null, "new@example.org"], revisions.Select(r => r.UserName)); + } + [Fact] public async Task The_settings_take_only_the_offered_times_and_an_old_form_changes_nothing() { diff --git a/tests/Commonage.Tests/RevisionTests.cs b/tests/Commonage.Tests/RevisionTests.cs new file mode 100644 index 0000000..2ac8ef1 --- /dev/null +++ b/tests/Commonage.Tests/RevisionTests.cs @@ -0,0 +1,141 @@ +using System.Net; +using Commonage.Web.Domain; +using Commonage.Web.Identity; +using Microsoft.EntityFrameworkCore; + +namespace Commonage.Tests; + +[Collection(nameof(AppCollection))] +public class RevisionTests(CommonageAppFactory app) +{ + private async Task DraftAsync(string description) + { + var item = await app.CreateContributionAsync(ItemStatus.Draft); + await app.WithDbAsync(async db => + { + var stored = await db.ArchiveItems.SingleAsync(i => i.Id == item.Id); + stored.Status = ItemStatus.Draft; + stored.Description = description; + return await db.SaveChangesAsync(); + }); + return item; + } + + private static Task SaveAsync(HttpClient client, ArchiveItem item, string description) => + Browser.SendFormAsync(client, $"/Admin/Items/Edit/{item.Id}", new() + { + ["Input.Title"] = item.Title, ["Input.CollectionId"] = item.CollectionId.ToString(), ["Input.Description"] = description, + }); + + private Task> RevisionsAsync(int itemId) => + app.WithDbAsync(db => db.ItemRevisions.AsNoTracking().Where(r => r.ArchiveItemId == itemId).OrderBy(r => r.Id).ToListAsync()); + + [Fact] + public async Task Changing_a_text_keeps_the_earlier_one_and_who_changed_it_and_a_curator_can_put_it_back() + { + using var curator = app.CreateClient(); + await Browser.LogInAsCuratorAsync(curator); + var item = await DraftAsync("The first text"); + + await SaveAsync(curator, item, "The first text"); + Assert.Empty(await RevisionsAsync(item.Id)); + + await SaveAsync(curator, item, "The second text"); + var revision = Assert.Single(await RevisionsAsync(item.Id)); + Assert.Equal(RevisionField.Description, revision.Field); + Assert.Equal("The first text", revision.OldValue); + Assert.Equal(CommonageAppFactory.AdminEmail, revision.UserName); + Assert.Contains("The first text", await curator.GetStringAsync($"/Admin/Items/Edit/{item.Id}")); + + await Browser.PostFormAsync(curator, $"/Admin/Items/Edit/{item.Id}?handler=RestoreText&revisionId={revision.Id}", new(), $"/Admin/Items/Edit/{item.Id}"); + + var stored = await app.WithDbAsync(db => db.ArchiveItems.AsNoTracking().SingleAsync(i => i.Id == item.Id)); + Assert.Equal("The first text", stored.Description); + // What was there before the restore is kept in turn, so nothing is lost by going back. + Assert.Equal(["The first text", "The second text"], (await RevisionsAsync(item.Id)).Select(r => r.OldValue)); + } + + [Fact] + public async Task A_helper_sees_earlier_texts_but_cannot_put_one_back() + { + using var admin = app.CreateClient(); + await Browser.LogInAsCuratorAsync(admin); + var (helper, _, _, _) = await app.CreateAccountAsync(admin, Roles.Helper); + var item = await DraftAsync("Before"); + await SaveAsync(admin, item, "After"); + var revision = Assert.Single(await RevisionsAsync(item.Id)); + + Assert.Contains("Before", await helper.GetStringAsync($"/Admin/Items/Edit/{item.Id}")); + var attempt = await Browser.SendFormAsync(helper, $"/Admin/Items/Edit/{item.Id}?handler=RestoreText&revisionId={revision.Id}", new(), $"/Admin/Items/Edit/{item.Id}"); + + Assert.Contains(attempt.StatusCode, new[] { HttpStatusCode.Forbidden, HttpStatusCode.Redirect, HttpStatusCode.Found }); + var stored = await app.WithDbAsync(db => db.ArchiveItems.AsNoTracking().SingleAsync(i => i.Id == item.Id)); + Assert.Equal("After", stored.Description); + } + + [Fact] + public async Task An_earlier_text_is_never_on_a_public_page_and_a_binned_item_cannot_be_restored_into() + { + using var curator = app.CreateClient(); + await Browser.LogInAsCuratorAsync(curator); + var item = await DraftAsync("Secret first draft words"); + await SaveAsync(curator, item, "Public words"); + await app.WithDbAsync(async db => + { + (await db.ArchiveItems.SingleAsync(i => i.Id == item.Id)).Publish(DateTime.UtcNow); + return await db.SaveChangesAsync(); + }); + var revision = Assert.Single(await RevisionsAsync(item.Id)); + + using var visitor = app.CreateClient(); + var page = await visitor.GetStringAsync($"/items/{item.Id}"); + Assert.Contains("Public words", page); + Assert.DoesNotContain("Secret first draft words", page); + Assert.DoesNotContain($"/items/{item.Id}", await visitor.GetStringAsync("/search?q=Secret+first+draft+words")); + + var editPage = $"/Admin/Items/Edit/{item.Id}"; + await Browser.PostFormAsync(curator, $"{editPage}?handler=Delete", new(), editPage); + var restore = await Browser.SendFormAsync(curator, $"{editPage}?handler=RestoreText&revisionId={revision.Id}", new(), editPage); + Assert.Equal(HttpStatusCode.NotFound, restore.StatusCode); + } + + [Fact] + public async Task Setting_a_date_for_many_items_keeps_the_date_they_had() + { + using var curator = app.CreateClient(); + await Browser.LogInAsCuratorAsync(curator); + var item = await DraftAsync("Words"); + await app.WithDbAsync(async db => + { + (await db.ArchiveItems.SingleAsync(i => i.Id == item.Id)).TrySetDate("1950"); + return await db.SaveChangesAsync(); + }); + var page = await curator.GetStringAsync("/Admin"); + + await curator.PostAsync("/Admin/Items/Bulk?handler=Apply", new FormUrlEncodedContent(new Dictionary + { + ["__RequestVerificationToken"] = Browser.Token(page), ["Action"] = "SetDate", ["Date"] = "1960", ["Ids"] = item.Id.ToString(), + })); + + var revision = Assert.Single(await RevisionsAsync(item.Id)); + Assert.Equal((RevisionField.Date, "1950"), (revision.Field, revision.OldValue)); + } + + [Fact] + public async Task A_revision_is_not_part_of_the_item_and_goes_when_the_item_does() + { + using var curator = app.CreateClient(); + await Browser.LogInAsCuratorAsync(curator); + var item = await DraftAsync("Text before"); + await SaveAsync(curator, item, "Text after"); + Assert.Single(await RevisionsAsync(item.Id)); + + await app.WithDbAsync(async db => + { + db.ArchiveItems.Remove(await db.ArchiveItems.IgnoreQueryFilters().SingleAsync(i => i.Id == item.Id)); + return await db.SaveChangesAsync(); + }); + + Assert.Empty(await RevisionsAsync(item.Id)); + } +}