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
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace LearningHub.Nhs.OpenApi.Services.Interface.Services
{
using System.Threading.Tasks;

/// <summary>
/// The UserGroupService interface.
/// </summary>
public interface IUserGroupService
{
/// <summary>
/// The GetRoleUserGroupDetailAsync.
/// </summary>
/// <returns>The <see cref="Task{List}"/>.</returns>
Task<bool> UserHasCatalogueContributionPermission(int userId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@
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 @@ -53,7 +56,7 @@ public async Task<NavigationModel> GetNavigationModelAsync(IPrincipal user, bool
}
else if (user.IsInRole("BlueUser"))
{
return AuthenticatedBlueUser(controllerName);
return await AuthenticatedBlueUser(controllerName, user.Identity.GetCurrentUserId());
}
else
{
Expand Down Expand Up @@ -114,12 +117,13 @@ private NavigationModel AuthenticatedAdministrator(string controllerName)
/// The AuthenticatedBlueUser.
/// </summary>
/// <param name="controllerName">The controller name.</param>
/// <param name="userId">The userId.</param>
/// <returns>The <see cref="NavigationModel"/>.</returns>
private NavigationModel AuthenticatedBlueUser(string controllerName)
private async Task<NavigationModel> AuthenticatedBlueUser(string controllerName, int userId)
{
return new NavigationModel()
{
ShowMyContributions = true,
ShowMyContributions = await this.userGroupService.UserHasCatalogueContributionPermission(userId),
ShowMyLearning = true,
ShowMyBookmarks = true,
ShowSearch = controllerName != "search" && controllerName != string.Empty,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
namespace LearningHub.Nhs.OpenApi.Services.Services
{
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using LearningHub.Nhs.Caching;
using LearningHub.Nhs.Models.Enums;
using LearningHub.Nhs.Models.Extensions;
using LearningHub.Nhs.Models.User;
using LearningHub.Nhs.OpenApi.Repositories.Interface.Repositories;
using LearningHub.Nhs.OpenApi.Services.Interface.Services;
using Microsoft.AspNetCore.Http;

/// <summary>
/// The user group service.
/// </summary>
public class UserGroupService : IUserGroupService
{

private readonly IRoleUserGroupRepository roleUserGroupRepository;

/// <summary>
/// Initializes a new instance of the <see cref="UserGroupService"/> class.
/// </summary>
/// <param name="roleUserGroupRepository">roleUserGroupRepository.</param>
public UserGroupService(IRoleUserGroupRepository roleUserGroupRepository)
{
this.roleUserGroupRepository = roleUserGroupRepository;
}


/// <inheritdoc />
public async Task<bool> UserHasCatalogueContributionPermission(int userId)
{
var userRoleGroups = await this.roleUserGroupRepository.GetRoleUserGroupViewModelsByUserId(userId);
if (userRoleGroups != null && userRoleGroups.Any(r => r.RoleEnum == RoleEnum.LocalAdmin || r.RoleEnum == RoleEnum.Editor))
{
return true;
}

return false;
}

}
}
1 change: 1 addition & 0 deletions OpenAPI/LearningHub.Nhs.OpenApi.Services/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public static void AddServices(this IServiceCollection services)
services.AddScoped<INavigationPermissionService, NavigationPermissionService>();
services.AddScoped<INotificationService, NotificationService>();
services.AddScoped<IUserNotificationService, UserNotificationService>();
services.AddScoped<IUserGroupService, UserGroupService>();

services.AddScoped<IActivityService, ActivityService>();
services.AddScoped<IFileTypeService, FileTypeService>();
Expand Down
Loading