Skip to content

Commit 3d71f78

Browse files
Merge pull request #1172 from TechnologyEnhancedLearning/Develop/Fixes/TD-5665-Adding-resources-to-the-community-catalogue-is-suspended
TD-5665-Adding resources to the community catalogue is suspended
2 parents 1a86b09 + 7d8e96e commit 3d71f78

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

LearningHub.Nhs.WebUI/Interfaces/IUserGroupService.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ public interface IUserGroupService
2222
/// <returns>The <see cref="Task{List}"/>.</returns>
2323
Task<List<RoleUserGroupViewModel>> GetRoleUserGroupDetailForUserAsync(int userId);
2424

25+
/// <summary>
26+
/// The UserHasCatalogueContributionPermission.
27+
/// </summary>
28+
/// <returns>The <see cref="UserHasCatalogueContributionPermission"/>.</returns>
29+
Task<bool> UserHasCatalogueContributionPermission();
30+
2531
/// <summary>
2632
/// Check if user has given permission.
2733
/// </summary>

LearningHub.Nhs.WebUI/Services/NavigationPermissionService.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,19 @@
1111
public class NavigationPermissionService : INavigationPermissionService
1212
{
1313
private readonly IResourceService resourceService;
14+
private readonly IUserGroupService userGroupService;
1415

1516
/// <summary>
1617
/// Initializes a new instance of the <see cref="NavigationPermissionService"/> class.
1718
/// </summary>
1819
/// <param name="resourceService">Resource service.</param>
19-
public NavigationPermissionService(IResourceService resourceService)
20+
/// <param name="userGroupService">UserGroup service.</param>
21+
public NavigationPermissionService(
22+
IResourceService resourceService,
23+
IUserGroupService userGroupService)
2024
{
2125
this.resourceService = resourceService;
26+
this.userGroupService = userGroupService;
2227
}
2328

2429
/// <summary>
@@ -52,7 +57,7 @@ public async Task<NavigationModel> GetNavigationModelAsync(IPrincipal user, bool
5257
}
5358
else if (user.IsInRole("BlueUser"))
5459
{
55-
return this.AuthenticatedBlueUser(controllerName);
60+
return await this.AuthenticatedBlueUser(controllerName);
5661
}
5762
else
5863
{
@@ -114,11 +119,11 @@ private NavigationModel AuthenticatedAdministrator(string controllerName)
114119
/// </summary>
115120
/// <param name="controllerName">The controller name.</param>
116121
/// <returns>The <see cref="NavigationModel"/>.</returns>
117-
private NavigationModel AuthenticatedBlueUser(string controllerName)
122+
private async Task<NavigationModel> AuthenticatedBlueUser(string controllerName)
118123
{
119124
return new NavigationModel()
120125
{
121-
ShowMyContributions = true,
126+
ShowMyContributions = await this.userGroupService.UserHasCatalogueContributionPermission(),
122127
ShowMyLearning = true,
123128
ShowMyBookmarks = true,
124129
ShowSearch = controllerName != "search" && controllerName != string.Empty,

LearningHub.Nhs.WebUI/Services/UserGroupService.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public UserGroupService(
4545
/// <inheritdoc />
4646
public async Task<List<RoleUserGroupViewModel>> GetRoleUserGroupDetailAsync()
4747
{
48-
var cacheKey = $"{this.contextAccessor.HttpContext.User.Identity.GetCurrentUserId()}:AllRolesWithPermissions";
48+
var cacheKey = $"{this.contextAccessor.HttpContext.User.Identity.GetCurrentUserId()}:AllRolesWithPermissions";
4949
return await this.cacheService.GetOrFetchAsync(cacheKey, () => this.FetchRoleUserGroupDetailAsync());
5050
}
5151

@@ -56,6 +56,18 @@ public async Task<List<RoleUserGroupViewModel>> GetRoleUserGroupDetailForUserAsy
5656
return await this.cacheService.GetOrFetchAsync(cacheKey, () => this.FetchRoleUserGroupDetailForUserAsync(userId));
5757
}
5858

59+
/// <inheritdoc />
60+
public async Task<bool> UserHasCatalogueContributionPermission()
61+
{
62+
var userRoleGroups = await this.GetRoleUserGroupDetailAsync();
63+
if (userRoleGroups != null && userRoleGroups.Any(r => r.RoleName == "Local Admin" || r.RoleName == "Editor"))
64+
{
65+
return true;
66+
}
67+
68+
return false;
69+
}
70+
5971
/// <inheritdoc />
6072
public async Task<bool> UserHasPermissionAsync(string permissionCode)
6173
{

0 commit comments

Comments
 (0)