Skip to content

Commit 61475ca

Browse files
Merge pull request #1185 from TechnologyEnhancedLearning/Develop/Fixes/TD-5663-Post-log-in-dashboard---remove-banner-promoting-contribute-a-resource
TD-5663: Post log in dashboard - remove banner promoting contribute a…
2 parents 4aafc75 + 4e1d065 commit 61475ca

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

LearningHub.Nhs.WebUI/Controllers/HomeController.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class HomeController : BaseController
4040
private readonly IDashboardService dashboardService;
4141
private readonly IContentService contentService;
4242
private readonly IFeatureManager featureManager;
43+
private readonly IUserGroupService userGroupService;
4344
private readonly Microsoft.Extensions.Configuration.IConfiguration configuration;
4445

4546
/// <summary>
@@ -55,6 +56,7 @@ public class HomeController : BaseController
5556
/// <param name="dashboardService">Dashboard service.</param>
5657
/// <param name="contentService">Content service.</param>
5758
/// <param name="featureManager"> featureManager.</param>
59+
/// <param name="userGroupService"> userGroupService.</param>
5860
/// <param name="configuration"> config.</param>
5961
public HomeController(
6062
IHttpClientFactory httpClientFactory,
@@ -67,6 +69,7 @@ public HomeController(
6769
IDashboardService dashboardService,
6870
IContentService contentService,
6971
IFeatureManager featureManager,
72+
IUserGroupService userGroupService,
7073
Microsoft.Extensions.Configuration.IConfiguration configuration)
7174
: base(hostingEnvironment, httpClientFactory, logger, settings.Value)
7275
{
@@ -76,6 +79,7 @@ public HomeController(
7679
this.dashboardService = dashboardService;
7780
this.contentService = contentService;
7881
this.featureManager = featureManager;
82+
this.userGroupService = userGroupService;
7983
this.configuration = configuration;
8084
}
8185

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

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

225-
await Task.WhenAll(learningTask, resourcesTask, cataloguesTask);
230+
await Task.WhenAll(learningTask, resourcesTask, cataloguesTask, userGroupsTask);
226231

227232
var model = new DashboardViewModel()
228233
{
@@ -231,7 +236,8 @@ public async Task<IActionResult> Index(string myLearningDashboard = "my-in-progr
231236
Catalogues = await cataloguesTask,
232237
EnrolledCourses = await enrolledCoursesTask,
233238
};
234-
239+
var userHasContributePermission = await userGroupsTask;
240+
this.ViewBag.userHasContributePermission = userHasContributePermission;
235241
if (!string.IsNullOrEmpty(this.Request.Query["preview"]) && Convert.ToBoolean(this.Request.Query["preview"]))
236242
{
237243
return this.View("LandingPage", await this.GetLandingPageContent(Convert.ToBoolean(this.Request.Query["preview"])));

LearningHub.Nhs.WebUI/Services/UserGroupService.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Linq;
66
using System.Threading.Tasks;
77
using LearningHub.Nhs.Caching;
8+
using LearningHub.Nhs.Models.Enums;
89
using LearningHub.Nhs.Models.Extensions;
910
using LearningHub.Nhs.Models.User;
1011
using LearningHub.Nhs.WebUI.Interfaces;
@@ -45,7 +46,7 @@ public UserGroupService(
4546
/// <inheritdoc />
4647
public async Task<List<RoleUserGroupViewModel>> GetRoleUserGroupDetailAsync()
4748
{
48-
var cacheKey = $"{this.contextAccessor.HttpContext.User.Identity.GetCurrentUserId()}:AllRolesWithPermissions";
49+
var cacheKey = $"{this.contextAccessor.HttpContext.User.Identity.GetCurrentUserId()}:AllRolesWithPermissions";
4950
return await this.cacheService.GetOrFetchAsync(cacheKey, () => this.FetchRoleUserGroupDetailAsync());
5051
}
5152

@@ -60,7 +61,7 @@ public async Task<List<RoleUserGroupViewModel>> GetRoleUserGroupDetailForUserAsy
6061
public async Task<bool> UserHasCatalogueContributionPermission()
6162
{
6263
var userRoleGroups = await this.GetRoleUserGroupDetailAsync();
63-
if (userRoleGroups != null && userRoleGroups.Any(r => r.RoleName == "Local Admin" || r.RoleName == "Editor"))
64+
if (userRoleGroups != null && userRoleGroups.Any(r => r.RoleEnum == RoleEnum.LocalAdmin || r.RoleEnum == RoleEnum.Editor))
6465
{
6566
return true;
6667
}

LearningHub.Nhs.WebUI/Views/Home/Dashboard.cshtml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@
55
@{
66
ViewData["Title"] = "Learning Hub - Home";
77

8-
var isReadOnly = User.IsInRole("ReadOnly") || User.IsInRole("BasicUser");
8+
var isReadOnly = false;
9+
if (User.IsInRole("ReadOnly") || User.IsInRole("BasicUser"))
10+
{
11+
isReadOnly = true;
12+
}
13+
else if (User.IsInRole("BlueUser") && !this.ViewBag.userHasContributePermission)
14+
{
15+
isReadOnly = true;
16+
}
917
}
1018

1119
@section styles {

0 commit comments

Comments
 (0)