Skip to content

Commit c562c91

Browse files
committed
Sonar qube
1 parent 4babcf3 commit c562c91

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

application/CohortManager/src/Functions/Shared/Common/Authentication/PermissionsMiddleware.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,15 @@ public async Task Invoke(FunctionContext context, FunctionExecutionDelegate next
4646
}
4747

4848
var req = await context.GetHttpRequestDataAsync();
49+
50+
if(req == null)
51+
{
52+
throw new InvalidOperationException("HttpRequestData is required for permissions check but was not found in the context.");
53+
}
54+
4955
var user = (Cis2User)context.Items["Cis2User"]!;
50-
if (requiredRoles.Length == 0 || requiredRoles.Any(role => _roleManager.ValidateRole(user, role)))
56+
57+
if (requiredRoles.Any(role => _roleManager.ValidateRole(user, role)))
5158
{
5259
await next(context);
5360
return;

application/CohortManager/src/Functions/Shared/Common/Authentication/RoleManager.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ namespace Common;
66
public class RoleManager : IRoleManager
77
{
88
private readonly Dictionary<string, Role> _roleMappings;
9-
private readonly IOptions<RoleConfig> _roleConfig;
9+
1010

1111
public RoleManager(IOptions<RoleConfig> roleConfig)
1212
{
13-
_roleConfig = roleConfig;
1413
_roleMappings = new Dictionary<string, Role>
1514
{
16-
{ _roleConfig.Value.CohortManagerUserWorkgroupId, Role.CohortManagerUser },
17-
{ _roleConfig.Value.CohortManagerDummyGpRemovalWorkgroupId, Role.CohortManagerDummyGpRemoval }
15+
{ roleConfig.Value.CohortManagerUserWorkgroupId, Role.CohortManagerUser },
16+
{ roleConfig.Value.CohortManagerDummyGpRemovalWorkgroupId, Role.CohortManagerDummyGpRemoval }
1817
};
1918
}
2019
public bool ValidateRole(Cis2User user, Role role)
@@ -25,7 +24,7 @@ public bool ValidateRole(Cis2User user, Role role)
2524
{
2625
return false;
2726
}
28-
return user.NhsidNrbacRoles.Count(x => x.WorkgroupsCodes.Contains(workgroupId)) > 0;
27+
return user.NhsidNrbacRoles.Any(x => x.WorkgroupsCodes.Contains(workgroupId));
2928
}
3029

3130
}

0 commit comments

Comments
 (0)