Skip to content

Commit

Permalink
PM 12001 - Fix Empty User Search 500 (#4770)
Browse files Browse the repository at this point in the history
* Setting null if user2Fa is empty. Added null check to view as well.

* Not setting the temp data at all if empty.
  • Loading branch information
jrmccannon committed Sep 13, 2024
1 parent 22a712b commit 897be7e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/Admin/Controllers/UsersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ public async Task<IActionResult> Index(string email, int page = 1, int count = 2

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<Tuple<T1,T2>>, do not set if empty.
if (user2Fa.Count != 0)
{
TempData["UsersTwoFactorIsEnabled"] = user2Fa;
}
}

return View(new UsersModel
Expand Down
4 changes: 3 additions & 1 deletion src/Admin/Views/Users/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
{
<i class="fa fa-lock fa-lg fa-fw" title="2FA Enabled"></i>
}
Expand Down

0 comments on commit 897be7e

Please sign in to comment.