diff --git a/dotnet-authserver/src/TeacherIdentity.AuthServer/Pages/Admin/MergeUser/SelectUser.cshtml.cs b/dotnet-authserver/src/TeacherIdentity.AuthServer/Pages/Admin/MergeUser/SelectUser.cshtml.cs
index 7d624c863..9300bf896 100644
--- a/dotnet-authserver/src/TeacherIdentity.AuthServer/Pages/Admin/MergeUser/SelectUser.cshtml.cs
+++ b/dotnet-authserver/src/TeacherIdentity.AuthServer/Pages/Admin/MergeUser/SelectUser.cshtml.cs
@@ -18,11 +18,9 @@ public Merge(TeacherIdentityServerDbContext dbContext)
_dbContext = dbContext;
}
- public ICollection? UserIds { get; set; }
-
[BindProperty]
- [Display(Name = "Select which user to merge")]
- [Required(ErrorMessage = "Select which user you want to merge")]
+ [Display(Name = "Enter the user ID to merge")]
+ [Required(ErrorMessage = "Enter the user ID to merge")]
public Guid? UserIdToMerge { get; set; }
[FromRoute]
@@ -34,14 +32,17 @@ public void OnGet()
public IActionResult OnPost()
{
- if (!ModelState.IsValid)
+ if (!UserIdToMerge.HasValue)
{
- return this.PageWithErrors();
+ ModelState.AddModelError(nameof(UserIdToMerge), "Enter the user ID of the user to merge.");
+ }
+ else if (UserIdToMerge.Value == UserId)
+ {
+ ModelState.AddModelError(nameof(UserIdToMerge), "User cannot be merged with itself.");
}
- if (UserIds == null || !UserIds.Contains((Guid)UserIdToMerge!))
+ if (!ModelState.IsValid)
{
- ModelState.AddModelError(nameof(UserIdToMerge), "You must select a user ID from the given list");
return this.PageWithErrors();
}
@@ -58,11 +59,6 @@ public override async Task OnPageHandlerExecutionAsync(PageHandlerExecutingConte
return;
}
- UserIds = _dbContext.Users
- .Where(u => u.UserId != UserId && u.UserType == UserType.Default)
- .Select(u => u.UserId)
- .ToArray();
-
await next();
}
}
diff --git a/dotnet-authserver/tests/TeacherIdentity.AuthServer.Tests/EndpointTests/Admin/MergeUser/SelectUserTests.cs b/dotnet-authserver/tests/TeacherIdentity.AuthServer.Tests/EndpointTests/Admin/MergeUser/SelectUserTests.cs
index 6920ea884..1a84e491b 100644
--- a/dotnet-authserver/tests/TeacherIdentity.AuthServer.Tests/EndpointTests/Admin/MergeUser/SelectUserTests.cs
+++ b/dotnet-authserver/tests/TeacherIdentity.AuthServer.Tests/EndpointTests/Admin/MergeUser/SelectUserTests.cs
@@ -97,7 +97,7 @@ public async Task Post_EmptyUserIdToMerge_ReturnsError()
var response = await HttpClient.SendAsync(request);
// Assert
- await AssertEx.HtmlResponseHasError(response, "UserIdToMerge", "Select which user you want to merge");
+ await AssertEx.HtmlResponseHasError(response, "UserIdToMerge", "Enter the user ID to merge");
}
[Fact]
@@ -105,13 +105,13 @@ public async Task Post_InvalidUserIdToMerge_ReturnsError()
{
// Arrange
var user = await TestData.CreateUser(userType: UserType.Default, hasTrn: false);
- var invalidUserToMerge = await TestData.CreateUser(userType: UserType.Staff, hasTrn: false);
+ var invalidUserToMergeId = user.UserId;
var request = new HttpRequestMessage(HttpMethod.Post, $"/admin/users/{user.UserId}/merge")
{
Content = new FormUrlEncodedContentBuilder()
{
- { "UserIdToMerge", invalidUserToMerge.UserId }
+ { "UserIdToMerge", invalidUserToMergeId }
}
};
@@ -119,7 +119,7 @@ public async Task Post_InvalidUserIdToMerge_ReturnsError()
var response = await HttpClient.SendAsync(request);
// Assert
- await AssertEx.HtmlResponseHasError(response, "UserIdToMerge", "You must select a user ID from the given list");
+ await AssertEx.HtmlResponseHasError(response, "UserIdToMerge", "User cannot be merged with itself.");
}
[Fact]