Skip to content

Commit

Permalink
VIH-10361 Fix for unable to update judge last minute (#1318)
Browse files Browse the repository at this point in the history
* Fix for unable to update judge last minute

* Use test url

* More code coverage

* Fix error saving hearing close to start time when panel member is present

* Fix test

* Revert test config

* Update nuget package
  • Loading branch information
oliver-scott authored Dec 15, 2023
1 parent ed89c32 commit 9185120
Show file tree
Hide file tree
Showing 10 changed files with 368 additions and 36 deletions.
6 changes: 3 additions & 3 deletions AdminWebsite/AdminWebsite.IntegrationTests/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@
},
"BookingsApi.Client": {
"type": "Transitive",
"resolved": "1.49.15",
"contentHash": "ye+s7y4jeNSgVd7sgbRee0dnx4HZIegmBxYlWHENPNv5u8zSH15dENPmLX8BODkUKOLpwHiIxQyRMh8KKzlcFQ==",
"resolved": "1.50.6",
"contentHash": "Ns9rPj4+jc2XpR3XSNHUMk+ZVbbmjhcXaBt1eHeQTtnBBkkSMTfbwK5kUJ4xrXhiwEjg32h6Njq5b3Y9L8Kd2w==",
"dependencies": {
"Microsoft.AspNetCore.Mvc.Core": "2.2.5"
}
Expand Down Expand Up @@ -2101,7 +2101,7 @@
"type": "Project",
"dependencies": {
"AspNetCore.HealthChecks.Uris": "[6.0.3, )",
"BookingsApi.Client": "[1.49.15, )",
"BookingsApi.Client": "[1.50.6, )",
"FluentValidation.AspNetCore": "[10.4.0, )",
"LaunchDarkly.ServerSdk": "[7.0.3, )",
"MicroElements.Swashbuckle.FluentValidation": "[5.7.0, )",
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -293,13 +293,9 @@ private HearingDetailsResponse InitHearing()
.With(x => x.Id = Guid.NewGuid())
.With(x => x.UserRoleName = "Staff Member")
.Build();
var telephoneParticipant = Builder<TelephoneParticipantResponse>.CreateNew()
.With(x => x.Id = Guid.NewGuid())
.Build();

return Builder<HearingDetailsResponse>.CreateNew()
.With(h => h.Participants = new List<ParticipantResponse> { rep, ind, joh, judge, staffMember })
.With(h => h.TelephoneParticipants = new List<TelephoneParticipantResponse> { telephoneParticipant })
.With(x => x.Cases = cases)
.With(x => x.Id = Guid.NewGuid())
.Build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using AdminWebsite.Contracts.Requests;

namespace AdminWebsite.UnitTests.Validators
{
Expand Down Expand Up @@ -47,6 +48,17 @@ public void Should_validate_participants_as_valid()
var result = _validator.Validate(testRequest);
Assert.That(!result.Errors.Any(o => o.PropertyName == "Participants"));
}

[Test]
public void Should_validate_participants_as_valid_when_judiciary_participants_are_provided()
{
var testRequest = new EditHearingRequest {
JudiciaryParticipants = new List<JudiciaryParticipantRequest> { new() },
Case = new EditCaseRequest(),
};
var result = _validator.Validate(testRequest);
Assert.That(!result.Errors.Any(o => o.PropertyName == "Participants"));
}

[Test]
public void Should_validate_scheduled_date_time_as_error_when_time_is_thirty_minutes_or_more()
Expand Down
6 changes: 3 additions & 3 deletions AdminWebsite/AdminWebsite.UnitTests/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@
},
"BookingsApi.Client": {
"type": "Transitive",
"resolved": "1.49.15",
"contentHash": "ye+s7y4jeNSgVd7sgbRee0dnx4HZIegmBxYlWHENPNv5u8zSH15dENPmLX8BODkUKOLpwHiIxQyRMh8KKzlcFQ==",
"resolved": "1.50.6",
"contentHash": "Ns9rPj4+jc2XpR3XSNHUMk+ZVbbmjhcXaBt1eHeQTtnBBkkSMTfbwK5kUJ4xrXhiwEjg32h6Njq5b3Y9L8Kd2w==",
"dependencies": {
"Microsoft.AspNetCore.Mvc.Core": "2.2.5"
}
Expand Down Expand Up @@ -1979,7 +1979,7 @@
"type": "Project",
"dependencies": {
"AspNetCore.HealthChecks.Uris": "[6.0.3, )",
"BookingsApi.Client": "[1.49.15, )",
"BookingsApi.Client": "[1.50.6, )",
"FluentValidation.AspNetCore": "[10.4.0, )",
"LaunchDarkly.ServerSdk": "[7.0.3, )",
"MicroElements.Swashbuckle.FluentValidation": "[5.7.0, )",
Expand Down
2 changes: 1 addition & 1 deletion AdminWebsite/AdminWebsite/AdminWebsite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.Uris" Version="6.0.3" />
<PackageReference Include="BookingsApi.Client" Version="1.49.15" />
<PackageReference Include="BookingsApi.Client" Version="1.50.6" />
<PackageReference Include="LaunchDarkly.ServerSdk" Version="7.0.3" />
<PackageReference Include="MicroElements.Swashbuckle.FluentValidation" Version="5.7.0" />
<PackageReference Include="Microsoft.Identity.Client" Version="4.51.0" />
Expand Down
40 changes: 38 additions & 2 deletions AdminWebsite/AdminWebsite/Controllers/HearingsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,10 @@ private async Task UpdateParticipantsV2(Guid hearingId, EditHearingRequest reque

var linkedParticipants = ExtractLinkedParticipants(request, originalHearing, removedParticipantIds, new List<IUpdateParticipantRequest>(existingParticipants), new List<IParticipantRequest>(newParticipants));
var linkedParticipantsV2 = linkedParticipants.Select(lp => lp.MapToV2()).ToList();

if (request.Participants != null && request.Participants.Any())
await _hearingsService.ProcessParticipantsV2(hearingId, existingParticipants, newParticipants, removedParticipantIds.ToList(), linkedParticipantsV2);

await _hearingsService.ProcessParticipantsV2(hearingId, existingParticipants, newParticipants, removedParticipantIds.ToList(), linkedParticipantsV2);
await _hearingsService.ProcessEndpoints(hearingId, request, originalHearing, new List<IParticipantRequest>(newParticipants));
}

Expand All @@ -410,11 +412,29 @@ private static List<Guid> GetRemovedParticipantIds(EditHearingRequest request, H
private async Task UpdateJudiciaryParticipants(Guid hearingId, EditHearingRequest request,
HearingDetailsResponse originalHearing)
{
// Due to booking api's domain restrictions for removing participants, we have to update judges differently
var oldJudge = originalHearing.JudiciaryParticipants.Find(ojp => ojp.RoleCode == "Judge");
var newJudge = request.JudiciaryParticipants.Find(njp => njp.Role == "Judge");
if (oldJudge?.PersonalCode != newJudge?.PersonalCode && newJudge != null)
{
await _bookingsApiClient.ReassignJudiciaryJudgeAsync(hearingId, new ReassignJudiciaryJudgeRequest
{
DisplayName = newJudge.DisplayName,
PersonalCode = newJudge.PersonalCode
});
}

// keep the order of removal first. this will allow admin web to change judiciary judges post booking
var removedJohs = originalHearing.JudiciaryParticipants.Where(ojp =>
request.JudiciaryParticipants.TrueForAll(jp => jp.PersonalCode != ojp.PersonalCode)).ToList();
foreach (var removedJoh in removedJohs)
{
if (removedJoh.RoleCode == "Judge")
{
// Judges are re-assigned instead of removed or added
continue;
}

await _bookingsApiClient.RemoveJudiciaryParticipantFromHearingAsync(hearingId, removedJoh.PersonalCode);
}

Expand All @@ -433,7 +453,15 @@ private async Task UpdateJudiciaryParticipants(Guid hearingId, EditHearingReques
}).ToList();
if (newJohRequest.Any())
{
await _bookingsApiClient.AddJudiciaryParticipantsToHearingAsync(hearingId, newJohRequest);
// Judges are re-assigned instead of removed or added
var johsToAdd = newJohRequest
.Where(x => x.HearingRoleCode != JudiciaryParticipantHearingRoleCode.Judge)
.ToList();

if (johsToAdd.Any())
{
await _bookingsApiClient.AddJudiciaryParticipantsToHearingAsync(hearingId, johsToAdd);
}
}

// get existing judiciary participants based on the personal code being present in the original hearing
Expand All @@ -442,6 +470,14 @@ private async Task UpdateJudiciaryParticipants(Guid hearingId, EditHearingReques

foreach (var joh in existingJohs)
{
// Only update the joh if their details have changed
var originalJoh = originalHearing.JudiciaryParticipants.Find(x => x.PersonalCode == joh.PersonalCode);
if (joh.DisplayName == originalJoh.DisplayName &&
joh.Role == originalJoh.RoleCode)
{
continue;
}

var roleCode = Enum.Parse<JudiciaryParticipantHearingRoleCode>(joh.Role);
await _bookingsApiClient.UpdateJudiciaryParticipantAsync(hearingId, joh.PersonalCode,
new UpdateJudiciaryParticipantRequest()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Linq;
using AdminWebsite.Contracts.Responses;
using V1 = BookingsApi.Contract.V1.Responses;
Expand All @@ -23,9 +24,7 @@ public static HearingDetailsResponse Map(this V1.HearingDetailsResponse hearingD
Number = e.Number
}).ToList(),
Participants = hearingDetails.Participants?.Map(),
TelephoneParticipants = hearingDetails.TelephoneParticipants?
.Select(t => t.Map())
.ToList(),
TelephoneParticipants = new List<TelephoneParticipantResponse>(),
HearingRoomName = hearingDetails.HearingRoomName,
OtherInformation = hearingDetails.OtherInformation,
CreatedDate = hearingDetails.CreatedDate,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using AdminWebsite.Models;
using AdminWebsite.Models;
using FluentValidation;

namespace AdminWebsite.Validators
Expand All @@ -19,6 +18,7 @@ public EditHearingRequestValidator()

RuleFor(x => x.Participants)
.Must(x => x != null && x.Count > 0)
.When(x => x.JudiciaryParticipants == null || x.JudiciaryParticipants.Count == 0)
.WithMessage(PARTICIPANT_MSG);

RuleForEach(x => x.Participants).NotNull().SetValidator(new EditParticipantRequestValidation());
Expand Down
6 changes: 3 additions & 3 deletions AdminWebsite/AdminWebsite/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
},
"BookingsApi.Client": {
"type": "Direct",
"requested": "[1.49.15, )",
"resolved": "1.49.15",
"contentHash": "ye+s7y4jeNSgVd7sgbRee0dnx4HZIegmBxYlWHENPNv5u8zSH15dENPmLX8BODkUKOLpwHiIxQyRMh8KKzlcFQ==",
"requested": "[1.50.6, )",
"resolved": "1.50.6",
"contentHash": "Ns9rPj4+jc2XpR3XSNHUMk+ZVbbmjhcXaBt1eHeQTtnBBkkSMTfbwK5kUJ4xrXhiwEjg32h6Njq5b3Y9L8Kd2w==",
"dependencies": {
"Microsoft.AspNetCore.Mvc.Core": "2.2.5"
}
Expand Down

0 comments on commit 9185120

Please sign in to comment.