From e5c77d5f90efa399e632dd53988b73cf416d0a61 Mon Sep 17 00:00:00 2001 From: Jared McCannon Date: Fri, 13 Sep 2024 12:03:53 -0500 Subject: [PATCH] PM 12001 - Fix Empty User Search 500 (#4770) * Setting null if user2Fa is empty. Added null check to view as well. * Not setting the temp data at all if empty. --- src/Admin/Controllers/UsersController.cs | 7 ++++++- src/Admin/Views/Users/Index.cshtml | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Admin/Controllers/UsersController.cs b/src/Admin/Controllers/UsersController.cs index a3620d968..e233b61e4 100644 --- a/src/Admin/Controllers/UsersController.cs +++ b/src/Admin/Controllers/UsersController.cs @@ -66,7 +66,12 @@ public class UsersController : Controller if (_featureService.IsEnabled(FeatureFlagKeys.MembersTwoFAQueryOptimization)) { - TempData["UsersTwoFactorIsEnabled"] = await _twoFactorIsEnabledQuery.TwoFactorIsEnabledAsync(users.Select(u => u.Id)); + var user2Fa = (await _twoFactorIsEnabledQuery.TwoFactorIsEnabledAsync(users.Select(u => u.Id))).ToList(); + // TempDataSerializer is having an issue serializing an empty IEnumerable>, do not set if empty. + if (user2Fa.Count != 0) + { + TempData["UsersTwoFactorIsEnabled"] = user2Fa; + } } return View(new UsersModel diff --git a/src/Admin/Views/Users/Index.cshtml b/src/Admin/Views/Users/Index.cshtml index 7f941a819..46419503f 100644 --- a/src/Admin/Views/Users/Index.cshtml +++ b/src/Admin/Views/Users/Index.cshtml @@ -73,7 +73,9 @@ @if (featureService.IsEnabled(Bit.Core.FeatureFlagKeys.MembersTwoFAQueryOptimization)) { var usersTwoFactorIsEnabled = TempData["UsersTwoFactorIsEnabled"] as IEnumerable<(Guid userId, bool twoFactorIsEnabled)>; - @if(usersTwoFactorIsEnabled.FirstOrDefault(tuple => tuple.userId == user.Id).twoFactorIsEnabled) + var matchingUser2Fa = usersTwoFactorIsEnabled?.FirstOrDefault(tuple => tuple.userId == user.Id); + + @if(matchingUser2Fa is { twoFactorIsEnabled: true }) { }