Skip to content

Commit 98b2f79

Browse files
feat: Add VerifyAssignment action and corresponding UI for map rotation verification
1 parent ca451d7 commit 98b2f79

5 files changed

Lines changed: 68 additions & 2 deletions

File tree

src/XtremeIdiots.Portal.Web/Controllers/MapRotationsController.cs

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,48 @@ public async Task<IActionResult> DeactivateAssignment(Guid assignmentId, Guid ma
703703
}, nameof(DeactivateAssignment)).ConfigureAwait(false);
704704
}
705705

706+
[HttpPost]
707+
[ValidateAntiForgeryToken]
708+
public async Task<IActionResult> VerifyAssignment(Guid assignmentId, Guid mapRotationId, CancellationToken cancellationToken = default)
709+
{
710+
return await ExecuteWithErrorHandlingAsync(async () =>
711+
{
712+
var rotationResponse = await repositoryApiClient.MapRotations.V1.GetMapRotation(mapRotationId, cancellationToken).ConfigureAwait(false);
713+
714+
if (rotationResponse.IsNotFound || rotationResponse.Result?.Data is null)
715+
return NotFound();
716+
717+
var rotation = rotationResponse.Result.Data;
718+
719+
var authResult = await CheckAuthorizationAsync(
720+
authorizationService,
721+
rotation.GameType,
722+
AuthPolicies.ManageMapRotations,
723+
nameof(VerifyAssignment),
724+
"MapRotation").ConfigureAwait(false);
725+
726+
if (authResult != null)
727+
return authResult;
728+
729+
if (rotation.ServerAssignments == null || !rotation.ServerAssignments.Any(a => a.MapRotationServerAssignmentId == assignmentId))
730+
return BadRequest("The specified assignment does not belong to this rotation.");
731+
732+
var result = await syncApiClient.TriggerVerify(assignmentId, cancellationToken).ConfigureAwait(false);
733+
734+
if (result.Success)
735+
{
736+
this.AddAlertSuccess("Verification triggered successfully.");
737+
TempData["PendingInstanceId"] = $"maprot-verify-{assignmentId}";
738+
}
739+
else
740+
{
741+
this.AddAlertDanger($"Failed to trigger verification: {result.Error}");
742+
}
743+
744+
return RedirectToAction(nameof(AssignmentStatus), new { id = assignmentId });
745+
}, nameof(VerifyAssignment)).ConfigureAwait(false);
746+
}
747+
706748
[HttpGet]
707749
public async Task<IActionResult> GetSyncProgress(string instanceId, CancellationToken cancellationToken = default)
708750
{
@@ -768,7 +810,8 @@ public async Task<IActionResult> CancelOperation(Guid operationId, Guid assignme
768810
$"maprot-sync-{assignmentId}",
769811
$"maprot-activate-{assignmentId}",
770812
$"maprot-deactivate-{assignmentId}",
771-
$"maprot-remove-{assignmentId}"
813+
$"maprot-remove-{assignmentId}",
814+
$"maprot-verify-{assignmentId}"
772815
};
773816

774817
if (allowedPrefixes.Any(p => string.Equals(instanceId, p, StringComparison.OrdinalIgnoreCase)))
@@ -822,7 +865,8 @@ public async Task<IActionResult> TerminateOrchestration(string instanceId, Guid
822865
$"maprot-sync-{assignmentId}",
823866
$"maprot-activate-{assignmentId}",
824867
$"maprot-deactivate-{assignmentId}",
825-
$"maprot-remove-{assignmentId}"
868+
$"maprot-remove-{assignmentId}",
869+
$"maprot-verify-{assignmentId}"
826870
};
827871

828872
if (!allowedPrefixes.Any(p => string.Equals(instanceId, p, StringComparison.OrdinalIgnoreCase)))

src/XtremeIdiots.Portal.Web/Services/ISyncApiClient.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ public interface ISyncApiClient
66
Task<SyncTriggerResult> TriggerActivate(Guid assignmentId, CancellationToken cancellationToken = default);
77
Task<SyncTriggerResult> TriggerDeactivate(Guid assignmentId, CancellationToken cancellationToken = default);
88
Task<SyncTriggerResult> TriggerRemove(Guid assignmentId, CancellationToken cancellationToken = default);
9+
Task<SyncTriggerResult> TriggerVerify(Guid assignmentId, CancellationToken cancellationToken = default);
910
Task<OrchestrationStatusQueryResult> GetOrchestrationStatus(string instanceId, CancellationToken cancellationToken = default);
1011
Task<SyncTriggerResult> TerminateOrchestration(string instanceId, CancellationToken cancellationToken = default);
1112
}

src/XtremeIdiots.Portal.Web/Services/NoOpSyncApiClient.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public Task<SyncTriggerResult> TriggerRemove(Guid assignmentId, CancellationToke
2222
return Task.FromResult(new SyncTriggerResult(false, Error: "Sync API not configured"));
2323
}
2424

25+
public Task<SyncTriggerResult> TriggerVerify(Guid assignmentId, CancellationToken cancellationToken = default)
26+
{
27+
return Task.FromResult(new SyncTriggerResult(false, Error: "Sync API not configured"));
28+
}
29+
2530
public Task<OrchestrationStatusQueryResult> GetOrchestrationStatus(string instanceId, CancellationToken cancellationToken = default)
2631
{
2732
return Task.FromResult(new OrchestrationStatusQueryResult(OrchestrationStatusQueryOutcome.Error));

src/XtremeIdiots.Portal.Web/Services/SyncApiClient.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ public Task<SyncTriggerResult> TriggerRemove(Guid assignmentId, CancellationToke
3131
return TriggerOrchestration($"/api/map-rotations/remove/{assignmentId}", cancellationToken);
3232
}
3333

34+
public Task<SyncTriggerResult> TriggerVerify(Guid assignmentId, CancellationToken cancellationToken = default)
35+
{
36+
return TriggerOrchestration($"/api/map-rotations/verify/{assignmentId}", cancellationToken);
37+
}
38+
3439
public async Task<OrchestrationStatusQueryResult> GetOrchestrationStatus(string instanceId, CancellationToken cancellationToken = default)
3540
{
3641
try

src/XtremeIdiots.Portal.Web/Views/MapRotations/AssignmentStatus.cshtml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,17 @@
137137
</button>
138138
</form>
139139
}
140+
@if (Model.Assignment.DeploymentState == DeploymentState.Synced)
141+
{
142+
<form policy="@AuthPolicies.ManageMapRotations" asp-action="VerifyAssignment" method="post" class="d-inline">
143+
@Html.AntiForgeryToken()
144+
<input type="hidden" name="assignmentId" value="@Model.Assignment.MapRotationServerAssignmentId" />
145+
<input type="hidden" name="mapRotationId" value="@Model.Rotation.MapRotationId" />
146+
<button type="submit" class="btn btn-outline-info btn-sm me-1">
147+
<i class="fa-solid fa-clipboard-check"></i> Verify Maps
148+
</button>
149+
</form>
150+
}
140151
</div>
141152
</div>
142153
</div>

0 commit comments

Comments
 (0)