Skip to content

Commit b36f76c

Browse files
authored
Merge branch 'DLS-Release-v1.2.3' into Develop/feature/TD-5616-Enrolling-on-retiring-self-assessment
2 parents 4fc772c + cadb115 commit b36f76c

File tree

17 files changed

+177
-18
lines changed

17 files changed

+177
-18
lines changed

DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/SelfAssessmentDataService.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public interface ISelfAssessmentDataService
1717
//Self Assessments
1818
string? GetSelfAssessmentNameById(int selfAssessmentId);
1919
SelfAssessment? GetSelfAssessmentById(int selfAssessmentId);
20+
SelfAssessment GetSelfAssessmentRetirementDateById(int selfAssessmentId);
2021

2122
// CompetencyDataService
2223
IEnumerable<int> GetCompetencyIdsForSelfAssessment(int selfAssessmentId);
@@ -254,6 +255,17 @@ FROM SelfAssessments
254255
new { selfAssessmentId }
255256
).SingleOrDefault();
256257
}
258+
public SelfAssessment GetSelfAssessmentRetirementDateById(int selfAssessmentId)
259+
{
260+
var date = connection.QueryFirstOrDefault<SelfAssessment>(
261+
@"SELECT Id,Name,[RetirementDate]
262+
FROM SelfAssessments
263+
WHERE ID = @selfAssessmentId"
264+
,
265+
new { selfAssessmentId }
266+
);
267+
return date;
268+
}
257269

258270
public (IEnumerable<SelfAssessmentDelegate>, int) GetSelfAssessmentDelegates(string searchString, int offSet, int itemsPerPage, string sortBy, string sortDirection,
259271
int? selfAssessmentId, int centreId, bool? isDelegateActive, bool? removed, bool? submitted, bool? signedOff)

DigitalLearningSolutions.Data/DataServices/SupervisorDataService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,8 @@ FROM CandidateAssessments AS CA
796796
WHERE (DelegateUserID = @delegateUserId) AND (RemovedDate IS NULL)
797797
AND (CompletedDate IS NULL)))
798798
AND ((rp.SupervisorSelfAssessmentReview = 1) OR (rp.SupervisorResultsReview = 1))
799-
AND (ISNULL(@categoryId, 0) = 0 OR rp.CategoryID = @categoryId)", new { delegateUserId, centreId, categoryId }
799+
AND (ISNULL(@categoryId, 0) = 0 OR rp.CategoryID = @categoryId) AND
800+
((CAST(rp.RetirementDate AS DATE) >= CAST(GETUTCDATE() AS DATE)) OR rp.RetirementDate IS NULL)", new { delegateUserId, centreId, categoryId }
800801
);
801802
}
802803

DigitalLearningSolutions.Data/Models/SelfAssessments/SelfAssessment.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class SelfAssessment : CurrentLearningItem
1414
public string? QuestionLabel { get; set; }
1515
public string? DescriptionLabel { get; set; }
1616
public DateTime? RetirementDate { get; set; }
17+
1718
public DateTime? EnrolmentCutoffDate { get; set; }
1819
public string? RetirementReason { get; set; }
1920

DigitalLearningSolutions.Web.Tests/Controllers/SupervisorController/SupervisorControllerTests.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using Microsoft.AspNetCore.Mvc;
1717
using Microsoft.Extensions.Configuration;
1818
using Microsoft.Extensions.Logging;
19+
using Microsoft.FeatureManagement;
1920
using NUnit.Framework;
2021
using System.Collections.Generic;
2122
using System.Linq;
@@ -49,6 +50,7 @@ public class SupervisorControllerTests
4950
private IPdfService pdfService = null!;
5051
private SupervisorController controller = null!;
5152
private ICourseCategoriesService courseCategoriesService = null!;
53+
private IFeatureManager featureManager = null!;
5254

5355
[SetUp]
5456
public void Setup()
@@ -73,6 +75,7 @@ public void Setup()
7375
candidateAssessmentDownloadFileService = A.Fake<ICandidateAssessmentDownloadFileService>();
7476
pdfService = A.Fake<IPdfService>();
7577
courseCategoriesService = A.Fake<ICourseCategoriesService>();
78+
featureManager = A.Fake<IFeatureManager>();
7679
A.CallTo(() => candidateAssessmentDownloadFileService.GetCandidateAssessmentDownloadFileForCentre(A<int>._, A<int>._, A<bool>._))
7780
.Returns(new byte[] { });
7881

@@ -108,7 +111,8 @@ public void Setup()
108111
candidateAssessmentDownloadFileService,
109112
clockUtility,
110113
pdfService,
111-
courseCategoriesService
114+
courseCategoriesService,
115+
featureManager
112116
);
113117
controller.ControllerContext = new ControllerContext
114118
{ HttpContext = new DefaultHttpContext { User = user } };
@@ -140,7 +144,8 @@ public void ExportCandidateAssessment_should_return_file_object_with_file_name_i
140144
candidateAssessmentDownloadFileService,
141145
clockUtility,
142146
pdfService,
143-
courseCategoriesService
147+
courseCategoriesService,
148+
featureManager
144149
);
145150
string expectedFileName = $"{((selfAssessmentName.Length > 30) ? selfAssessmentName.Substring(0, 30) : selfAssessmentName)} - {delegateName} - {clockUtility.UtcNow:yyyy-MM-dd}.xlsx";
146151

DigitalLearningSolutions.Web/Controllers/LearningPortalController/Available.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
using DigitalLearningSolutions.Data.Models.SearchSortFilterPaginate;
55
using DigitalLearningSolutions.Web.Attributes;
66
using DigitalLearningSolutions.Web.Helpers;
7+
using DigitalLearningSolutions.Web.Services;
78
using DigitalLearningSolutions.Web.ViewModels.LearningPortal.Available;
89
using Microsoft.AspNetCore.Mvc;
10+
using System;
911
using System.Linq;
1012

1113
public partial class LearningPortalController
@@ -58,8 +60,41 @@ public IActionResult AllAvailableItems()
5860

5961
public IActionResult EnrolOnSelfAssessment(int selfAssessmentId)
6062
{
63+
var selfAssessment = selfAssessmentService.GetSelfAssessmentRetirementDateById(selfAssessmentId);
64+
if(CheckRetirementDate(selfAssessment.RetirementDate)) return RedirectToAction("ConfirmRetirement", new { selfAssessmentId });
6165
courseService.EnrolOnSelfAssessment(selfAssessmentId, User.GetUserIdKnownNotNull(), User.GetCentreIdKnownNotNull());
6266
return RedirectToAction("SelfAssessment", new { selfAssessmentId });
6367
}
68+
69+
[Route("/LearningPortal/Retirement/{selfAssessmentId:int}/confirm")]
70+
public IActionResult ConfirmRetirement(int selfAssessmentId)
71+
{
72+
var selfAssessment = selfAssessmentService.GetSelfAssessmentRetirementDateById(selfAssessmentId);
73+
var model = new RetirementViewModel(selfAssessmentId, selfAssessment.RetirementDate, selfAssessment.Name);
74+
return View("Available/ConfirmRetirement", model);
75+
}
76+
[HttpPost]
77+
[Route("/LearningPortal/Retirement/{selfAssessmentId:int}/confirm")]
78+
public IActionResult ConfirmRetirement(RetirementViewModel retirementViewModel)
79+
{
80+
if (!ModelState.IsValid && !retirementViewModel.ActionConfirmed)
81+
{
82+
var selfAssessment = selfAssessmentService.GetSelfAssessmentRetirementDateById(retirementViewModel.SelfAssessmentId);
83+
var model = new RetirementViewModel(retirementViewModel.SelfAssessmentId , selfAssessment.RetirementDate, selfAssessment.Name);
84+
return View("Available/ConfirmRetirement", model);
85+
}
86+
var date = selfAssessmentService.GetSelfAssessmentRetirementDateById(retirementViewModel.SelfAssessmentId);
87+
courseService.EnrolOnSelfAssessment(retirementViewModel.SelfAssessmentId, User.GetUserIdKnownNotNull(), User.GetCentreIdKnownNotNull());
88+
return RedirectToAction("SelfAssessment", new { retirementViewModel.SelfAssessmentId });
89+
}
90+
private bool CheckRetirementDate(DateTime? date)
91+
{
92+
if (date == null)
93+
return false;
94+
95+
DateTime twoWeeksbeforeRetirementdate = DateTime.Today.AddDays(14);
96+
DateTime today = DateTime.Today;
97+
return (date >= today && date <= twoWeeksbeforeRetirementdate);
98+
}
6499
}
65100
}

DigitalLearningSolutions.Web/Controllers/SupervisorController/Supervisor.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,23 @@
2727

2828
public partial class SupervisorController
2929
{
30-
public IActionResult Index()
30+
public async Task<IActionResult> IndexAsync()
3131
{
3232
var adminId = GetAdminId();
3333
var dashboardData = supervisorService.GetDashboardDataForAdminId(adminId);
3434
var signOffRequests = supervisorService.GetSupervisorDashboardToDoItemsForRequestedSignOffs(adminId);
3535
var reviewRequests = supervisorService.GetSupervisorDashboardToDoItemsForRequestedReviews(adminId);
3636
var supervisorDashboardToDoItems = Enumerable.Concat(signOffRequests, reviewRequests);
3737
var bannerText = GetBannerText();
38+
var tableauFlag = await featureManager.IsEnabledAsync(FeatureFlags.TableauSelfAssessmentDashboards);
39+
var tableauQueryOverride = string.Equals(Request.Query["tableaulink"], "true", StringComparison.OrdinalIgnoreCase);
40+
var showTableauLink = tableauFlag || tableauQueryOverride;
3841
var model = new SupervisorDashboardViewModel()
3942
{
4043
DashboardData = dashboardData,
4144
SupervisorDashboardToDoItems = supervisorDashboardToDoItems,
42-
BannerText = bannerText
45+
BannerText = bannerText,
46+
ShowTableauLink = showTableauLink
4347
};
4448
return View(model);
4549
}

DigitalLearningSolutions.Web/Controllers/SupervisorController/SupervisorController.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Microsoft.AspNetCore.Mvc;
99
using Microsoft.Extensions.Configuration;
1010
using Microsoft.Extensions.Logging;
11+
using Microsoft.FeatureManagement;
1112

1213
[Authorize(Policy = CustomPolicies.UserSupervisor)]
1314
public partial class SupervisorController : Controller
@@ -28,7 +29,7 @@ public partial class SupervisorController : Controller
2829
private readonly IClockUtility clockUtility;
2930
private readonly IPdfService pdfService;
3031
private readonly ICourseCategoriesService courseCategoriesService;
31-
32+
private readonly IFeatureManager featureManager;
3233
public SupervisorController(
3334
ISupervisorService supervisorService,
3435
ICommonService commonService,
@@ -49,7 +50,8 @@ public SupervisorController(
4950
ICandidateAssessmentDownloadFileService candidateAssessmentDownloadFileService,
5051
IClockUtility clockUtility,
5152
IPdfService pdfService,
52-
ICourseCategoriesService courseCategoriesService
53+
ICourseCategoriesService courseCategoriesService,
54+
IFeatureManager featureManager
5355
)
5456
{
5557
this.supervisorService = supervisorService;
@@ -68,6 +70,7 @@ ICourseCategoriesService courseCategoriesService
6870
this.clockUtility = clockUtility;
6971
this.pdfService = pdfService;
7072
this.courseCategoriesService = courseCategoriesService;
73+
this.featureManager = featureManager;
7174
}
7275

7376
private int GetCentreId()

DigitalLearningSolutions.Web/Controllers/TrackingSystem/Centre/SelfAssessmentReports/SelfAssessmentReportsController.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ IFeatureManager featureManager
5353
this.selfAssessmentService = selfAssessmentService;
5454
this.featureManager = featureManager;
5555
}
56+
[Route("/TrackingSystem/Centre/Reports/SelfAssessments")]
5657
public async Task<IActionResult> IndexAsync()
5758
{
5859
var centreId = User.GetCentreId();
@@ -65,7 +66,7 @@ public async Task<IActionResult> IndexAsync()
6566
return View(model);
6667
}
6768
[HttpGet]
68-
[Route("DownloadDcsa")]
69+
[Route("/TrackingSystem/Centre/Reports/DownloadDcsa")]
6970
public IActionResult DownloadDigitalCapabilityToExcel()
7071
{
7172
var centreId = User.GetCentreIdKnownNotNull();
@@ -78,7 +79,7 @@ public IActionResult DownloadDigitalCapabilityToExcel()
7879
);
7980
}
8081
[HttpGet]
81-
[Route("DownloadReport")]
82+
[Route("/TrackingSystem/Centre/Reports/DownloadReport")]
8283
public IActionResult DownloadSelfAssessmentReport(int selfAssessmentId)
8384
{
8485
var centreId = User.GetCentreId();
@@ -92,15 +93,16 @@ public IActionResult DownloadSelfAssessmentReport(int selfAssessmentId)
9293
);
9394
}
9495
[HttpGet]
95-
[Route("TableauCompetencyDashboard")]
96-
public async Task<IActionResult> TableauCompetencyDashboardAsync()
96+
[Route("/{source}/Reports/TableauCompetencyDashboard")]
97+
public async Task<IActionResult> TableauCompetencyDashboardAsync(string source = "TrackingSystem")
9798
{
9899
var userEmail = User.GetUserPrimaryEmail();
99100
var adminId = User.GetAdminId();
100101
var jwt = tableauConnectionHelper.GetTableauJwt();
101102
var tableauFlag = await featureManager.IsEnabledAsync(FeatureFlags.TableauSelfAssessmentDashboards);
102103
var tableauQueryOverride = string.Equals(Request.Query["tableaulink"], "true", StringComparison.OrdinalIgnoreCase);
103104
var showTableauLink = tableauFlag || tableauQueryOverride;
105+
ViewBag.Source = source;
104106
ViewBag.Email = userEmail;
105107
ViewBag.AdminId = adminId;
106108
ViewBag.SiteName = tableauSiteName;

DigitalLearningSolutions.Web/Services/SelfAssessmentService.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ public IEnumerable<SelfAssessmentResult> GetSelfAssessmentResultswithSupervisorV
163163
int competencyId
164164
);
165165
void RemoveReviewCandidateAssessmentOptionalCompetencies(int id);
166+
SelfAssessment GetSelfAssessmentRetirementDateById(int selfAssessmentId);
166167
}
167168

168169
public class SelfAssessmentService : ISelfAssessmentService
@@ -616,5 +617,9 @@ public void RemoveReviewCandidateAssessmentOptionalCompetencies(int id)
616617
{
617618
selfAssessmentDataService.RemoveReviewCandidateAssessmentOptionalCompetencies(id);
618619
}
620+
public SelfAssessment GetSelfAssessmentRetirementDateById(int selfAssessmentId)
621+
{
622+
return selfAssessmentDataService.GetSelfAssessmentRetirementDateById(selfAssessmentId);
623+
}
619624
}
620625
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using DigitalLearningSolutions.Web.Attributes;
2+
using System;
3+
4+
namespace DigitalLearningSolutions.Web.ViewModels.LearningPortal.Available
5+
{
6+
7+
public class RetirementViewModel
8+
{
9+
public RetirementViewModel()
10+
{
11+
12+
}
13+
public RetirementViewModel(int selfAssessmentId, DateTime? retirementDate, string name)
14+
{
15+
SelfAssessmentId = selfAssessmentId;
16+
RetirementDate = retirementDate;
17+
Name = name;
18+
}
19+
public string Name { get; set; } = string.Empty;
20+
public int SelfAssessmentId { get; set; }
21+
public DateTime? RetirementDate { get; set; }
22+
[BooleanMustBeTrue(ErrorMessage = "Please tick the checkbox to confirm you wish to perform this action")]
23+
public bool ActionConfirmed { get; set; }
24+
}
25+
}

0 commit comments

Comments
 (0)