Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions LearningHub.Nhs.WebUI/Interfaces/IUserGroupService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ public interface IUserGroupService
/// <returns>The <see cref="Task{List}"/>.</returns>
Task<List<RoleUserGroupViewModel>> GetRoleUserGroupDetailForUserAsync(int userId);

/// <summary>
/// The UserHasCatalogueContributionPermission.
/// </summary>
/// <returns>The <see cref="UserHasCatalogueContributionPermission"/>.</returns>
Task<bool> UserHasCatalogueContributionPermission();

/// <summary>
/// Check if user has given permission.
/// </summary>
Expand Down
13 changes: 9 additions & 4 deletions LearningHub.Nhs.WebUI/Services/NavigationPermissionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@
public class NavigationPermissionService : INavigationPermissionService
{
private readonly IResourceService resourceService;
private readonly IUserGroupService userGroupService;

/// <summary>
/// Initializes a new instance of the <see cref="NavigationPermissionService"/> class.
/// </summary>
/// <param name="resourceService">Resource service.</param>
public NavigationPermissionService(IResourceService resourceService)
/// <param name="userGroupService">UserGroup service.</param>
public NavigationPermissionService(
IResourceService resourceService,
IUserGroupService userGroupService)
{
this.resourceService = resourceService;
this.userGroupService = userGroupService;
}

/// <summary>
Expand Down Expand Up @@ -52,7 +57,7 @@ public async Task<NavigationModel> GetNavigationModelAsync(IPrincipal user, bool
}
else if (user.IsInRole("BlueUser"))
{
return this.AuthenticatedBlueUser(controllerName);
return await this.AuthenticatedBlueUser(controllerName);
}
else
{
Expand Down Expand Up @@ -114,11 +119,11 @@ private NavigationModel AuthenticatedAdministrator(string controllerName)
/// </summary>
/// <param name="controllerName">The controller name.</param>
/// <returns>The <see cref="NavigationModel"/>.</returns>
private NavigationModel AuthenticatedBlueUser(string controllerName)
private async Task<NavigationModel> AuthenticatedBlueUser(string controllerName)
{
return new NavigationModel()
{
ShowMyContributions = true,
ShowMyContributions = await this.userGroupService.UserHasCatalogueContributionPermission(),
ShowMyLearning = true,
ShowMyBookmarks = true,
ShowSearch = controllerName != "search" && controllerName != string.Empty,
Expand Down
14 changes: 13 additions & 1 deletion LearningHub.Nhs.WebUI/Services/UserGroupService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public UserGroupService(
/// <inheritdoc />
public async Task<List<RoleUserGroupViewModel>> GetRoleUserGroupDetailAsync()
{
var cacheKey = $"{this.contextAccessor.HttpContext.User.Identity.GetCurrentUserId()}:AllRolesWithPermissions";
var cacheKey = $"{this.contextAccessor.HttpContext.User.Identity.GetCurrentUserId()}:AllRolesWithPermissions";
return await this.cacheService.GetOrFetchAsync(cacheKey, () => this.FetchRoleUserGroupDetailAsync());
}

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

/// <inheritdoc />
public async Task<bool> UserHasCatalogueContributionPermission()
{
var userRoleGroups = await this.GetRoleUserGroupDetailAsync();
if (userRoleGroups != null && userRoleGroups.Any(r => r.RoleName == "Local Admin" || r.RoleName == "Editor"))
{
return true;
}

return false;
}

/// <inheritdoc />
public async Task<bool> UserHasPermissionAsync(string permissionCode)
{
Expand Down
Loading