Skip to content

Commit c58cfe7

Browse files
committed
Configure OpenID Connect authentication using the Moodle user ID, retrieve the currently logged-in user ID, and display enrolled courses on the Learning Hub dashboard.
1 parent 1db59a2 commit c58cfe7

18 files changed

+653
-5
lines changed

LearningHub.Nhs.WebUI/Controllers/BaseController.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Net.Http;
44
using LearningHub.Nhs.Models.Extensions;
55
using LearningHub.Nhs.WebUI.Configuration;
6+
using LearningHub.Nhs.WebUI.Extensions;
67
using LearningHub.Nhs.WebUI.Filters;
78
using LearningHub.Nhs.WebUI.Helpers;
89
using LearningHub.Nhs.WebUI.Models;
@@ -76,6 +77,11 @@ protected BaseController(
7677
/// </summary>
7778
protected int CurrentUserId => this.User.Identity.GetCurrentUserId();
7879

80+
/// <summary>
81+
/// Gets the CurrentUserId.
82+
/// </summary>
83+
protected int CurrentMoodleUserId => this.User.Identity.GetMoodleUserId();
84+
7985
/// <summary>
8086
/// The OnActionExecuting.
8187
/// </summary>

LearningHub.Nhs.WebUI/Controllers/HomeController.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,21 @@ public async Task<IActionResult> Index(string myLearningDashboard = "my-in-progr
207207
var resourcesTask = this.dashboardService.GetResourcesAsync(resourceDashboard, 1);
208208
var cataloguesTask = this.dashboardService.GetCataloguesAsync(catalogueDashboard, 1);
209209

210+
var enrolledCoursesTask = Task.FromResult(new List<MoodleCourseResponseViewModel>());
211+
212+
if (myLearningDashboard == "my-enrolled-courses")
213+
{
214+
enrolledCoursesTask = this.dashboardService.GetEnrolledCoursesFromMoodleAsync(this.CurrentMoodleUserId, 1);
215+
}
216+
210217
await Task.WhenAll(learningTask, resourcesTask, cataloguesTask);
211218

212219
var model = new DashboardViewModel()
213220
{
214221
MyLearnings = await learningTask,
215222
Resources = await resourcesTask,
216223
Catalogues = await cataloguesTask,
224+
EnrolledCourses = await enrolledCoursesTask,
217225
};
218226

219227
if (!string.IsNullOrEmpty(this.Request.Query["preview"]) && Convert.ToBoolean(this.Request.Query["preview"]))

LearningHub.Nhs.WebUI/Extensions/ClaimsPrincipalExtensions.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
using System;
44
using System.Security.Claims;
5+
using System.Security.Principal;
56

67
/// <summary>
78
/// Defines the <see cref="ClaimsPrincipalExtensions" />.
@@ -23,5 +24,21 @@ public static string GetTimezoneOffsetCacheKey(this ClaimsPrincipal claimsPrinci
2324

2425
return $"usr_{userId}_tz";
2526
}
27+
28+
/// <summary>
29+
/// Get MoodleUserId.
30+
/// </summary>
31+
/// <param name="identity">The identity.</param>
32+
/// <returns>The System.Int32.</returns>
33+
public static int GetMoodleUserId(this IIdentity identity)
34+
{
35+
Claim claim = (identity as ClaimsIdentity)?.FindFirst("moodle_username");
36+
if (claim != null)
37+
{
38+
return int.Parse(claim.Value);
39+
}
40+
41+
return 0;
42+
}
2643
}
2744
}

LearningHub.Nhs.WebUI/Interfaces/IDashboardService.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace LearningHub.Nhs.WebUI.Interfaces
22
{
3+
using System.Collections.Generic;
34
using System.Threading.Tasks;
45
using LearningHub.Nhs.Models.Dashboard;
56
using LearningHub.Nhs.WebUI.Models;
@@ -39,5 +40,13 @@ public interface IDashboardService
3940
/// <param name="dashboardEventViewModel">dashboardEventViewModel.</param>
4041
/// <returns>A <see cref="Task"/> representing the result of the asynchronous operation.</returns>
4142
Task RecordDashBoardEventAsync(DashboardEventViewModel dashboardEventViewModel);
43+
44+
/// <summary>
45+
/// GetEnrolledCoursesFromMoodleAsync.
46+
/// </summary>
47+
/// <param name="currentUserId">The current User Id type.</param>
48+
/// <param name="pageNumber">The page Number.</param>
49+
/// <returns>A <see cref="Task{TResult}"/> representing the result of the asynchronous operation.</returns>
50+
Task<List<MoodleCourseResponseViewModel>> GetEnrolledCoursesFromMoodleAsync(int currentUserId, int pageNumber);
4251
}
4352
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace LearningHub.Nhs.WebUI.Interfaces
2+
{
3+
using System.Collections.Generic;
4+
using System.Threading.Tasks;
5+
using LearningHub.Nhs.Models.Dashboard;
6+
using LearningHub.Nhs.WebUI.Models;
7+
8+
/// <summary>
9+
/// IMoodleApiService.
10+
/// </summary>
11+
public interface IMoodleApiService
12+
{
13+
/// <summary>
14+
/// GetEnrolledCoursesAsync.
15+
/// </summary>
16+
/// <param name="currentUserId">Moodle user id.</param>
17+
/// <param name="pageNumber">pageNumber.</param>
18+
/// <returns> List of MoodleCourseResponseViewModel.</returns>
19+
Task<List<MoodleCourseResponseViewModel>> GetEnrolledCoursesAsync(int currentUserId, int pageNumber);
20+
}
21+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace LearningHub.Nhs.Services.Interface
2+
{
3+
using System.Net.Http;
4+
using System.Threading.Tasks;
5+
6+
/// <summary>
7+
/// The Moodle Http Client interface.
8+
/// </summary>
9+
public interface IMoodleHttpClient
10+
{
11+
/// <summary>
12+
/// The get cient async.
13+
/// </summary>
14+
/// <returns>The <see cref="Task"/>.</returns>
15+
Task<HttpClient> GetClient();
16+
17+
/// <summary>
18+
/// GetDefaultParameters.
19+
/// </summary>
20+
/// <returns>defaultParameters.</returns>
21+
string GetDefaultParameters();
22+
}
23+
}

LearningHub.Nhs.WebUI/Models/DashboardViewModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace LearningHub.Nhs.WebUI.Models
22
{
3+
using System.Collections.Generic;
34
using LearningHub.Nhs.Models.Dashboard;
45

56
/// <summary>
@@ -28,5 +29,10 @@ public DashboardViewModel()
2829
/// Gets or sets a list of catalogues to be displayed in the dashboard.
2930
/// </summary>
3031
public DashboardCatalogueResponseViewModel Catalogues { get; set; }
32+
33+
/// <summary>
34+
/// Gets or sets a list of enrolled courses to be displayed in the dashboard.
35+
/// </summary>
36+
public List<MoodleCourseResponseViewModel> EnrolledCourses { get; set; }
3137
}
3238
}
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
namespace LearningHub.Nhs.WebUI.Models
2+
{
3+
using System.Collections.Generic;
4+
5+
/// <summary>
6+
/// MoodleCourseResponseViewModel.
7+
/// </summary>
8+
public class MoodleCourseResponseViewModel
9+
{
10+
/// <summary>
11+
/// Gets or sets the ID.
12+
/// </summary>
13+
public int? Id { get; set; }
14+
15+
/// <summary>
16+
/// Gets or sets the short name.
17+
/// </summary>
18+
public string ShortName { get; set; }
19+
20+
/// <summary>
21+
/// Gets or sets the full name.
22+
/// </summary>
23+
public string FullName { get; set; }
24+
25+
/// <summary>
26+
/// Gets or sets the display name.
27+
/// </summary>
28+
public string DisplayName { get; set; }
29+
30+
/// <summary>
31+
/// Gets or sets the enrolled user count.
32+
/// </summary>
33+
public int? EnrolledUserCount { get; set; }
34+
35+
/// <summary>
36+
/// Gets or sets the ID number.
37+
/// </summary>
38+
public string IdNumber { get; set; }
39+
40+
/// <summary>
41+
/// Gets or sets the visibility status.
42+
/// </summary>
43+
public int? Visible { get; set; }
44+
45+
/// <summary>
46+
/// Gets or sets the summary.
47+
/// </summary>
48+
public string Summary { get; set; }
49+
50+
/// <summary>
51+
/// Gets or sets the summary format.
52+
/// </summary>
53+
public int? SummaryFormat { get; set; }
54+
55+
/// <summary>
56+
/// Gets or sets the format.
57+
/// </summary>
58+
public string Format { get; set; }
59+
60+
/// <summary>
61+
/// Gets or sets the course image URL.
62+
/// </summary>
63+
public string CourseImage { get; set; }
64+
65+
/// <summary>
66+
/// Gets or sets a value indicating whether grades are shown.
67+
/// </summary>
68+
public bool? ShowGrades { get; set; }
69+
70+
/// <summary>
71+
/// Gets or sets the language.
72+
/// </summary>
73+
public string Lang { get; set; }
74+
75+
/// <summary>
76+
/// Gets or sets a value indicating whether completion is enabled.
77+
/// </summary>
78+
public bool? EnableCompletion { get; set; }
79+
80+
/// <summary>
81+
/// Gets or sets a value indicating whether completion has criteria.
82+
/// </summary>
83+
public bool? CompletionHasCriteria { get; set; }
84+
85+
/// <summary>
86+
/// Gets or sets a value indicating whether completion is user-tracked.
87+
/// </summary>
88+
public bool? CompletionUserTracked { get; set; }
89+
90+
/// <summary>
91+
/// Gets or sets the category ID.
92+
/// </summary>
93+
public int? Category { get; set; }
94+
95+
/// <summary>
96+
/// Gets or sets the progress.
97+
/// </summary>
98+
public int? Progress { get; set; }
99+
100+
/// <summary>
101+
/// Gets or sets the completion status.
102+
/// </summary>
103+
public bool? Completed { get; set; }
104+
105+
/// <summary>
106+
/// Gets or sets the start date (Unix timestamp).
107+
/// </summary>
108+
public long? StartDate { get; set; }
109+
110+
/// <summary>
111+
/// Gets or sets the end date.
112+
/// </summary>
113+
public int? EndDate { get; set; }
114+
115+
/// <summary>
116+
/// Gets or sets the marker.
117+
/// </summary>
118+
public int? Marker { get; set; }
119+
120+
/// <summary>
121+
/// Gets or sets the last access timestamp.
122+
/// </summary>
123+
public int? LastAccess { get; set; }
124+
125+
/// <summary>
126+
/// Gets or sets a value indicating whether the course is a favorite.
127+
/// </summary>
128+
public bool? IsFavourite { get; set; }
129+
130+
/// <summary>
131+
/// Gets or sets a value indicating whether the course is hidden.
132+
/// </summary>
133+
public bool? Hidden { get; set; }
134+
135+
/// <summary>
136+
/// Gets or sets the overview files.
137+
/// </summary>
138+
public List<object> OverviewFiles { get; set; }
139+
140+
/// <summary>
141+
/// Gets or sets a value indicating whether activity dates are shown.
142+
/// </summary>
143+
public bool? ShowActivityDates { get; set; }
144+
145+
/// <summary>
146+
/// Gets or sets a value indicating whether completion conditions are shown.
147+
/// </summary>
148+
public bool? ShowCompletionConditions { get; set; }
149+
150+
/// <summary>
151+
/// Gets or sets the last modified timestamp (Unix timestamp).
152+
/// </summary>
153+
public long? TimeModified { get; set; }
154+
}
155+
}

0 commit comments

Comments
 (0)