Skip to content

Commit 8865177

Browse files
CFODEV-1505: Prevent user from being able to change enrolment location (#926)
* CFODEV-1505: Prevent user from being able to change enrolment location after consent has been granted. * Update src/Server.UI/Pages/Participants/Components/ParticipantActionMenu.razor Co-authored-by: Carl Sixsmith <carl.sixsmith1@justice.gov.uk> --------- Co-authored-by: Carl Sixsmith <carl.sixsmith1@justice.gov.uk>
1 parent 5f45311 commit 8865177

4 files changed

Lines changed: 29 additions & 28 deletions

File tree

src/Application/Features/Participants/Commands/ChangeEnrolmentLocation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private async Task<bool> BeChangeable(string participantId, CancellationToken ca
9393
.IgnoreAutoIncludes()
9494
.FirstAsync(x => x.Id == participantId, cancellationToken);
9595

96-
return participant.EnrolmentStatus!.AllowEnrolmentLocationChange();
96+
return participant.EnrolmentStatus!.AllowEnrolmentLocationChange() && participant.ConsentStatus!.AllowEnrolmentLocationChange();
9797
}
9898
}
9999
}

src/Domain/Common/Enums/ConsentStatus.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,25 @@
22

33
namespace Cfo.Cats.Domain.Common.Enums;
44

5-
public class ConsentStatus : SmartEnum<ConsentStatus>
5+
public abstract class ConsentStatus : SmartEnum<ConsentStatus>
66
{
7-
public static readonly ConsentStatus PendingStatus = new("Pending", 0);
8-
public static readonly ConsentStatus GrantedStatus = new("Granted", 1);
9-
10-
private ConsentStatus(string name, int value) : base(name, value)
7+
public static readonly ConsentStatus PendingStatus = new Pending();
8+
public static readonly ConsentStatus GrantedStatus = new Granted();
9+
10+
private ConsentStatus(string name, int value)
11+
: base(name, value)
1112
{
1213
}
14+
15+
public virtual bool AllowEnrolmentLocationChange() => false;
16+
17+
private sealed class Pending() : ConsentStatus("Pending", 0)
18+
{
19+
public override bool AllowEnrolmentLocationChange() => true;
20+
}
21+
22+
private sealed class Granted() : ConsentStatus("Granted", 1)
23+
{
24+
public override bool AllowEnrolmentLocationChange() => false;
25+
}
1326
}

src/Server.UI/Pages/Participants/Components/AdjustEnrolmentLocationDialog.razor

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
@inject IValidationService Validator
88

9-
109
<MudDialog>
1110
<DialogContent>
1211
<MudForm Model="@Command" @ref="_form" Validation="@(Validator.ValidateValue(Command))">
@@ -29,8 +28,7 @@
2928
<MudItem xs="12">
3029
<MudTextField @bind-Value="Command.JustificationReason" Label="Justification Reason"
3130
Lines="5" Class="mt-4" MaxLength="@ValidationConstants.NotesLength"
32-
Immediate="true" oninput="UpdateCharacterCount" Required="true"/>
33-
<MudText Class="ml-2">Characters: @characterCount / 1000</MudText>
31+
Immediate="true" Counter=@ValidationConstants.NotesLength Required="true"/>
3432
</MudItem>
3533
</MudForm>
3634

@@ -52,21 +50,21 @@
5250

5351
@code {
5452
private MudForm? _form;
55-
private bool _saving = false;
53+
private bool _saving;
5654

57-
[Inject] public ILocationService LocationService { get; set; } = default!;
55+
[Inject] public ILocationService LocationService { get; set; } = null!;
5856

5957
[CascadingParameter]
60-
private IMudDialogInstance MudDialog { get; set; } = default!;
58+
private IMudDialogInstance MudDialog { get; set; } = null!;
6159

62-
[Parameter] public UserProfile UserProfile { get; set; } = default!;
60+
[Parameter] public UserProfile UserProfile { get; set; } = null!;
6361

6462
[Parameter] public string? ParticipantId { get; set; }
6563
[Parameter] public string? JustificationReason { get; set; }
6664

6765
public LocationDto[] Locations { get; set; } = [];
6866

69-
private ChangeEnrolmentLocation.Command Command { get; set; } = new();
67+
private ChangeEnrolmentLocation.Command Command { get; } = new();
7068

7169
private void Cancel()
7270
{
@@ -81,9 +79,7 @@
8179
.ToArray();
8280

8381
Command.CurrentUser = UserProfile;
84-
Command.ParticipantId = ParticipantId;
85-
Command.JustificationReason = JustificationReason;
86-
82+
Command.ParticipantId = ParticipantId;
8783
}
8884

8985
private async Task Submit()
@@ -115,13 +111,5 @@
115111
{
116112
_saving = false;
117113
}
118-
}
119-
120-
private int characterCount => Command.JustificationReason?.Length ?? 0;
121-
122-
private void UpdateCharacterCount(ChangeEventArgs args)
123-
{
124-
Command.JustificationReason = args?.Value?.ToString() ?? string.Empty;
125-
}
126-
114+
}
127115
}

src/Server.UI/Pages/Participants/Components/ParticipantActionMenu.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<MudMenuItem Icon="@Icons.Material.Filled.Approval" IconColor="Color.Primary" OnClick="OpenConsentDialog">@ConstantString.AddConsent</MudMenuItem>
3737
}
3838

39-
@if (Participant.EnrolmentStatus.AllowEnrolmentLocationChange())
39+
@if (Participant.EnrolmentStatus.AllowEnrolmentLocationChange() && Participant.ConsentStatus.AllowEnrolmentLocationChange())
4040
{
4141
<MudMenuItem Icon="@Icons.Material.Filled.Map" IconColor="Color.Primary" OnClick="OpenAdjustLocationDialog">
4242
@ConstantString.ChangeEnrolmentLocation
@@ -227,7 +227,7 @@
227227

228228
var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.Medium, FullWidth = true };
229229

230-
var dialog = await DialogService.ShowAsync<AdjustEnrolmentLocationDialog>("Change Enrolment Location", parameters, options);
230+
var dialog = await DialogService.ShowAsync<AdjustEnrolmentLocationDialog>(@ConstantString.ChangeEnrolmentLocation, parameters, options);
231231
var state = await dialog.Result;
232232

233233
if (state!.Canceled == false)

0 commit comments

Comments
 (0)