Repository navigation
Add trash listing, purge and the retention purge job - #2760
Merged
Merged
Conversation
This was referenced Nov 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2696
Adds the trash list, purge and the retention job on top of the delete and restore that came with #2747.
IContentServiceandIContentService<T>getQueryTrashAsyncandPurgeAsync;ContentService.PurgeAsyncdeletes the content rows, references and every version of an entry (published ones included) and raisesEntryPurgedEventper locale; the recurring jobcontent.trash.purgecalls it for what is past each type's retention and logs a report. No system migration:deleted_atanddeleted_bywere already oncms_document, and nothing in the system model changed.Dependencies: none.
Acceptance
Under Q19, everything here is SQLite only until #2711.
TrashTests.ATrashedEntryLeavesEveryReadAndComesBackWithItsVersions: draft and published get and query, version list and version read, publish; after restore the version rows, their snapshots and status are identical.TrashTests.PurgeNeedsItsOwnPermission(Editor, Author, Anonymous and a restore-only role are refused; Super Admin purges) andPurgeDeletesEveryRowOfAnEntryInEveryLocaleAndEveryVersion(document, shared and locale content rows, references and versions, in two locales with published versions; another entry's rows are untouched).TrashPurgeJobTests.TheJobPurgesOnlyWhatIsPastItsRetentionAndLogsAReport(31 days purged, 29 days, today and a live entry stay; the report is logged and a second run is a no-op),EachTypeKeepsItsTrashForItsOwnPeriod,TheJobRunsThroughTheRunnerAndItsScheduleIsStoredOnceHoweverOftenItStarts.Design
restoreorpurgeon the type, and lists only what the principal may read. Each entry carriesdeletedAt, anddeletedBywhere the principal may read who changed an entry.cms_documentis off for that whole query (EF cannot turn it off for the root alone), so every row reached through a relation saysDeletedAt == nullexplicitly, inQueryScope.Rowsand in the in-site check ofFilterCompiler. A trashed target never matches a filter or a row rule and is never populated.TrashTests.ATargetInTheTrashNeverMatchesAFilterOrFillsAPopulatefails without that guard (checked by removing it).ContentService.PurgeAsync, a write like delete and restore:InTransactionAsync, the permission on the type,ReachAllLocalesAsyncwith the purge operation, so the row rule, locale limit and site of thepurgegrant decide. A live entry, another site's or type's, and one the rule excludes are allEntryNotFoundExceptionwith the same message; one reached in only some locales isContentAccessDeniedException, as for restore. The event is staged in the transaction and delivered after the commit; a rolled-back purge, even in a transaction the caller began, leaves every row.FCMS2404as for the trashed one (APurgedTargetIsAsMissingAsATrashedOneWasForPublishing).[PublishPolicy(TrashRetentionDays = n)],ITypeBuilder.PublishPolicy(trashRetentionDays: n),trashRetentionDaysin schema JSON; default 30, least 1. LikemaxVersionsit is written to JSON only when not the default, so no existing model changes its key.PurgeAsyncasPrincipal.SystemwithOrigin.Job, one transaction per entry, at most 500 per type per run (Limitin the payload). An entry that fails is logged and left for the next run without holding up the others (AnEntryThatCannotBePurgedStaysAndDoesNotStopTheOthers), a run with nothing due does nothing, and the report logs how many were purged and failed.AScheduleThatCannotBeStoredAtStartupIsRetriedUntilItIs). A first version that always registered in a background task left the SQLite file locked for host tests that dispose a started host without stopping it (SchemaSyncTests), which is why it is inline.Security
All from the low-privilege side, in
TrashTests:OnlyAPurgeFreesTheValuesTheTrashHolds).restoreorpurgeand the read: a principal with only the read getsContentAccessDeniedException, one with restore but not the read gets theValidationExceptionan unknown type gets, identical in path and code (OnlyWhoCanRestoreOrPurgeAndReadMayLookAtTheTrash).TheTrashListHoldsTheReadRowRuleAndTheFieldLimits), the site and the locale grant, and refuses every locale at once (TheTrashOfAnotherSiteOrLocaleIsNotListed).EntryNotFoundExceptionas a missing id and leaves the entry in the trash (AnEntryThePurgeRuleExcludesIsNotFoundWhateverTheIdIsAndStaysInTheTrash); the locale and site limits (PurgeNeedsTheGrantOnEveryLocaleOfTheEntryAndTheSiteOfIt); only an entry in the trash, of that type (OnlyAnEntryInTheTrashCanBePurged).Verification
On Windows:
dotnet build -c Release -warnaserror,dotnet test -c Releaseanddotnet pack -c Releasepass;markdownlint-cli2on the spec found nothing. The twoSchemaSyncTestsfailures described above showed up in a first full run, were traced to the background schedule by disabling the service, and are gone after the change (three repeat runs).Decisions worth a look
IContentServicesurface gains two members on both interfaces,FluentCMS.Testing's scoped services forward them, andITypeBuilder.PublishPolicygains an optional parameter, all inPublicAPI.Unshipped.txt.Known gaps
deletedAtanddeletedByare added to the page after the engine ran, so they cannot be filtered or sorted on.