Skip to content

Commit 694ecd4

Browse files
Fixes the results of the code-quality-bot's review
1 parent fed2a98 commit 694ecd4

3 files changed

Lines changed: 27 additions & 12 deletions

File tree

web/Areas/Directory/Controllers/DirectoryController.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ public async Task<ActionResult<IEnumerable<NavMenuItem>>> Nav()
5858
[HttpGet("search")]
5959
public async Task<ActionResult<IEnumerable<IndividualSearchResult>>> GetFromQuery([FromQuery] string search, [FromQuery] bool ucd = false)
6060
{
61+
if (!ModelState.IsValid)
62+
{
63+
return BadRequest(ModelState);
64+
}
6165
if (string.IsNullOrWhiteSpace(search))
6266
{
6367
return Ok(new List<IndividualSearchResult>());
@@ -104,11 +108,7 @@ public async Task<ActionResult<IEnumerable<IndividualSearchResult>>> Get(string
104108
results.Add(result);
105109

106110
var vmsearch = VMACSService.Search(result.LoginId);
107-
var vm = vmsearch.Result;
108-
if (vm != null && vm.item != null && vm.item.Nextel != null) result.Nextel = vm.item.Nextel[0];
109-
if (vm != null && vm.item != null && vm.item.LDPager != null) result.LDPager = vm.item.LDPager[0];
110-
if (vm != null && vm.item != null && vm.item.Unit != null) result.Department = vm.item.Unit[0];
111-
111+
PopulateVmacsDetails(result, vmsearch.Result);
112112
});
113113
return results;
114114
}
@@ -149,10 +149,7 @@ public async Task<ActionResult<IEnumerable<IndividualSearchResult>>> GetUCD(stri
149149
results.Add(result);
150150

151151
var vmsearch = VMACSService.Search(result.LoginId);
152-
var vm = vmsearch.Result;
153-
if (vm != null && vm.item != null && vm.item.Nextel != null) result.Nextel = vm.item.Nextel[0];
154-
if (vm != null && vm.item != null && vm.item.LDPager != null) result.LDPager = vm.item.LDPager[0];
155-
if (vm != null && vm.item != null && vm.item.Unit != null) result.Department = vm.item.Unit[0];
152+
PopulateVmacsDetails(result, vmsearch.Result);
156153
}
157154

158155
return results;
@@ -169,6 +166,17 @@ public async Task<IActionResult> DirectoryResult(string mothraID)
169166
return await Task.Run(() => View("~/Areas/Directory/Views/UserInfo.cshtml"));
170167
}
171168

169+
private static void PopulateVmacsDetails(IndividualSearchResult result, VMACSQuery? vm)
170+
{
171+
if (vm?.item != null)
172+
{
173+
if (vm.item.Nextel != null) result.Nextel = vm.item.Nextel[0];
174+
if (vm.item.LDPager != null) result.LDPager = vm.item.LDPager[0];
175+
if (vm.item.Unit != null) result.Department = vm.item.Unit[0];
176+
}
177+
}
178+
179+
[NonAction]
172180
public override async Task OnActionExecutionAsync(ActionExecutingContext context,
173181
ActionExecutionDelegate next)
174182
{

web/Areas/Directory/Controllers/UserInfoController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public async Task<ActionResult> UserInfo(string? mothraID)
7878
{
7979
// Check if user is viewing their own page
8080
var currentUser = _userHelper.GetCurrentUser();
81-
bool ownPage = mothraID == currentUser.MothraId;
81+
bool ownPage = currentUser != null && mothraID == currentUser.MothraId;
8282
var individual = await _aaud.AaudUsers.Where(u => (u.MothraId == mothraID)).FirstOrDefaultAsync();
8383
string? iamId = null;
8484
if (individual != null) iamId = individual.IamId;
@@ -142,6 +142,7 @@ public async Task<ActionResult<IEnumerable<NavMenuItem>>> Nav()
142142
return await Task.Run(() => nav);
143143
}
144144

145+
[NonAction]
145146
public override async Task OnActionExecutionAsync(ActionExecutingContext context,
146147
ActionExecutionDelegate next)
147148
{

web/Areas/Directory/Services/UserInfoService.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ public UserInfoService(
9292
await PopulateIDCardsAsync(result);
9393
await PopulateKeysAsync(result);
9494
await PopulateLoansAsync(result);
95-
await PopulateInstinctInfoAsync(result, individual);
95+
if (individual != null)
96+
{
97+
await PopulateInstinctInfoAsync(result, individual);
98+
}
9699
await PopulateActiveDirectoryInfoAsync(result);
97100

98101
return result;
@@ -1791,7 +1794,10 @@ private async Task<InstinctResult> GetInstinctUserAsync(string lastName, string
17911794
result.PasswordExpiresAt = matchedUser.PasswordExpiresAt;
17921795
result.Status = matchedUser.Status;
17931796
result.Username = matchedUser.Username;
1794-
result.Roles = matchedUser.Roles?.Select(r => r.Label).ToList() ?? new List<string>();
1797+
result.Roles = matchedUser.Roles?
1798+
.Where(r => r.Label != null)
1799+
.Select(r => r.Label!)
1800+
.ToList() ?? new List<string>();
17951801
foundMatch = true;
17961802
}
17971803
if (!foundMatch)

0 commit comments

Comments
 (0)