Skip to content

Commit a731074

Browse files
authored
Merge pull request #2917 from TechnologyEnhancedLearning/Develop/Features/TD-4889-WhenasupervisorpromotesalearnertotheNominatedsupervisorrole,assignthemtothesamecategoryasthesupervisor
TD-4889 When a supervisor promotes a learner to the Nominated supervisor role, assign them to the same category as the supervisor
2 parents e0365ab + e47d940 commit a731074

File tree

5 files changed

+89
-47
lines changed

5 files changed

+89
-47
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class SupervisorControllerTests
3232
private IClockUtility clockUtility = null!;
3333
private ICandidateAssessmentDownloadFileService candidateAssessmentDownloadFileService = null!;
3434
private IPdfService pdfService = null!;
35+
private ICourseCategoriesService courseCategoriesService = null!;
3536

3637
[SetUp]
3738
public void Setup()
@@ -55,6 +56,7 @@ public void Setup()
5556
clockUtility = A.Fake<IClockUtility>();
5657
candidateAssessmentDownloadFileService = A.Fake<ICandidateAssessmentDownloadFileService>();
5758
pdfService = A.Fake<IPdfService>();
59+
courseCategoriesService = A.Fake<ICourseCategoriesService>();
5860
A.CallTo(() => candidateAssessmentDownloadFileService.GetCandidateAssessmentDownloadFileForCentre(A<int>._, A<int>._, A<bool>._))
5961
.Returns(new byte[] { });
6062
}
@@ -83,7 +85,8 @@ public void ExportCandidateAssessment_should_return_file_object_with_file_name_i
8385
emailService,
8486
candidateAssessmentDownloadFileService,
8587
clockUtility,
86-
pdfService
88+
pdfService,
89+
courseCategoriesService
8790
);
8891
string expectedFileName = $"{((selfAssessmentName.Length > 30) ? selfAssessmentName.Substring(0, 30) : selfAssessmentName)} - {delegateName} - {clockUtility.UtcNow:yyyy-MM-dd}.xlsx";
8992

DigitalLearningSolutions.Web/Controllers/SupervisorController/Supervisor.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,9 +1273,13 @@ public IActionResult SignOffHistory(int supervisorDelegateId, int candidateAsses
12731273
[Route("/Supervisor/Staff/{supervisorDelegateId}/NominateSupervisor")]
12741274
public IActionResult NominateSupervisor(int supervisorDelegateId, ReturnPageQuery returnPageQuery)
12751275
{
1276+
var centreId = User.GetCentreIdKnownNotNull();
1277+
var loggedInAdmin = userService.GetAdminById(GetAdminId());
12761278
var superviseDelegate =
12771279
supervisorService.GetSupervisorDelegateDetailsById(supervisorDelegateId, GetAdminId(), 0);
1278-
var model = new SupervisorDelegateViewModel(superviseDelegate, returnPageQuery);
1280+
var categories = courseCategoriesService.GetCategoriesForCentreAndCentrallyManagedCourses(centreId);
1281+
categories = categories.Prepend(new Category { CategoryName = "All", CourseCategoryID = 0 });
1282+
var model = new SupervisorDelegateViewModel(superviseDelegate, returnPageQuery, categories, loggedInAdmin.CategoryId);
12791283
if (TempData["NominateSupervisorError"] != null)
12801284
{
12811285
if (Convert.ToBoolean(TempData["NominateSupervisorError"].ToString()))
@@ -1300,13 +1304,13 @@ public IActionResult ConfirmNominateSupervisor(SupervisorDelegateViewModel super
13001304
supervisorDelegateDetail.DelegateUserID,
13011305
(int)User.GetCentreId()
13021306
);
1303-
1307+
supervisorDelegate.SelfAssessmentCategory = supervisorDelegate.SelfAssessmentCategory == 0 ? adminUser.CategoryId.Value : supervisorDelegate.SelfAssessmentCategory;
13041308
var centreName = adminUser.CentreName;
13051309

13061310
var adminRoles = new AdminRoles(false, false, true, false, false, false, false, false);
13071311
if (supervisorDelegateDetail.DelegateUserID != null)
13081312
{
1309-
registrationService.PromoteDelegateToAdmin(adminRoles, categoryId, (int)supervisorDelegateDetail.DelegateUserID, (int)User.GetCentreId(), true);
1313+
registrationService.PromoteDelegateToAdmin(adminRoles, supervisorDelegate.SelfAssessmentCategory, (int)supervisorDelegateDetail.DelegateUserID, (int)User.GetCentreId(), true);
13101314

13111315
if (delegateUser != null && adminUser != null)
13121316
{

DigitalLearningSolutions.Web/Controllers/SupervisorController/SupervisorController.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public partial class SupervisorController : Controller
2727
private readonly ICandidateAssessmentDownloadFileService candidateAssessmentDownloadFileService;
2828
private readonly IClockUtility clockUtility;
2929
private readonly IPdfService pdfService;
30+
private readonly ICourseCategoriesService courseCategoriesService;
3031

3132
public SupervisorController(
3233
ISupervisorService supervisorService,
@@ -47,7 +48,8 @@ public SupervisorController(
4748
IEmailService emailService,
4849
ICandidateAssessmentDownloadFileService candidateAssessmentDownloadFileService,
4950
IClockUtility clockUtility,
50-
IPdfService pdfService
51+
IPdfService pdfService,
52+
ICourseCategoriesService courseCategoriesService
5153
)
5254
{
5355
this.supervisorService = supervisorService;
@@ -65,6 +67,7 @@ IPdfService pdfService
6567
this.candidateAssessmentDownloadFileService = candidateAssessmentDownloadFileService;
6668
this.clockUtility = clockUtility;
6769
this.pdfService = pdfService;
70+
this.courseCategoriesService = courseCategoriesService;
6871
}
6972

7073
private int GetCentreId()

DigitalLearningSolutions.Web/ViewModels/Supervisor/SupervisorDelegateViewModel.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,29 @@
33
using DigitalLearningSolutions.Data.Models.SearchSortFilterPaginate;
44
using DigitalLearningSolutions.Data.Models.Supervisor;
55
using DigitalLearningSolutions.Web.Attributes;
6+
using Microsoft.AspNetCore.Mvc.Rendering;
7+
using System.Collections.Generic;
68
using System.ComponentModel;
9+
using DigitalLearningSolutions.Data.Models.Common;
10+
using DigitalLearningSolutions.Web.Helpers;
11+
using System.Linq;
712

813
public class SupervisorDelegateViewModel
914
{
15+
public SupervisorDelegateViewModel(SupervisorDelegateDetail detail, ReturnPageQuery returnPageQuery, IEnumerable<Category> categories, int? adminCategoryId)
16+
{
17+
Id = detail.ID;
18+
FirstName = detail.FirstName;
19+
LastName = detail.LastName;
20+
DelegateEmail = detail.DelegateEmail;
21+
CandidateAssessmentCount = detail.CandidateAssessmentCount;
22+
ReturnPageQuery = returnPageQuery;
23+
SelfAssessmentCategory = AdminCategoryHelper.CategoryIdToAdminCategory(adminCategoryId);
24+
SelfAssessmentCategories = SelectListHelper.MapOptionsToSelectListItems(
25+
categories.Select(c => (c.CourseCategoryID, c.CategoryName)),
26+
adminCategoryId
27+
);
28+
}
1029
public SupervisorDelegateViewModel(SupervisorDelegateDetail detail, ReturnPageQuery returnPageQuery)
1130
{
1231
Id = detail.ID;
@@ -23,10 +42,11 @@ public SupervisorDelegateViewModel() { }
2342
public int CandidateAssessmentCount { get; set; }
2443
public string DelegateEmail { get; set; }
2544
public ReturnPageQuery ReturnPageQuery { get; set; }
26-
2745
[BooleanMustBeTrue(ErrorMessage = "Please tick the checkbox to confirm you wish to perform this action")]
2846
public bool ActionConfirmed { get; set; }
2947
[DefaultValue(false)]
3048
public bool ConfirmedRemove { get; set; }
49+
public int SelfAssessmentCategory { get; set; }
50+
public IEnumerable<SelectListItem> SelfAssessmentCategories { get; set; }
3151
}
3252
}

DigitalLearningSolutions.Web/Views/Supervisor/NominateSupervisor.cshtml

Lines changed: 53 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,65 @@
33
@model SupervisorDelegateViewModel;
44
@inject IConfiguration Configuration;
55
@{
6-
var errorHasOccurred = !ViewData.ModelState.IsValid;
7-
ViewData["Application"] = "Supervisor";
8-
ViewData["Title"] = "Confirm Nominated supervisor";
9-
ViewData["HeaderPath"] = $"{Configuration["AppRootPath"]}/Supervisor/MyStaff";
10-
ViewData["HeaderPathName"] = "My Staff";
6+
var errorHasOccurred = !ViewData.ModelState.IsValid;
7+
ViewData["Application"] = "Supervisor";
8+
ViewData["Title"] = "Confirm Nominated supervisor";
9+
ViewData["HeaderPath"] = $"{Configuration["AppRootPath"]}/Supervisor/MyStaff";
10+
ViewData["HeaderPathName"] = "My Staff";
1111
}
1212

1313
@section NavMenuItems {
14-
<partial name="Shared/_NavMenuItems" />
14+
<partial name="Shared/_NavMenuItems" />
1515
}
1616

17-
<div class="nhsuk-grid-row">
17+
<div class="nhsuk-grid-row">
1818
<div class="nhsuk-grid-column-full">
19-
@if (errorHasOccurred)
20-
{
21-
<vc:error-summary order-of-property-names="@(new[] { nameof(Model.ActionConfirmed) })" />
22-
}
23-
<h1 id="page-heading">@ViewData["Title"]</h1>
24-
<div class="nhsuk-grid-row">
25-
<div class="nhsuk-grid-column-one-quarter nhsuk-heading-l">
26-
<div class="nhsuk-u-font-weight-bold">
27-
Staff member:
19+
@if (errorHasOccurred)
20+
{
21+
<vc:error-summary order-of-property-names="@(new[] { nameof(Model.ActionConfirmed) })" />
22+
}
23+
<h1 id="page-heading">@ViewData["Title"]</h1>
24+
<div class="nhsuk-grid-row">
25+
<div class="nhsuk-grid-column-one-quarter nhsuk-heading-l">
26+
<div class="nhsuk-u-font-weight-bold">
27+
Staff member:
28+
</div>
29+
</div>
30+
<div class="nhsuk-grid-column-three-quarters nhsuk-heading-l nhsuk-u-font-weight-normal">
31+
@Model.FirstName @Model.LastName (@Model.DelegateEmail)
32+
</div>
2833
</div>
29-
</div>
30-
<div class="nhsuk-grid-column-three-quarters nhsuk-heading-l nhsuk-u-font-weight-normal">
31-
@Model.FirstName @Model.LastName (@Model.DelegateEmail)
32-
</div>
33-
</div>
34-
<p class="nhsuk-body-m">By promoting this member of staff to the Nominated supervisor role, you are confirming their competence to assess the capability of others.</p>
35-
<p>Once the Nominated supervisor role has been assigned, it can only be removed by a Centre Manager or Clinical Centre Manager.</p>
36-
<form method="post" asp-controller="Supervisor">
37-
<div class="nhsuk-checkboxes__item">
38-
<vc:single-checkbox asp-for="@nameof(Model.ActionConfirmed)"
39-
label="I am sure that I wish to promote @Model.FirstName @Model.LastName to the Nominated supervisor role"
40-
hint-text="I understand that the Nominated supervisor role can only be removed by a Centre Manager or Clinical Centre Manager." />
41-
</div>
42-
<button type="submit" class="nhsuk-button nhsuk-u-margin-top-4" asp-action="ConfirmNominateSupervisor">
43-
Confirm
44-
</button>
45-
@Html.HiddenFor(m => m.Id)
46-
@Html.HiddenFor(m => m.FirstName)
47-
@Html.HiddenFor(m => m.LastName)
48-
@Html.HiddenFor(m => m.DelegateEmail)
49-
@Html.HiddenFor(m => m.CandidateAssessmentCount)
50-
@Html.HiddenFor(m => m.ReturnPageQuery)
51-
</form>
34+
<p class="nhsuk-body-m">By promoting this member of staff to the Nominated supervisor role, you are confirming their competence to assess the capability of others.</p>
35+
<p>Once the Nominated supervisor role has been assigned, it can only be removed by a Centre Manager or Clinical Centre Manager.</p>
36+
<form method="post" asp-controller="Supervisor">
37+
<div class="nhsuk-checkboxes__item">
38+
<vc:single-checkbox asp-for="@nameof(Model.ActionConfirmed)"
39+
label="I am sure that I wish to promote @Model.FirstName @Model.LastName to the Nominated supervisor role"
40+
hint-text="I understand that the Nominated supervisor role can only be removed by a Centre Manager or Clinical Centre Manager." />
41+
</div>
42+
@if(Model.SelfAssessmentCategory == 0)
43+
{
44+
<vc:select-list asp-for="SelfAssessmentCategory"
45+
label="Self assessment category (optional)"
46+
value="@Model.SelfAssessmentCategory.ToString()"
47+
hint-text="Limits the nominated supervisor to self assessments in a particular category."
48+
required="false"
49+
css-class="nhsuk-u-width-one-half"
50+
default-option=""
51+
select-list-options="@Model.SelfAssessmentCategories" />
52+
}
53+
<button type="submit" class="nhsuk-button nhsuk-u-margin-top-4" asp-action="ConfirmNominateSupervisor">
54+
Confirm
55+
</button>
56+
@Html.HiddenFor(m => m.Id)
57+
@Html.HiddenFor(m => m.FirstName)
58+
@Html.HiddenFor(m => m.LastName)
59+
@Html.HiddenFor(m => m.DelegateEmail)
60+
@Html.HiddenFor(m => m.CandidateAssessmentCount)
61+
@Html.HiddenFor(m => m.ReturnPageQuery)
62+
@Html.HiddenFor(m => m.SelfAssessmentCategories)
63+
</form>
5264

53-
<vc:cancel-link-with-return-page-query asp-controller="Supervisor" asp-action="MyStaffList" return-page-query="@Model.ReturnPageQuery" />
54-
</div>
65+
<vc:cancel-link-with-return-page-query asp-controller="Supervisor" asp-action="MyStaffList" return-page-query="@Model.ReturnPageQuery" />
66+
</div>
5567
</div>

0 commit comments

Comments
 (0)