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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,6 @@ obj
/AdminUI/LearningHub.Nhs.AdminUI/LearningHub.Nhs.AdminUI.csproj.user
/WebAPI/LearningHub.Nhs.API/LearningHub.Nhs.Api.csproj.user
/ReportAPI/LearningHub.Nhs.ReportApi/web.config
/AdminUI/LearningHub.Nhs.AdminUI/web.config
/LearningHub.Nhs.WebUI/web.config
/WebAPI/LearningHub.Nhs.API/web.config
21 changes: 0 additions & 21 deletions AdminUI/LearningHub.Nhs.AdminUI/web.config

This file was deleted.

10 changes: 8 additions & 2 deletions LearningHub.Nhs.WebUI/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class HomeController : BaseController
private readonly IDashboardService dashboardService;
private readonly IContentService contentService;
private readonly IFeatureManager featureManager;
private readonly IUserGroupService userGroupService;
private readonly Microsoft.Extensions.Configuration.IConfiguration configuration;

/// <summary>
Expand All @@ -55,6 +56,7 @@ public class HomeController : BaseController
/// <param name="dashboardService">Dashboard service.</param>
/// <param name="contentService">Content service.</param>
/// <param name="featureManager"> featureManager.</param>
/// <param name="userGroupService"> userGroupService.</param>
/// <param name="configuration"> config.</param>
public HomeController(
IHttpClientFactory httpClientFactory,
Expand All @@ -67,6 +69,7 @@ public HomeController(
IDashboardService dashboardService,
IContentService contentService,
IFeatureManager featureManager,
IUserGroupService userGroupService,
Microsoft.Extensions.Configuration.IConfiguration configuration)
: base(hostingEnvironment, httpClientFactory, logger, settings.Value)
{
Expand All @@ -76,6 +79,7 @@ public HomeController(
this.dashboardService = dashboardService;
this.contentService = contentService;
this.featureManager = featureManager;
this.userGroupService = userGroupService;
this.configuration = configuration;
}

Expand Down Expand Up @@ -212,6 +216,7 @@ public async Task<IActionResult> Index(string myLearningDashboard = "my-in-progr
var learningTask = this.dashboardService.GetMyAccessLearningsAsync(myLearningDashboard, 1);
var resourcesTask = this.dashboardService.GetResourcesAsync(resourceDashboard, 1);
var cataloguesTask = this.dashboardService.GetCataloguesAsync(catalogueDashboard, 1);
var userGroupsTask = this.userGroupService.UserHasCatalogueContributionPermission();

var enrolledCoursesTask = Task.FromResult(new List<MoodleCourseResponseViewModel>());
var enableMoodle = Task.Run(() => this.featureManager.IsEnabledAsync(FeatureFlags.EnableMoodle)).Result;
Expand All @@ -222,7 +227,7 @@ public async Task<IActionResult> Index(string myLearningDashboard = "my-in-progr
enrolledCoursesTask = this.dashboardService.GetEnrolledCoursesFromMoodleAsync(this.CurrentMoodleUserId, 1);
}

await Task.WhenAll(learningTask, resourcesTask, cataloguesTask);
await Task.WhenAll(learningTask, resourcesTask, cataloguesTask, userGroupsTask);

var model = new DashboardViewModel()
{
Expand All @@ -231,7 +236,8 @@ public async Task<IActionResult> Index(string myLearningDashboard = "my-in-progr
Catalogues = await cataloguesTask,
EnrolledCourses = await enrolledCoursesTask,
};

var userHasContributePermission = await userGroupsTask;
this.ViewBag.userHasContributePermission = userHasContributePermission;
if (!string.IsNullOrEmpty(this.Request.Query["preview"]) && Convert.ToBoolean(this.Request.Query["preview"]))
{
return this.View("LandingPage", await this.GetLandingPageContent(Convert.ToBoolean(this.Request.Query["preview"])));
Expand Down
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
13 changes: 13 additions & 0 deletions LearningHub.Nhs.WebUI/Services/UserGroupService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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.WebUI.Interfaces;
Expand Down Expand Up @@ -56,6 +57,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.RoleEnum == RoleEnum.LocalAdmin || r.RoleEnum == RoleEnum.Editor))
{
return true;
}

return false;
}

/// <inheritdoc />
public async Task<bool> UserHasPermissionAsync(string permissionCode)
{
Expand Down
10 changes: 9 additions & 1 deletion LearningHub.Nhs.WebUI/Views/Home/Dashboard.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@
@{
ViewData["Title"] = "Learning Hub - Home";

var isReadOnly = User.IsInRole("ReadOnly") || User.IsInRole("BasicUser");
var isReadOnly = false;
if (User.IsInRole("ReadOnly") || User.IsInRole("BasicUser"))
{
isReadOnly = true;
}
else if (User.IsInRole("BlueUser") && !this.ViewBag.userHasContributePermission)
{
isReadOnly = true;
}
}

@section styles {
Expand Down
21 changes: 0 additions & 21 deletions LearningHub.Nhs.WebUI/web.config

This file was deleted.

21 changes: 0 additions & 21 deletions WebAPI/LearningHub.Nhs.API/web.config

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ public async Task<List<CatalogueNodeVersion>> GetPublishedCatalogues()
/// <returns>The <see cref="Task"/>.</returns>
public IQueryable<CatalogueNodeVersion> GetPublishedCataloguesForUserAsync(int userId)
{
var communityCatalogue = this.DbContext.CatalogueNodeVersion.AsNoTracking()
.Include(cnv => cnv.NodeVersion.Node)
.Where(cnv => cnv.NodeVersion.VersionStatusEnum == VersionStatusEnum.Published
&& cnv.NodeVersion.NodeId == 1 /* Community Catalogue */);

var cataloguesForUser = from cnv in this.DbContext.CatalogueNodeVersion.Include(cnv => cnv.NodeVersion.Node).AsNoTracking()
join nv in this.DbContext.NodeVersion.Where(cnv => cnv.VersionStatusEnum == VersionStatusEnum.Published && !cnv.Deleted) // .Include(nv => nv.Node)
on cnv.NodeVersionId equals nv.Id
Expand All @@ -99,7 +94,7 @@ join n in this.DbContext.Node.Where(x => !x.Deleted)
on nv.Id equals n.CurrentNodeVersionId
select cnv;

var returnedCatalogues = communityCatalogue.Union(cataloguesForUser).Distinct()
var returnedCatalogues = cataloguesForUser.Distinct()
.OrderBy(cnv => cnv.NodeVersion.NodeId != 1)
.ThenBy(cnv => cnv.Name);

Expand Down
Loading