Skip to content

Commit d573baa

Browse files
authored
Merge pull request #1675 - Fix contest visibility inconsistencies
Fix contest visibility inconsistencies
2 parents 51e7266 + dab1223 commit d573baa

2 files changed

Lines changed: 28 additions & 8 deletions

File tree

Services/UI/OJS.Services.Ui.Business/Implementations/ContestsBusinessService.cs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace OJS.Services.Ui.Business.Implementations;
1313
using OJS.Services.Infrastructure.Constants;
1414
using OJS.Services.Infrastructure.Extensions;
1515
using OJS.Services.Infrastructure.Models;
16+
using OJS.Services.Infrastructure;
1617
using OJS.Services.Ui.Business.Cache;
1718
using OJS.Services.Ui.Business.Validations.Implementations.Contests;
1819
using OJS.Services.Ui.Data;
@@ -34,7 +35,8 @@ public class ContestsBusinessService(
3435
IContestParticipantsCacheService contestParticipantsCacheService,
3536
IContestsCacheService contestsCacheService,
3637
ILecturersInContestsCacheService lecturersInContestsCache,
37-
IContestDetailsValidationService contestDetailsValidationService)
38+
IContestDetailsValidationService contestDetailsValidationService,
39+
IDatesService datesService)
3840
: IContestsBusinessService
3941
{
4042
public async Task<ServiceResult<ContestDetailsServiceModel>> GetContestDetails(int id)
@@ -328,6 +330,8 @@ public async Task<ContestSearchServiceResultModel> GetSearchContestsByName(
328330
.MapCollection<ContestForListingServiceModel>()
329331
.ToPagedListAsync(model.PageNumber, model.ItemsPerPage);
330332

333+
this.SetContestVisibility(searchContests);
334+
331335
modelResult.Contests = searchContests;
332336
modelResult.TotalContestsCount = allContestsQueryable.Count();
333337

@@ -344,6 +348,8 @@ public async Task<PagedResult<ContestForListingServiceModel>> GetAllByFiltersAnd
344348
var pagedContests =
345349
await contestsData.GetAllAsPageByFiltersAndSorting<ContestForListingServiceModel>(model, includeHidden);
346350

351+
this.SetContestVisibility(pagedContests.Items);
352+
347353
var participantResultsByContest = new Dictionary<int, List<ParticipantResultServiceModel>>();
348354
if (user.IsAuthenticated)
349355
{
@@ -390,6 +396,8 @@ public async Task<PagedResult<ContestForListingServiceModel>> GetParticipatedByU
390396
participatedContests,
391397
sortAndFilterModel);
392398

399+
this.SetContestVisibility(participatedContestsInPage.Items);
400+
393401
var participantResultsByContest = new Dictionary<int, List<ParticipantResultServiceModel>>();
394402
var loggedInUser = userProviderService.GetCurrentUser();
395403

@@ -499,10 +507,16 @@ await pagedContests.Items.ForEachAsync(c =>
499507
.ToListAsync();
500508

501509
public async Task<IEnumerable<ContestForListingServiceModel>> GetAllParticipatedContests(string username)
502-
=> await contestsData
503-
.GetLatestForParticipantByUsername(username)
504-
.MapCollection<ContestForListingServiceModel>()
505-
.ToListAsync();
510+
{
511+
var contests = await contestsData
512+
.GetLatestForParticipantByUsername(username)
513+
.MapCollection<ContestForListingServiceModel>()
514+
.ToListAsync();
515+
516+
this.SetContestVisibility(contests);
517+
518+
return contests;
519+
}
506520

507521
private static async Task<Dictionary<int, List<ParticipantResultServiceModel>>> MapParticipationResultsToContestsInPage(
508522
IQueryable<Participant> participants)
@@ -565,4 +579,13 @@ private async Task<ContestFiltersServiceModel> GetNestedFilterCategoriesIfAny(Co
565579
official,
566580
isUserAdminOrLecturerInContest);
567581
}
582+
583+
private void SetContestVisibility(IEnumerable<ContestForListingServiceModel> contests)
584+
{
585+
var now = datesService.GetUtcNow();
586+
foreach (var contest in contests)
587+
{
588+
contest.IsVisible = contest.IsVisible || contest.VisibleFrom <= now;
589+
}
590+
}
568591
}

Services/UI/OJS.Services.Ui.Models/Contests/ContestForListingServiceModel.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ public void RegisterMappings(IProfileExpression configuration)
8484
.SelectMany(pg => pg.Problems)
8585
.Where(x => !x.IsDeleted)
8686
.Sum(pr => pr.MaximumPoints)))
87-
.ForMember(
88-
c => c.IsVisible,
89-
opt => opt.MapFrom(s => s.IsVisible || s.VisibleFrom <= DateTime.UtcNow))
9087
// For online contests:
9188
// In a problem group with multiple problems, compete points are derived from a single problem,
9289
// unlike practice mode where points can be accumulated from all problems across groups.

0 commit comments

Comments
 (0)