Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EES-5656 Allow custom ordering of a publication's latest release when reordering releases #5455

Merged
merged 22 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1f7d716
EES-5656 Change PublicationService to use primary constructor
benoutram Dec 10, 2024
3043196
EES-5656 Set the latest published release version for publication bas…
benoutram Dec 10, 2024
a12a200
EES-5656 Add UI tests to cover changing a publication's latest publis…
benoutram Dec 12, 2024
a15bf4f
EES-5656 Correct mistake in UpdateReleaseSeries_UpdatesLatestPublishe…
benoutram Dec 12, 2024
9787a3d
EES-5656 Add additional test UpdateReleaseSeries_UpdatesLatestPublish…
benoutram Dec 12, 2024
5fba23d
EES-5656 Remove incorrect mention of ordering in method comments
benoutram Dec 12, 2024
303e0a1
EES-5656 Remove mention of 'published' in method comments because it'…
benoutram Dec 12, 2024
2bb26de
EES-5656 Check latest release link has correct release name on non-la…
benoutram Dec 12, 2024
7ff9fe3
EES-5656 Change ManageContentPageService.GetManageContentPageViewMode…
benoutram Dec 13, 2024
da82791
EES-5656 Change PublicationService.Get to not use method ListLatestPu…
benoutram Dec 13, 2024
0d82a73
EES-5656 Consolidate methods ListLatestReleaseVersionIds/ListLatestPu…
benoutram Dec 16, 2024
cbbeb43
EES-5656 Change ReleaseService to not use method GetLatestPublishedRe…
benoutram Dec 16, 2024
65a1bb8
EES-5656 Change PermalinkService to not use method GetLatestPublished…
benoutram Dec 16, 2024
364dc08
EES-5656 Change TableBuilderService to not use method GetLatestPublis…
benoutram Dec 16, 2024
2d81e79
EES-5656 Change TableBuilderController to not use method GetLatestPub…
benoutram Dec 16, 2024
2d04ca5
EES-5656 On completing publishing, set the latest published release v…
benoutram Dec 16, 2024
f3012b1
EES-5656 Refactor logic to extract release id's from a release serie…
benoutram Dec 17, 2024
9c87376
EES-5656 Update methods of ReleaseVersionRepository to use release se…
benoutram Dec 18, 2024
2e744b2
EES-5656 Rename method GetLatestPublishedReleaseVersion to GetLatestP…
benoutram Dec 19, 2024
23523e2
EES-5656 Remove ManageContentPageViewModel.PublicationViewModel.Releases
benoutram Dec 19, 2024
9412715
EES-5656 Change ContentService UpdateContent/UpdateContentStaged meth…
benoutram Dec 20, 2024
cf1747a
Merge pull request #5474 from dfe-analytical-services/EES-5656_Publis…
benoutram Dec 20, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
using GovUk.Education.ExploreEducationStatistics.Content.Model;
using GovUk.Education.ExploreEducationStatistics.Content.Model.Database;
using GovUk.Education.ExploreEducationStatistics.Content.Model.Extensions;
using GovUk.Education.ExploreEducationStatistics.Content.Model.Repository;
using GovUk.Education.ExploreEducationStatistics.Content.Model.Repository.Interfaces;
using GovUk.Education.ExploreEducationStatistics.Content.Model.Tests.Fixtures;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -26,10 +27,6 @@
using static GovUk.Education.ExploreEducationStatistics.Common.Model.TimeIdentifier;
using static GovUk.Education.ExploreEducationStatistics.Common.Services.CollectionUtils;
using HtmlBlockViewModel = GovUk.Education.ExploreEducationStatistics.Admin.ViewModels.HtmlBlockViewModel;
using IReleaseVersionRepository =
GovUk.Education.ExploreEducationStatistics.Content.Model.Repository.Interfaces.IReleaseVersionRepository;
using ReleaseVersionRepository =
GovUk.Education.ExploreEducationStatistics.Content.Model.Repository.ReleaseVersionRepository;

namespace GovUk.Education.ExploreEducationStatistics.Admin.Tests.Services.ManageContent
{
Expand Down Expand Up @@ -327,12 +324,6 @@ public async Task GetManageContentPageViewModel()
Assert.Equal(publication.ReleaseSeries[2].LegacyLinkUrl,
contentPublicationReleaseSeries[2].LegacyLinkUrl);

var contentPublicationReleases = contentPublication.Releases;
Assert.Single(contentPublicationReleases);
Assert.Equal(otherReleaseVersion.Id, contentPublicationReleases[0].Id);
Assert.Equal(otherReleaseVersion.Slug, contentPublicationReleases[0].Slug);
Assert.Equal(otherReleaseVersion.Title, contentPublicationReleases[0].Title);

Assert.Equal(2, contentPublication.Methodologies.Count);
Assert.Equal(methodology.Versions[0].Id, contentPublication.Methodologies[0].Id);
Assert.Equal(methodology.Versions[0].Title, contentPublication.Methodologies[0].Title);
Expand Down Expand Up @@ -678,7 +669,7 @@ private static ManageContentPageService SetupManageContentPageService(
IDataBlockService? dataBlockService = null,
IMethodologyVersionRepository? methodologyVersionRepository = null,
IReleaseFileService? releaseFileService = null,
IReleaseVersionRepository? releaseVersionRepository = null,
IReleaseRepository? releaseRepository = null,
IUserService? userService = null)
{
return new(
Expand All @@ -688,7 +679,7 @@ private static ManageContentPageService SetupManageContentPageService(
dataBlockService ?? new Mock<IDataBlockService>().Object,
methodologyVersionRepository ?? new Mock<IMethodologyVersionRepository>().Object,
releaseFileService ?? new Mock<IReleaseFileService>().Object,
releaseVersionRepository ?? new ReleaseVersionRepository(contentDbContext),
releaseRepository ?? new ReleaseRepository(contentDbContext),
userService ?? MockUtils.AlwaysTrueUserService().Object
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ private static PublicationService BuildPublicationService(
IReleaseVersionRepository? releaseVersionRepository = null,
IMethodologyService? methodologyService = null,
IPublicationCacheService? publicationCacheService = null,
IReleaseCacheService? releaseCacheService = null,
IMethodologyCacheService? methodologyCacheService = null,
IRedirectsCacheService? redirectsCacheService = null)
{
Expand All @@ -641,6 +642,7 @@ private static PublicationService BuildPublicationService(
releaseVersionRepository ?? Mock.Of<IReleaseVersionRepository>(Strict),
methodologyService ?? Mock.Of<IMethodologyService>(Strict),
publicationCacheService ?? Mock.Of<IPublicationCacheService>(Strict),
releaseCacheService ?? Mock.Of<IReleaseCacheService>(Strict),
methodologyCacheService ?? Mock.Of<IMethodologyCacheService>(Strict),
redirectsCacheService ?? Mock.Of<IRedirectsCacheService>(Strict));
}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,6 @@ public MappingProfiles()
Title = rv.Publication.Title,
Slug = rv.Publication.Slug,
Contact = rv.Publication.Contact,
Releases = rv.Publication.ReleaseVersions
.FindAll(otherReleaseVersion => rv.Id != otherReleaseVersion.Id &&
IsLatestVersionOfRelease(rv.Publication.ReleaseVersions, otherReleaseVersion.Id))
.OrderByDescending(otherReleaseVersion => otherReleaseVersion.Year)
.ThenByDescending(otherReleaseVersion => otherReleaseVersion.TimePeriodCoverage)
.Select(otherReleaseVersion => new PreviousReleaseViewModel
{
Id = otherReleaseVersion.Id,
Slug = otherReleaseVersion.Slug,
Title = otherReleaseVersion.Title,
})
.ToList(),
ReleaseSeries = new List<ReleaseSeriesItemViewModel>(), // Must be hydrated after mapping
ExternalMethodology = rv.Publication.ExternalMethodology != null
? new ExternalMethodology
Expand Down Expand Up @@ -225,10 +213,5 @@ private void CreateContentBlockMap()

CreateMap<MarkDownBlock, MarkDownBlockViewModel>();
}

private static bool IsLatestVersionOfRelease(IEnumerable<ReleaseVersion> releaseVersions, Guid releaseVersionId)
{
return !releaseVersions.Any(rv => rv.PreviousVersionId == releaseVersionId && rv.Id != releaseVersionId);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
using System.Linq;
using System.Threading.Tasks;
using static GovUk.Education.ExploreEducationStatistics.Common.Model.FileType;
using IReleaseVersionRepository = GovUk.Education.ExploreEducationStatistics.Content.Model.Repository.Interfaces.IReleaseVersionRepository;

namespace GovUk.Education.ExploreEducationStatistics.Admin.Services.ManageContent
{
Expand All @@ -31,7 +30,7 @@ public class ManageContentPageService : IManageContentPageService
private readonly IDataBlockService _dataBlockService;
private readonly IMethodologyVersionRepository _methodologyVersionRepository;
private readonly IReleaseFileService _releaseFileService;
private readonly IReleaseVersionRepository _releaseVersionRepository;
private readonly IReleaseRepository _releaseRepository;
private readonly IUserService _userService;

public ManageContentPageService(
Expand All @@ -41,7 +40,7 @@ public ManageContentPageService(
IDataBlockService dataBlockService,
IMethodologyVersionRepository methodologyVersionRepository,
IReleaseFileService releaseFileService,
IReleaseVersionRepository releaseVersionRepository,
IReleaseRepository releaseRepository,
IUserService userService)
{
_contentDbContext = contentDbContext;
Expand All @@ -50,7 +49,7 @@ public ManageContentPageService(
_dataBlockService = dataBlockService;
_methodologyVersionRepository = methodologyVersionRepository;
_releaseFileService = releaseFileService;
_releaseVersionRepository = releaseVersionRepository;
_releaseRepository = releaseRepository;
_userService = userService;
}

Expand Down Expand Up @@ -101,38 +100,12 @@ public async Task<Either<ActionResult, ManageContentPageViewModel>> GetManageCon

var releaseViewModel = _mapper.Map<ManageContentPageViewModel.ReleaseViewModel>(releaseVersion);

// Hydrate Publication.ReleaseSeries
var publishedVersions =
await _releaseVersionRepository
.ListLatestPublishedReleaseVersions(releaseVersion.PublicationId);
var filteredReleaseSeries = releaseVersion.Publication.ReleaseSeries
.Where(rsi => // only show items for legacy links and published releases
rsi.IsLegacyLink
|| publishedVersions
.Any(rv => rsi.ReleaseId == rv.ReleaseId)
).ToList();
releaseViewModel.Publication.ReleaseSeries = filteredReleaseSeries
.Select(rsi =>
{
if (rsi.IsLegacyLink)
{
return new ReleaseSeriesItemViewModel
{
Description = rsi.LegacyLinkDescription!,
LegacyLinkUrl = rsi.LegacyLinkUrl,
};
}

var latestReleaseVersion = publishedVersions
.Single(rv => rv.ReleaseId == rsi.ReleaseId);
var publishedReleases =
await _releaseRepository.ListPublishedReleases(releaseVersion.PublicationId);

return new ReleaseSeriesItemViewModel
{
Description = latestReleaseVersion.Title,
ReleaseId = latestReleaseVersion.ReleaseId,
ReleaseSlug = latestReleaseVersion.Slug,
};
}).ToList();
// Hydrate Publication.ReleaseSeries
releaseViewModel.Publication.ReleaseSeries =
BuildReleaseSeriesItemViewModels(releaseVersion.Publication, publishedReleases);

releaseViewModel.DownloadFiles = files.ToList();
releaseViewModel.Publication.Methodologies =
Expand All @@ -146,6 +119,37 @@ await _releaseVersionRepository
});
}

private static List<ReleaseSeriesItemViewModel> BuildReleaseSeriesItemViewModels(
Publication publication,
List<Release> publishedReleases)
{
var publishedReleasesById = publishedReleases.ToDictionary(r => r.Id);
return publication.ReleaseSeries
// Only include release series items for legacy links and published releases
.Where(rsi => rsi.IsLegacyLink || publishedReleasesById.ContainsKey(rsi.ReleaseId!.Value))
.Select(rsi =>
{
if (rsi.IsLegacyLink)
{
return new ReleaseSeriesItemViewModel
{
Description = rsi.LegacyLinkDescription!,
LegacyLinkUrl = rsi.LegacyLinkUrl
};
}

var release = publishedReleasesById[rsi.ReleaseId!.Value];

return new ReleaseSeriesItemViewModel
{
Description = release.Title,
ReleaseId = release.Id,
ReleaseSlug = release.Slug
};
})
.ToList();
}

private IQueryable<ReleaseVersion> HydrateReleaseQuery(IQueryable<ReleaseVersion> queryable)
{
// Using `AsSplitQuery` as the generated SQL without it is incredibly
Expand Down
Loading
Loading