Skip to content

Commit 39ac467

Browse files
authored
Merge pull request #1188 from TechnologyEnhancedLearning/Develop/Feature/TD-5661-Removal-of-Community-Contribution-process
Develop/feature/td 5661 removal of community contribution process
2 parents e662e23 + 61475ca commit 39ac467

File tree

10 files changed

+49
-76
lines changed

10 files changed

+49
-76
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,6 @@ obj
5353
/AdminUI/LearningHub.Nhs.AdminUI/LearningHub.Nhs.AdminUI.csproj.user
5454
/WebAPI/LearningHub.Nhs.API/LearningHub.Nhs.Api.csproj.user
5555
/ReportAPI/LearningHub.Nhs.ReportApi/web.config
56+
/AdminUI/LearningHub.Nhs.AdminUI/web.config
57+
/LearningHub.Nhs.WebUI/web.config
58+
/WebAPI/LearningHub.Nhs.API/web.config

AdminUI/LearningHub.Nhs.AdminUI/web.config

Lines changed: 0 additions & 21 deletions
This file was deleted.

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/Interfaces/IUserGroupService.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ public interface IUserGroupService
2222
/// <returns>The <see cref="Task{List}"/>.</returns>
2323
Task<List<RoleUserGroupViewModel>> GetRoleUserGroupDetailForUserAsync(int userId);
2424

25+
/// <summary>
26+
/// The UserHasCatalogueContributionPermission.
27+
/// </summary>
28+
/// <returns>The <see cref="UserHasCatalogueContributionPermission"/>.</returns>
29+
Task<bool> UserHasCatalogueContributionPermission();
30+
2531
/// <summary>
2632
/// Check if user has given permission.
2733
/// </summary>

LearningHub.Nhs.WebUI/Services/NavigationPermissionService.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,19 @@
1111
public class NavigationPermissionService : INavigationPermissionService
1212
{
1313
private readonly IResourceService resourceService;
14+
private readonly IUserGroupService userGroupService;
1415

1516
/// <summary>
1617
/// Initializes a new instance of the <see cref="NavigationPermissionService"/> class.
1718
/// </summary>
1819
/// <param name="resourceService">Resource service.</param>
19-
public NavigationPermissionService(IResourceService resourceService)
20+
/// <param name="userGroupService">UserGroup service.</param>
21+
public NavigationPermissionService(
22+
IResourceService resourceService,
23+
IUserGroupService userGroupService)
2024
{
2125
this.resourceService = resourceService;
26+
this.userGroupService = userGroupService;
2227
}
2328

2429
/// <summary>
@@ -52,7 +57,7 @@ public async Task<NavigationModel> GetNavigationModelAsync(IPrincipal user, bool
5257
}
5358
else if (user.IsInRole("BlueUser"))
5459
{
55-
return this.AuthenticatedBlueUser(controllerName);
60+
return await this.AuthenticatedBlueUser(controllerName);
5661
}
5762
else
5863
{
@@ -114,11 +119,11 @@ private NavigationModel AuthenticatedAdministrator(string controllerName)
114119
/// </summary>
115120
/// <param name="controllerName">The controller name.</param>
116121
/// <returns>The <see cref="NavigationModel"/>.</returns>
117-
private NavigationModel AuthenticatedBlueUser(string controllerName)
122+
private async Task<NavigationModel> AuthenticatedBlueUser(string controllerName)
118123
{
119124
return new NavigationModel()
120125
{
121-
ShowMyContributions = true,
126+
ShowMyContributions = await this.userGroupService.UserHasCatalogueContributionPermission(),
122127
ShowMyLearning = true,
123128
ShowMyBookmarks = true,
124129
ShowSearch = controllerName != "search" && controllerName != string.Empty,

LearningHub.Nhs.WebUI/Services/UserGroupService.cs

Lines changed: 13 additions & 0 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;
@@ -56,6 +57,18 @@ public async Task<List<RoleUserGroupViewModel>> GetRoleUserGroupDetailForUserAsy
5657
return await this.cacheService.GetOrFetchAsync(cacheKey, () => this.FetchRoleUserGroupDetailForUserAsync(userId));
5758
}
5859

60+
/// <inheritdoc />
61+
public async Task<bool> UserHasCatalogueContributionPermission()
62+
{
63+
var userRoleGroups = await this.GetRoleUserGroupDetailAsync();
64+
if (userRoleGroups != null && userRoleGroups.Any(r => r.RoleEnum == RoleEnum.LocalAdmin || r.RoleEnum == RoleEnum.Editor))
65+
{
66+
return true;
67+
}
68+
69+
return false;
70+
}
71+
5972
/// <inheritdoc />
6073
public async Task<bool> UserHasPermissionAsync(string permissionCode)
6174
{

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 {

LearningHub.Nhs.WebUI/web.config

Lines changed: 0 additions & 21 deletions
This file was deleted.

WebAPI/LearningHub.Nhs.API/web.config

Lines changed: 0 additions & 21 deletions
This file was deleted.

WebAPI/LearningHub.Nhs.Repository/Hierarchy/CatalogueNodeVersionRepository.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,6 @@ public async Task<List<CatalogueNodeVersion>> GetPublishedCatalogues()
8181
/// <returns>The <see cref="Task"/>.</returns>
8282
public IQueryable<CatalogueNodeVersion> GetPublishedCataloguesForUserAsync(int userId)
8383
{
84-
var communityCatalogue = this.DbContext.CatalogueNodeVersion.AsNoTracking()
85-
.Include(cnv => cnv.NodeVersion.Node)
86-
.Where(cnv => cnv.NodeVersion.VersionStatusEnum == VersionStatusEnum.Published
87-
&& cnv.NodeVersion.NodeId == 1 /* Community Catalogue */);
88-
8984
var cataloguesForUser = from cnv in this.DbContext.CatalogueNodeVersion.Include(cnv => cnv.NodeVersion.Node).AsNoTracking()
9085
join nv in this.DbContext.NodeVersion.Where(cnv => cnv.VersionStatusEnum == VersionStatusEnum.Published && !cnv.Deleted) // .Include(nv => nv.Node)
9186
on cnv.NodeVersionId equals nv.Id
@@ -99,7 +94,7 @@ join n in this.DbContext.Node.Where(x => !x.Deleted)
9994
on nv.Id equals n.CurrentNodeVersionId
10095
select cnv;
10196

102-
var returnedCatalogues = communityCatalogue.Union(cataloguesForUser).Distinct()
97+
var returnedCatalogues = cataloguesForUser.Distinct()
10398
.OrderBy(cnv => cnv.NodeVersion.NodeId != 1)
10499
.ThenBy(cnv => cnv.Name);
105100

0 commit comments

Comments
 (0)