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
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
5 changes: 3 additions & 2 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 @@ -45,7 +46,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 @@ -60,7 +61,7 @@ public async Task<List<RoleUserGroupViewModel>> GetRoleUserGroupDetailForUserAsy
public async Task<bool> UserHasCatalogueContributionPermission()
{
var userRoleGroups = await this.GetRoleUserGroupDetailAsync();
if (userRoleGroups != null && userRoleGroups.Any(r => r.RoleName == "Local Admin" || r.RoleName == "Editor"))
if (userRoleGroups != null && userRoleGroups.Any(r => r.RoleEnum == RoleEnum.LocalAdmin || r.RoleEnum == RoleEnum.Editor))
{
return true;
}
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
Loading