From a60d2451009e0e7c6c5df877e334443581e4d267 Mon Sep 17 00:00:00 2001 From: James Gunn Date: Mon, 4 Nov 2024 17:10:51 +0000 Subject: [PATCH] Allow updating users with no roles (#1646) --- .../Pages/Users/EditUser.cshtml.cs | 5 ----- .../PageTests/Users/EditUserTests.cs | 22 ------------------- 2 files changed, 27 deletions(-) diff --git a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Users/EditUser.cshtml.cs b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Users/EditUser.cshtml.cs index 02ed19810..201031e6f 100644 --- a/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Users/EditUser.cshtml.cs +++ b/TeachingRecordSystem/src/TeachingRecordSystem.SupportUi/Pages/Users/EditUser.cshtml.cs @@ -67,11 +67,6 @@ public async Task OnPost() // Sanitize roles var newRoles = Roles!.Where(r => UserRoles.All.Contains(r)).ToArray(); - if (Roles?.Length == 0) - { - ModelState.AddModelError(nameof(Roles), "Select at least one role"); - } - if (!ModelState.IsValid) { return this.PageWithErrors(); diff --git a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Users/EditUserTests.cs b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Users/EditUserTests.cs index 4bd63e31b..806c872e6 100644 --- a/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Users/EditUserTests.cs +++ b/TeachingRecordSystem/tests/TeachingRecordSystem.SupportUi.Tests/PageTests/Users/EditUserTests.cs @@ -184,28 +184,6 @@ public async Task Post_NoName_RendersError() await AssertEx.HtmlResponseHasError(response, "Name", "Enter a name"); } - [Fact] - public async Task Post_NoRolesSelected_RendersError() - { - // Arrange - var user = await TestData.CreateUser(); - var newName = Faker.Name.FullName(); - - var request = new HttpRequestMessage(HttpMethod.Post, GetRequestPath(user.UserId)) - { - Content = new FormUrlEncodedContentBuilder() - { - { "Name", newName }, - } - }; - - // Act - var response = await HttpClient.SendAsync(request); - - // Assert - await AssertEx.HtmlResponseHasError(response, "Roles", "Select at least one role"); - } - [Theory] [InlineData(true, false, true, UserUpdatedEventChanges.Name)] [InlineData(false, true, true, UserUpdatedEventChanges.Roles)]