* ContentVersion cleanup backoffice UI (#11637) * init rollback ui prototype * add busy state to button, deselect version, add pagination status * add localisation * style current version * disable rollback button when nothing is selected * stop click event * Endpoints for paginated content versions. Light on tests, tight on time. * Endpoints to "pin" content versions * camel case json output. Not sure why json formatter not set for controller, bit risky to add it now * wire up paging * wire up pin/unpin * rename getPagedRollbackVersions to getPagedContentVersions * prevent selection of current version and current draft * add current draft and current version to UI * remove pointer if the row is not selectable * Improve warning for globally disabled cleanup feature. * Fix current loses prevent cleanup state on publish. * Added umbracoLog audit entries for "pin" / "unpin" * Match v9 defaults for keepVersions settings * Fix - losing preventCleanup on save current with content changes * update pin/unpin button labels * fix pagination bug * add missing " * always send culture when a doc type can vary Co-authored-by: Mads Rasmussen <madsr@hey.com> # Conflicts: # src/Umbraco.Core/ContentEditing/ContentVersionMetaViewModel.cs # src/Umbraco.Core/Models/HistoricContentVersionMeta.cs # src/Umbraco.Infrastructure/Services/Implement/ContentService.cs # src/Umbraco.Tests/Persistence/Repositories/DocumentVersionRepository_Tests_Integration.cs # src/Umbraco.Tests/Services/ContentVersionCleanupService_Tests_UnitTests.cs # src/Umbraco.Web.BackOffice/Controllers/ContentController.cs # src/Umbraco.Web.UI.Client/src/common/resources/content.resource.js # src/Umbraco.Web.UI/config/umbracoSettings.Release.config # src/Umbraco.Web.UI/umbraco/config/lang/en.xml # src/Umbraco.Web.UI/umbraco/config/lang/en_us.xml # src/Umbraco.Web/Umbraco.Web.csproj * Added tests * Misc - missed translation update * Bugfix - DocumentVersionRepository.Get should not join culture variation * Bugfix - Missing write lock * Removed unnecessary view model * Misc - kill some warnings * Misc - Kill some more warnings * Fixed cypress rollback test * Bugfix - Policy returns items to delete not items to keep. Switch to inverse behavior. # Conflicts: # src/Umbraco.Tests/Services/DefaultContentVersionCleanupPolicy_Tests_UnitTests.cs Co-authored-by: Paul Johnson <pmj@umbraco.com>
168 lines
6.8 KiB
C#
168 lines
6.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using AutoFixture.NUnit3;
|
|
using Moq;
|
|
using NUnit.Framework;
|
|
using Umbraco.Cms.Core.Events;
|
|
using Umbraco.Cms.Core.Models;
|
|
using Umbraco.Cms.Core.Notifications;
|
|
using Umbraco.Cms.Core.Persistence.Repositories;
|
|
using Umbraco.Cms.Core.Services;
|
|
using Umbraco.Cms.Core.Services.Implement;
|
|
using Umbraco.Cms.Tests.UnitTests.AutoFixture;
|
|
|
|
namespace Umbraco.Tests.Services
|
|
{
|
|
[TestFixture]
|
|
internal class ContentVersionCleanupServiceTest
|
|
{
|
|
[Test]
|
|
[AutoMoqData]
|
|
public void PerformContentVersionCleanup_Always_RespectsDeleteRevisionsCancellation(
|
|
[Frozen] Mock<IScopedNotificationPublisher> eventAggregator,
|
|
[Frozen] Mock<IContentVersionCleanupPolicy> policy,
|
|
[Frozen] Mock<IDocumentVersionRepository> documentVersionRepository,
|
|
List<ContentVersionMeta> someHistoricVersions,
|
|
DateTime aDateTime,
|
|
ContentVersionService sut)
|
|
{
|
|
documentVersionRepository.Setup(x => x.GetDocumentVersionsEligibleForCleanup())
|
|
.Returns(someHistoricVersions);
|
|
|
|
eventAggregator.Setup(x => x.PublishCancelable(It.IsAny<ContentDeletingVersionsNotification>()))
|
|
.Returns(true);
|
|
|
|
policy.Setup(x => x.Apply(aDateTime, someHistoricVersions))
|
|
.Returns(someHistoricVersions);
|
|
|
|
// # Act
|
|
IReadOnlyCollection<ContentVersionMeta> report = sut.PerformContentVersionCleanup(aDateTime);
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
eventAggregator.Verify(x => x.PublishCancelable(It.IsAny<ContentDeletingVersionsNotification>()), Times.Exactly(someHistoricVersions.Count));
|
|
Assert.AreEqual(0, report.Count);
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
[AutoMoqData]
|
|
public void PerformContentVersionCleanup_Always_FiresDeletedVersionsForEachDeletedVersion(
|
|
[Frozen] Mock<IScopedNotificationPublisher> eventAggregator,
|
|
[Frozen] Mock<IContentVersionCleanupPolicy> policy,
|
|
[Frozen] Mock<IDocumentVersionRepository> documentVersionRepository,
|
|
List<ContentVersionMeta> someHistoricVersions,
|
|
DateTime aDateTime,
|
|
ContentVersionService sut)
|
|
{
|
|
documentVersionRepository.Setup(x => x.GetDocumentVersionsEligibleForCleanup())
|
|
.Returns(someHistoricVersions);
|
|
|
|
eventAggregator
|
|
.Setup(x => x.PublishCancelable(It.IsAny<ICancelableNotification>()))
|
|
.Returns(false);
|
|
|
|
policy.Setup(x => x.Apply(aDateTime, someHistoricVersions))
|
|
.Returns(someHistoricVersions);
|
|
|
|
// # Act
|
|
sut.PerformContentVersionCleanup(aDateTime);
|
|
|
|
eventAggregator.Verify(x => x.Publish(It.IsAny<ContentDeletedVersionsNotification>()), Times.Exactly(someHistoricVersions.Count));
|
|
}
|
|
|
|
[Test, AutoMoqData]
|
|
public void PerformContentVersionCleanup_Always_ReturnsReportOfDeletedItems(
|
|
[Frozen] Mock<IScopedNotificationPublisher> eventAggregator,
|
|
[Frozen] Mock<IContentVersionCleanupPolicy> policy,
|
|
[Frozen] Mock<IDocumentVersionRepository> documentVersionRepository,
|
|
List<ContentVersionMeta> someHistoricVersions,
|
|
DateTime aDateTime,
|
|
ContentVersionService sut)
|
|
{
|
|
documentVersionRepository.Setup(x => x.GetDocumentVersionsEligibleForCleanup())
|
|
.Returns(someHistoricVersions);
|
|
|
|
eventAggregator
|
|
.Setup(x => x.PublishCancelable(It.IsAny<ICancelableNotification>()))
|
|
.Returns(false);
|
|
|
|
// # Act
|
|
var report = sut.PerformContentVersionCleanup(aDateTime);
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.Greater(report.Count, 0);
|
|
Assert.AreEqual(someHistoricVersions.Count, report.Count);
|
|
});
|
|
}
|
|
|
|
[Test, AutoMoqData]
|
|
public void PerformContentVersionCleanup_Always_AdheresToCleanupPolicy(
|
|
[Frozen] Mock<IScopedNotificationPublisher> eventAggregator,
|
|
[Frozen] Mock<IContentVersionCleanupPolicy> policy,
|
|
[Frozen] Mock<IDocumentVersionRepository> documentVersionRepository,
|
|
List<ContentVersionMeta> someHistoricVersions,
|
|
DateTime aDateTime,
|
|
ContentVersionService sut)
|
|
{
|
|
documentVersionRepository.Setup(x => x.GetDocumentVersionsEligibleForCleanup())
|
|
.Returns(someHistoricVersions);
|
|
|
|
eventAggregator
|
|
.Setup(x => x.PublishCancelable(It.IsAny<ICancelableNotification>()))
|
|
.Returns(false);
|
|
|
|
policy.Setup(x => x.Apply(It.IsAny<DateTime>(), It.IsAny<IEnumerable<ContentVersionMeta>>()))
|
|
.Returns<DateTime, IEnumerable<ContentVersionMeta>>((_, items) => items.Take(1));
|
|
|
|
// # Act
|
|
var report = sut.PerformContentVersionCleanup(aDateTime);
|
|
|
|
Debug.Assert(someHistoricVersions.Count > 1);
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
policy.Verify(x => x.Apply(aDateTime, someHistoricVersions), Times.Once);
|
|
Assert.AreEqual(someHistoricVersions.First(), report.Single());
|
|
});
|
|
}
|
|
|
|
/// <remarks>
|
|
/// For v9 this just needs a rewrite, no static events, no service location etc
|
|
/// </remarks>
|
|
[Test, AutoMoqData]
|
|
public void PerformContentVersionCleanup_HasVersionsToDelete_CallsDeleteOnRepositoryWithFilteredSet(
|
|
[Frozen] Mock<IScopedNotificationPublisher> eventAggregator,
|
|
[Frozen] Mock<IContentVersionCleanupPolicy> policy,
|
|
[Frozen] Mock<IDocumentVersionRepository> documentVersionRepository,
|
|
List<ContentVersionMeta> someHistoricVersions,
|
|
DateTime aDateTime,
|
|
ContentVersionService sut)
|
|
{
|
|
documentVersionRepository.Setup(x => x.GetDocumentVersionsEligibleForCleanup())
|
|
.Returns(someHistoricVersions);
|
|
|
|
eventAggregator
|
|
.Setup(x => x.PublishCancelable(It.IsAny<ICancelableNotification>()))
|
|
.Returns(false);
|
|
|
|
var filteredSet = someHistoricVersions.Take(1);
|
|
|
|
policy.Setup(x => x.Apply(It.IsAny<DateTime>(), It.IsAny<IEnumerable<ContentVersionMeta>>()))
|
|
.Returns<DateTime, IEnumerable<ContentVersionMeta>>((_, items) => filteredSet);
|
|
|
|
// # Act
|
|
var report = sut.PerformContentVersionCleanup(aDateTime);
|
|
|
|
Debug.Assert(someHistoricVersions.Any());
|
|
|
|
var expectedId = filteredSet.First().VersionId;
|
|
|
|
documentVersionRepository.Verify(x => x.DeleteVersions(It.Is<IEnumerable<int>>(y => y.Single() == expectedId)), Times.Once);
|
|
}
|
|
}
|
|
}
|