Skip to content

Commit 6f96106

Browse files
Merge pull request #1315 from TechnologyEnhancedLearning/Develop/Feature-Revised-My-Learning-implementation
Develop/feature revised my learning implementation
2 parents 6d96638 + e43d930 commit 6f96106

94 files changed

Lines changed: 3843 additions & 2054 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AdminUI/LearningHub.Nhs.AdminUI/LearningHub.Nhs.AdminUI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
<PackageReference Include="HtmlSanitizer" Version="6.0.453" />
9090
<PackageReference Include="IdentityModel" Version="4.6.0" />
9191
<PackageReference Include="LearningHub.Nhs.Caching" Version="2.0.2" />
92-
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.48" />
92+
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.52" />
9393
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.19.0" />
9494
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.0.36" />
9595
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.36" />

LearningHub.Nhs.WebUI.AutomatedUiTests/LearningHub.Nhs.WebUI.AutomatedUiTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
<ItemGroup>
1414
<PackageReference Include="FluentAssertions" Version="6.12.0" />
15+
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.52" />
1516
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="3.1.13" />
1617
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
1718
<PackageReference Include="Selenium.Axe" Version="4.0.19" />
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
namespace LearningHub.Nhs.WebUI.Configuration
2+
{
3+
/// <summary>
4+
/// The Moodle Settings.
5+
/// </summary>
6+
public class MoodleApiConfig
7+
{
8+
/// <summary>
9+
/// Gets or sets the base url for the Moodle service.
10+
/// </summary>
11+
public string BaseUrl { get; set; } = null!;
12+
13+
/// <summary>
14+
/// Gets or sets the Web service Rest Format.
15+
/// </summary>
16+
public string MoodleWSRestFormat { get; set; } = null!;
17+
18+
/// <summary>
19+
/// Gets or sets the token.
20+
/// </summary>
21+
public string WSToken { get; set; } = null!;
22+
23+
/// <summary>
24+
/// Gets or sets the token.
25+
/// </summary>
26+
public string ApiPath { get; set; } = "webservice/rest/server.php";
27+
28+
/// <summary>
29+
/// Gets or sets the token.
30+
/// </summary>
31+
public string CoursePath { get; set; } = "course/view.php";
32+
}
33+
}

LearningHub.Nhs.WebUI/Controllers/Api/MyLearningController.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,34 @@ public async Task<ActionResult> GetActivityDetailed([FromBody] MyLearningRequest
4444
return this.Ok(activity);
4545
}
4646

47+
/// <summary>
48+
/// Gets the detailed activity data.
49+
/// </summary>
50+
/// <param name="requestModel">The request model - filter settings.</param>
51+
/// <returns>The <see cref="Task"/>.</returns>
52+
[HttpPost]
53+
[Route("GetUserRecentMyLearningActivities")]
54+
public async Task<ActionResult> GetUserRecentMyLearningActivities([FromBody] MyLearningRequestModel requestModel)
55+
{
56+
var activity = await this.myLearningService.GetUserRecentMyLearningActivities(requestModel);
57+
58+
return this.Ok(activity);
59+
}
60+
61+
/// <summary>
62+
/// Gets the detailed activity data.
63+
/// </summary>
64+
/// <param name="requestModel">The request model - filter settings.</param>
65+
/// <returns>The <see cref="Task"/>.</returns>
66+
[HttpPost]
67+
[Route("GetUserLearningHistory")]
68+
public async Task<ActionResult> GetUserLearningHistory([FromBody] MyLearningRequestModel requestModel)
69+
{
70+
var activity = await this.myLearningService.GetUserLearningHistory(requestModel);
71+
72+
return this.Ok(activity);
73+
}
74+
4775
/// <summary>
4876
/// Gets the played segment data for the progress modal in My Learning screen.
4977
/// </summary>

LearningHub.Nhs.WebUI/Controllers/ContributeController.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public class ContributeController : BaseController
2828
private readonly IFileService fileService;
2929
private readonly IResourceService resourceService;
3030
private readonly IUserService userService;
31+
private readonly IUserGroupService userGroupService;
3132

3233
/// <summary>
3334
/// Initializes a new instance of the <see cref="ContributeController"/> class.
@@ -37,6 +38,7 @@ public class ContributeController : BaseController
3738
/// <param name="logger">Logger.</param>
3839
/// <param name="settings">Settings.</param>
3940
/// <param name="userService">User service.</param>
41+
/// <param name="userGroupService"> userGroupService.</param>
4042
/// <param name="fileService">File service.</param>
4143
/// <param name="resourceService">Resource service.</param>
4244
/// <param name="azureMediaService">Azure media service.</param>
@@ -48,6 +50,7 @@ public ContributeController(
4850
ILogger<ContributeController> logger,
4951
IOptions<Settings> settings,
5052
IUserService userService,
53+
IUserGroupService userGroupService,
5154
IFileService fileService,
5255
IResourceService resourceService,
5356
IAzureMediaService azureMediaService,
@@ -58,6 +61,7 @@ public ContributeController(
5861
this.authConfig = authConfig;
5962

6063
this.userService = userService;
64+
this.userGroupService = userGroupService;
6165
this.fileService = fileService;
6266
this.resourceService = resourceService;
6367
this.azureMediaService = azureMediaService;
@@ -167,7 +171,8 @@ public async Task<IActionResult> CreateVersion(int resourceId)
167171
[Route("my-contributions/{selectedTab}/{catalogueId}/{nodeId}")]
168172
public async Task<IActionResult> MyContributions()
169173
{
170-
if ((this.User.IsInRole("ReadOnly") || this.User.IsInRole("BasicUser")) && !await this.resourceService.UserHasPublishedResourcesAsync())
174+
bool catalogueContributionPermission = await this.userGroupService.UserHasCatalogueContributionPermission();
175+
if ((this.User.IsInRole("ReadOnly") || this.User.IsInRole("BasicUser")) || (!catalogueContributionPermission && (!await this.resourceService.UserHasPublishedResourcesAsync())))
171176
{
172177
return this.RedirectToAction("AccessDenied", "Home");
173178
}

LearningHub.Nhs.WebUI/Controllers/HomeController.cs

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace LearningHub.Nhs.WebUI.Controllers
1111
using LearningHub.Nhs.Models.Content;
1212
using LearningHub.Nhs.Models.Enums.Content;
1313
using LearningHub.Nhs.Models.Extensions;
14+
using LearningHub.Nhs.Models.Moodle.API;
1415
using LearningHub.Nhs.WebUI.Configuration;
1516
using LearningHub.Nhs.WebUI.Filters;
1617
using LearningHub.Nhs.WebUI.Helpers;
@@ -218,13 +219,12 @@ public async Task<IActionResult> Index(string myLearningDashboard = "my-in-progr
218219
var cataloguesTask = this.dashboardService.GetCataloguesAsync(catalogueDashboard, 1);
219220
var userGroupsTask = this.userGroupService.UserHasCatalogueContributionPermission();
220221

221-
var enrolledCoursesTask = Task.FromResult(new List<MoodleCourseResponseViewModel>());
222-
var enableMoodle = Task.Run(() => this.featureManager.IsEnabledAsync(FeatureFlags.EnableMoodle)).Result;
223-
this.ViewBag.EnableMoodle = enableMoodle;
224-
this.ViewBag.ValidMoodleUser = this.CurrentMoodleUserId > 0;
222+
var enrolledCoursesTask = Task.FromResult(new List<MoodleCourseResponseModel>());
223+
(bool enableMoodle, int currentMoodleUserId) = await this.GetMoodleFeatureStateAsync();
224+
225225
if (enableMoodle && myLearningDashboard == "my-enrolled-courses")
226226
{
227-
enrolledCoursesTask = this.dashboardService.GetEnrolledCoursesFromMoodleAsync(this.CurrentMoodleUserId, 1);
227+
enrolledCoursesTask = this.dashboardService.GetEnrolledCoursesFromMoodleAsync(currentMoodleUserId, 1);
228228
}
229229

230230
await Task.WhenAll(learningTask, resourcesTask, cataloguesTask, userGroupsTask);
@@ -280,9 +280,7 @@ public async Task<IActionResult> LoadPage(string dashBoardTray = "my-learning",
280280
Catalogues = new Nhs.Models.Dashboard.DashboardCatalogueResponseViewModel { Type = catalogueDashBoard },
281281
};
282282

283-
var enableMoodle = Task.Run(() => this.featureManager.IsEnabledAsync(FeatureFlags.EnableMoodle)).Result;
284-
this.ViewBag.EnableMoodle = enableMoodle;
285-
this.ViewBag.ValidMoodleUser = this.CurrentMoodleUserId > 0;
283+
(bool enableMoodle, int currentMoodleUserId) = await this.GetMoodleFeatureStateAsync();
286284

287285
bool isAjax = this.HttpContext.Request.Headers["X-Requested-With"] == "XMLHttpRequest";
288286

@@ -449,5 +447,28 @@ private async Task<LandingPageViewModel> GetLandingPageContent(bool preview = fa
449447
return new LandingPageViewModel { PageSectionDetailViewModels = new List<PageSectionDetailViewModel>(), PageViewModel = new PageViewModel { PageSections = new List<PageSectionViewModel> { } } };
450448
}
451449
}
450+
451+
/// <summary>
452+
/// Asynchronously retrieves the state of the Moodle feature and the current Moodle user ID.
453+
/// </summary>
454+
/// <remarks>The method checks if the Moodle feature is enabled and retrieves the current Moodle
455+
/// user ID. If the user ID is not already set, it attempts to obtain it asynchronously from the dashboard
456+
/// service.</remarks>
457+
/// <returns>A tuple containing a boolean indicating whether the Moodle feature is enabled and an integer representing
458+
/// the current Moodle user ID.</returns>
459+
private async Task<(bool enableMoodle, int currentMoodleUserId)> GetMoodleFeatureStateAsync()
460+
{
461+
var enableMoodle = Task.Run(() => this.featureManager.IsEnabledAsync(FeatureFlags.EnableMoodle)).Result;
462+
this.ViewBag.EnableMoodle = enableMoodle;
463+
int currentMoodleUserId = this.CurrentMoodleUserId;
464+
465+
if (currentMoodleUserId == 0)
466+
{
467+
currentMoodleUserId = await this.dashboardService.GetMoodleUserIdAsync(this.CurrentUserId);
468+
}
469+
470+
this.ViewBag.ValidMoodleUser = currentMoodleUserId > 0;
471+
return (enableMoodle, currentMoodleUserId);
472+
}
452473
}
453474
}

0 commit comments

Comments
 (0)