From 0d77ebc58da510dcc29ea2fe327d93337bf27d65 Mon Sep 17 00:00:00 2001 From: showkath10 <90783892+showkath10@users.noreply.github.com> Date: Mon, 25 Oct 2021 01:59:48 +0100 Subject: [PATCH 1/6] HEEDLS-445 Edit course options --- .../DataServices/CourseDataServiceTests.cs | 65 +++++++++++++ .../DataServices/CourseDataService.cs | 46 +++++++++ .../Models/Courses/CourseOptions.cs | 20 ++++ .../Services/CourseService.cs | 20 ++++ .../BasicAuthenticatedAccessibilityTests.cs | 1 + .../ManageCourseControllerTests.cs | 95 +++++++++++++++++++ .../CourseSetup/ManageCourseController.cs | 55 +++++++++++ .../CourseDetails/CourseOptionsViewModel.cs | 2 + .../EditCourseOptionsViewModel.cs | 56 +++++++++++ .../ManageCourse/EditCourseOptions.cshtml | 35 +++++++ .../_CourseOptionsExpandable.cshtml | 58 +++++------ 11 files changed, 426 insertions(+), 27 deletions(-) create mode 100644 DigitalLearningSolutions.Data/Models/Courses/CourseOptions.cs create mode 100644 DigitalLearningSolutions.Web/ViewModels/TrackingSystem/CourseSetup/CourseDetails/EditCourseOptionsViewModel.cs create mode 100644 DigitalLearningSolutions.Web/Views/TrackingSystem/CourseSetup/ManageCourse/EditCourseOptions.cshtml diff --git a/DigitalLearningSolutions.Data.Tests/DataServices/CourseDataServiceTests.cs b/DigitalLearningSolutions.Data.Tests/DataServices/CourseDataServiceTests.cs index a58128eec0..62a5df2356 100644 --- a/DigitalLearningSolutions.Data.Tests/DataServices/CourseDataServiceTests.cs +++ b/DigitalLearningSolutions.Data.Tests/DataServices/CourseDataServiceTests.cs @@ -450,5 +450,70 @@ public void UpdateLearningPathwayDefaultsForCourse_correctly_updates_learning_pa transaction.Dispose(); } } + + [Test] + public void Edit_Course_Options_updates_course_options_successfully() + { + using var transaction = new TransactionScope(); + const int customisationId = 100; + const int centreId = 101; + const int categoryId = 0; + + var defaultCourseOptions = new CourseOptions() + { + Active = true, + DiagObjSelect = true, + SelfRegister = false, + HideInLearnerPortal = false, + }; + + try + { + // When + courseDataService.UpdateCourseOptions(defaultCourseOptions, customisationId); + var updatedCourseOptions = courseDataService.GetCourseOptionsForAdminCategoryId( + customisationId, + centreId, + categoryId + ); + + // Then + using (new AssertionScope()) + { + updatedCourseOptions?.Active.Should().BeTrue(); + updatedCourseOptions?.DiagObjSelect.Should().BeTrue(); + updatedCourseOptions?.SelfRegister.Should().BeFalse(); + updatedCourseOptions?.HideInLearnerPortal.Should().BeFalse(); + } + } + finally + { + transaction.Dispose(); + } + } + + [Test] + public void Edit_Course_Options_get_course_options_for_admin_categoryId() + { + const int customisationId = 100; + const int centreId = 101; + const int categoryId = 0; + + // When + var updatedCourseOptions = courseDataService.GetCourseOptionsForAdminCategoryId( + customisationId, + centreId, + categoryId + ); + + // Then + using (new AssertionScope()) + { + updatedCourseOptions?.Active.Should().BeFalse(); + updatedCourseOptions?.DiagObjSelect.Should().BeTrue(); + updatedCourseOptions?.SelfRegister.Should().BeTrue(); + updatedCourseOptions?.HideInLearnerPortal.Should().BeFalse(); + } + } } } diff --git a/DigitalLearningSolutions.Data/DataServices/CourseDataService.cs b/DigitalLearningSolutions.Data/DataServices/CourseDataService.cs index 8194237c71..ba9847ea18 100644 --- a/DigitalLearningSolutions.Data/DataServices/CourseDataService.cs +++ b/DigitalLearningSolutions.Data/DataServices/CourseDataService.cs @@ -32,6 +32,9 @@ void UpdateLearningPathwayDefaultsForCourse( bool mandatory, bool autoRefresh ); + + void UpdateCourseOptions(CourseOptions courseOptions, int customisationId); + CourseOptions? GetCourseOptionsForAdminCategoryId(int customisationId, int centreId, int categoryId); } public class CourseDataService : ICourseDataService @@ -422,5 +425,48 @@ bool autoRefresh new { completeWithinMonths, validityMonths, mandatory, autoRefresh, customisationId } ); } + + public void UpdateCourseOptions(CourseOptions courseOptions, int customisationId) + { + connection.Execute( + @"UPDATE cu + SET Active = @Active, + SelfRegister = @SelfRegister, + HideInLearnerPortal = @HideInLearnerPortal, + DiagObjSelect = @DiagObjSelect + FROM dbo.Customisations AS cu + WHERE + cu.CustomisationID = @customisationId", + new + { + courseOptions.Active, + courseOptions.SelfRegister, + courseOptions.HideInLearnerPortal, + courseOptions.DiagObjSelect, + customisationId, + }); + } + + public CourseOptions? GetCourseOptionsForAdminCategoryId(int customisationId, int centreId, int categoryId) + { + return connection.Query( + @"SELECT + cu.Active, + cu.SelfRegister, + cu.HideInLearnerPortal, + cu.DiagObjSelect, + ap.DiagAssess + FROM dbo.Customisations AS cu + INNER JOIN dbo.Applications AS ap ON ap.ApplicationID = cu.ApplicationID + LEFT JOIN dbo.Customisations AS refreshToCu ON refreshToCu.CustomisationID = cu.RefreshToCustomisationId + LEFT JOIN dbo.Applications AS refreshToAp ON refreshToAp.ApplicationID = refreshToCu.ApplicationID + WHERE + (ap.CourseCategoryID = @categoryId OR @categoryId = 0) + AND cu.CentreID = @centreId + AND ap.ArchivedDate IS NULL + AND cu.CustomisationID = @customisationId", + new { customisationId, centreId, categoryId } + ).FirstOrDefault(); + } } } diff --git a/DigitalLearningSolutions.Data/Models/Courses/CourseOptions.cs b/DigitalLearningSolutions.Data/Models/Courses/CourseOptions.cs new file mode 100644 index 0000000000..77c0205dd4 --- /dev/null +++ b/DigitalLearningSolutions.Data/Models/Courses/CourseOptions.cs @@ -0,0 +1,20 @@ +namespace DigitalLearningSolutions.Data.Models.Courses +{ + public interface ICourseOptions + { + public bool Active { get; set; } + public bool SelfRegister { get; set; } + public bool HideInLearnerPortal { get; set; } + public bool DiagObjSelect { get; set; } + public bool DiagAssess { get; set; } + } + + public class CourseOptions : ICourseOptions + { + public bool Active { get; set; } + public bool SelfRegister { get; set; } + public bool HideInLearnerPortal { get; set; } + public bool DiagObjSelect { get; set; } + public bool DiagAssess { get; set; } + } +} diff --git a/DigitalLearningSolutions.Data/Services/CourseService.cs b/DigitalLearningSolutions.Data/Services/CourseService.cs index 76830138b1..c97360b78f 100644 --- a/DigitalLearningSolutions.Data/Services/CourseService.cs +++ b/DigitalLearningSolutions.Data/Services/CourseService.cs @@ -20,6 +20,9 @@ public void UpdateLearningPathwayDefaultsForCourse( bool mandatory, bool autoRefresh ); + + void UpdateCourseOptions(CourseOptions courseOptions, int customisationId); + CourseOptions? GetCourseOptionsForAdminCategoryId(int customisationId, int centreId, int categoryId); } public class CourseService : ICourseService @@ -106,5 +109,22 @@ bool autoRefresh autoRefresh ); } + + public void UpdateCourseOptions(CourseOptions courseOptions, int customisationId) + { + courseDataService.UpdateCourseOptions( + courseOptions, + customisationId + ); + } + + public CourseOptions? GetCourseOptionsForAdminCategoryId(int customisationId, int centreId, int categoryId) + { + return courseDataService.GetCourseOptionsForAdminCategoryId( + customisationId, + centreId, + categoryId + ); + } } } diff --git a/DigitalLearningSolutions.Web.AutomatedUiTests/AccessibilityTests/BasicAuthenticatedAccessibilityTests.cs b/DigitalLearningSolutions.Web.AutomatedUiTests/AccessibilityTests/BasicAuthenticatedAccessibilityTests.cs index 654c22700b..a8772a652a 100644 --- a/DigitalLearningSolutions.Web.AutomatedUiTests/AccessibilityTests/BasicAuthenticatedAccessibilityTests.cs +++ b/DigitalLearningSolutions.Web.AutomatedUiTests/AccessibilityTests/BasicAuthenticatedAccessibilityTests.cs @@ -46,6 +46,7 @@ public BasicAuthenticatedAccessibilityTests(AuthenticatedAccessibilityTestsFixtu "/TrackingSystem/CourseSetup/10716/Manage/LearningPathwayDefaults", "Edit Learning Pathway defaults" )] + [InlineData("/TrackingSystem/CourseSetup/10716/Manage/EditCourseOptions", "Edit course options")] [InlineData("/TrackingSystem/Delegates/All", "Delegates")] [InlineData("/TrackingSystem/Delegates/Groups", "Groups")] [InlineData("/TrackingSystem/Delegates/Groups/5/Delegates", "Group delegates")] diff --git a/DigitalLearningSolutions.Web.Tests/Controllers/TrackingSystem/CourseSetup/ManageCourseControllerTests.cs b/DigitalLearningSolutions.Web.Tests/Controllers/TrackingSystem/CourseSetup/ManageCourseControllerTests.cs index 6496347e39..22bba252d2 100644 --- a/DigitalLearningSolutions.Web.Tests/Controllers/TrackingSystem/CourseSetup/ManageCourseControllerTests.cs +++ b/DigitalLearningSolutions.Web.Tests/Controllers/TrackingSystem/CourseSetup/ManageCourseControllerTests.cs @@ -115,5 +115,100 @@ public void result.Should().BeViewResult().ModelAs(); Assert.IsFalse(controller.ModelState.IsValid); } + + [Test] + public void Edit_Course_Options_page_opens_up_with_course_options() + { + // Given + const int customisationId = 1; + A.CallTo( + () => courseService.VerifyAdminUserCanAccessCourse( + customisationId, + A._, + A._ + ) + ).Returns(true); + + A.CallTo( + () => courseService.GetCourseOptionsForAdminCategoryId( + customisationId, + A._, + A._ + ) + ).Returns(new CourseOptions()); + + + // When + var result = controller.EditCourseOptions(customisationId); + + // Then + result.Should().BeViewResult().WithDefaultViewName().ModelAs(); + } + + [Test] + public void Edit_Course_Options_page_redirects_to_Index_when_course_details_are_updated() + { + // Given + const int customisationId = 1; + var courseOptions = new CourseOptions() + { + Active = true, + DiagObjSelect = true, + HideInLearnerPortal = true, + SelfRegister = true + }; + + A.CallTo( + () => courseService.UpdateCourseOptions( + A._, + customisationId + ) + ).DoesNothing(); + + var editCourseOptionsViewModel = new EditCourseOptionsViewModel(courseOptions, customisationId); + + // When + var result = controller.EditCourseOptions(customisationId, editCourseOptionsViewModel); + + // Then + A.CallTo( + () => courseService.UpdateCourseOptions( + A._, + customisationId + ) + ).MustHaveHappened(); + + result.Should().BeRedirectToActionResult().WithControllerName("ManageCourse").WithActionName("Index"); + } + + [Test] + public void Edit_Course_Options_redirects_to_not_found_page_when_admin_user_cannot_access_course() + { + // Given + const int customisationId = 1; + A.CallTo( + () => courseService.VerifyAdminUserCanAccessCourse( + customisationId, + A._, + A._ + ) + ).Returns(false); + + A.CallTo( + () => courseService.GetCourseOptionsForAdminCategoryId( + customisationId, + A._, + A._ + ) + ).Returns(new CourseOptions()); + + + // When + var result = controller.EditCourseOptions(customisationId); + + // Then + result.Should().BeNotFoundResult(); + } + } } diff --git a/DigitalLearningSolutions.Web/Controllers/TrackingSystem/CourseSetup/ManageCourseController.cs b/DigitalLearningSolutions.Web/Controllers/TrackingSystem/CourseSetup/ManageCourseController.cs index d645a194ce..a0c482fab0 100644 --- a/DigitalLearningSolutions.Web/Controllers/TrackingSystem/CourseSetup/ManageCourseController.cs +++ b/DigitalLearningSolutions.Web/Controllers/TrackingSystem/CourseSetup/ManageCourseController.cs @@ -1,6 +1,7 @@ namespace DigitalLearningSolutions.Web.Controllers.TrackingSystem.CourseSetup { using DigitalLearningSolutions.Data.Enums; + using DigitalLearningSolutions.Data.Models.Courses; using DigitalLearningSolutions.Data.Services; using DigitalLearningSolutions.Web.Attributes; using DigitalLearningSolutions.Web.Helpers; @@ -98,5 +99,59 @@ EditLearningPathwayDefaultsViewModel model return RedirectToAction("Index", new { customisationId = model.CustomisationId }); } + + [HttpGet] + [Route("EditCourseOptions")] + public IActionResult EditCourseOptions(int customisationId) + { + var centreId = User.GetCentreId(); + var categoryId = User.GetAdminCategoryId()!; + + if (!courseService.VerifyAdminUserCanAccessCourse( + customisationId, + centreId, categoryId.GetValueOrDefault())) + { + return NotFound(); + } + + var courseOptions = courseService.GetCourseOptionsForAdminCategoryId( + customisationId, + centreId, + categoryId.GetValueOrDefault() + ); + + var model = new EditCourseOptionsViewModel(courseOptions!, customisationId); + return View(model); + } + + [HttpPost] + [Route("EditCourseOptions")] + public IActionResult EditCourseOptions( + int customisationId, + EditCourseOptionsViewModel editCourseOptionsViewModel + ) + { + var centreId = User.GetCentreId(); + var categoryId = User.GetAdminCategoryId()!; + + if (!courseService.VerifyAdminUserCanAccessCourse( + customisationId, + centreId, + categoryId.GetValueOrDefault())) + { + return NotFound(); + } + + var courseOptions = new CourseOptions + { + Active = editCourseOptionsViewModel.Active, + SelfRegister = editCourseOptionsViewModel.AllowSelfEnrolment, + HideInLearnerPortal = editCourseOptionsViewModel.HideInLearningPortal, + DiagObjSelect = editCourseOptionsViewModel.DiagnosticObjectiveSelection, + }; + + courseService.UpdateCourseOptions(courseOptions, customisationId); + return RedirectToAction("Index", "ManageCourse", new { customisationId }); + } } } diff --git a/DigitalLearningSolutions.Web/ViewModels/TrackingSystem/CourseSetup/CourseDetails/CourseOptionsViewModel.cs b/DigitalLearningSolutions.Web/ViewModels/TrackingSystem/CourseSetup/CourseDetails/CourseOptionsViewModel.cs index 7f21d92b2f..ef131efb6a 100644 --- a/DigitalLearningSolutions.Web/ViewModels/TrackingSystem/CourseSetup/CourseDetails/CourseOptionsViewModel.cs +++ b/DigitalLearningSolutions.Web/ViewModels/TrackingSystem/CourseSetup/CourseDetails/CourseOptionsViewModel.cs @@ -10,8 +10,10 @@ public CourseOptionsViewModel(CourseDetails courseDetails) AllowSelfEnrolment = courseDetails.SelfRegister; DiagnosticObjectiveSelection = courseDetails.DiagObjSelect; HideInLearningPortal = courseDetails.HideInLearnerPortal; + CustomisationId = courseDetails.CustomisationId; } + public int CustomisationId { get; set; } public bool Active { get; set; } public bool AllowSelfEnrolment { get; set; } public bool DiagnosticObjectiveSelection { get; set; } diff --git a/DigitalLearningSolutions.Web/ViewModels/TrackingSystem/CourseSetup/CourseDetails/EditCourseOptionsViewModel.cs b/DigitalLearningSolutions.Web/ViewModels/TrackingSystem/CourseSetup/CourseDetails/EditCourseOptionsViewModel.cs new file mode 100644 index 0000000000..0ea38934fa --- /dev/null +++ b/DigitalLearningSolutions.Web/ViewModels/TrackingSystem/CourseSetup/CourseDetails/EditCourseOptionsViewModel.cs @@ -0,0 +1,56 @@ +namespace DigitalLearningSolutions.Web.ViewModels.TrackingSystem.CourseSetup.CourseDetails +{ + using System.Collections.Generic; + using DigitalLearningSolutions.Data.Models.Courses; + using DigitalLearningSolutions.Web.ViewModels.Common.ViewComponents; + + public class EditCourseOptionsViewModel + { + public readonly List Checkboxes = new List + { + new CheckboxListItemViewModel( + nameof(Active), + "Active", + "Active courses are open to new enrolments. Inactive courses are not." + ), + new CheckboxListItemViewModel( + nameof(AllowSelfEnrolment), + "Allow self-enrolment", + "The course will be in the Available courses list of the Learning Portal for self-enrolment." + ), + new CheckboxListItemViewModel( + nameof(HideInLearningPortal), + "Hide in Learning Portal", + "The course will not be visible to learners in the Learning Portal." + ), + }; + + public EditCourseOptionsViewModel(CourseOptions courseOptions, int customisationId) + { + Active = courseOptions.Active; + AllowSelfEnrolment = courseOptions.SelfRegister; + DiagnosticObjectiveSelection = courseOptions.DiagObjSelect; + HideInLearningPortal = courseOptions.HideInLearnerPortal; + CustomisationId = customisationId; + + if (courseOptions.DiagAssess) + { + Checkboxes.Add( + new CheckboxListItemViewModel( + nameof(DiagnosticObjectiveSelection), + "Allow diagnostic objective selection", + "Allow the learner to choose which objectives to be assessed against when starting a diagnostic assessment." + ) + ); + } + } + + public EditCourseOptionsViewModel() { } + + public int CustomisationId { get; set; } + public bool Active { get; set; } + public bool AllowSelfEnrolment { get; set; } + public bool DiagnosticObjectiveSelection { get; set; } + public bool HideInLearningPortal { get; set; } + } +} diff --git a/DigitalLearningSolutions.Web/Views/TrackingSystem/CourseSetup/ManageCourse/EditCourseOptions.cshtml b/DigitalLearningSolutions.Web/Views/TrackingSystem/CourseSetup/ManageCourse/EditCourseOptions.cshtml new file mode 100644 index 0000000000..7c1877d219 --- /dev/null +++ b/DigitalLearningSolutions.Web/Views/TrackingSystem/CourseSetup/ManageCourse/EditCourseOptions.cshtml @@ -0,0 +1,35 @@ +@inject IConfiguration Configuration; +@using DigitalLearningSolutions.Web.ViewModels.TrackingSystem.CourseSetup.CourseDetails +@using Microsoft.Extensions.Configuration +@using DigitalLearningSolutions.Web.Models.Enums +@model EditCourseOptionsViewModel + +@{ + ViewData["Title"] = "Edit course options"; + ViewData["Application"] = DlsSubApplication.TrackingSystem.HeaderExtension; + ViewData["HeaderPath"] = DlsSubApplication.TrackingSystem.HeaderPath; + ViewData["HeaderPathName"] = DlsSubApplication.TrackingSystem.HeaderPathName; + var cancelRouteData = new Dictionary { { "customisationId", Model.CustomisationId.ToString() } }; +} + +@section NavMenuItems { + +} + +
+
+

@ViewData["Title"]

+ +
+ + + + + + + +
+
diff --git a/DigitalLearningSolutions.Web/Views/TrackingSystem/CourseSetup/ManageCourse/_CourseOptionsExpandable.cshtml b/DigitalLearningSolutions.Web/Views/TrackingSystem/CourseSetup/ManageCourse/_CourseOptionsExpandable.cshtml index 41ec65a205..2db87035ba 100644 --- a/DigitalLearningSolutions.Web/Views/TrackingSystem/CourseSetup/ManageCourse/_CourseOptionsExpandable.cshtml +++ b/DigitalLearningSolutions.Web/Views/TrackingSystem/CourseSetup/ManageCourse/_CourseOptionsExpandable.cshtml @@ -11,37 +11,41 @@
-
- Active -
- -
+
+ Active +
+ +
-
-
- Allow self-enrolment -
- -
+
+
+ Allow self-enrolment +
+ +
-
-
- Hide in Learning Portal -
- -
+
+
+ Hide in Learning Portal +
+ +
-
-
- Allow diagnostic objective selection -
- -
- +
+
+ Allow diagnostic objective selection +
+ +
+ - - Edit - + + Edit + From b543cc9acc46a8a5959af07cac77706ec38c992c Mon Sep 17 00:00:00 2001 From: showkath10 <90783892+showkath10@users.noreply.github.com> Date: Mon, 25 Oct 2021 12:19:29 +0100 Subject: [PATCH 2/6] HEEDLS-445 Edit Couse Options Branch - tech lead review fixes --- .../DataServices/CourseDataServiceTests.cs | 51 ++++++++++++++-- .../Models/Courses/CourseOptions.cs | 11 +--- .../CourseSetup/ManageCourseController.cs | 18 ------ .../ManageCourse/EditCourseOptions.cshtml | 61 ++++++++----------- 4 files changed, 74 insertions(+), 67 deletions(-) diff --git a/DigitalLearningSolutions.Data.Tests/DataServices/CourseDataServiceTests.cs b/DigitalLearningSolutions.Data.Tests/DataServices/CourseDataServiceTests.cs index 62a5df2356..08b2802839 100644 --- a/DigitalLearningSolutions.Data.Tests/DataServices/CourseDataServiceTests.cs +++ b/DigitalLearningSolutions.Data.Tests/DataServices/CourseDataServiceTests.cs @@ -452,9 +452,11 @@ public void UpdateLearningPathwayDefaultsForCourse_correctly_updates_learning_pa } [Test] - public void Edit_Course_Options_updates_course_options_successfully() + public void UpdateCourseOptions_updates_course_options_successfully() { using var transaction = new TransactionScope(); + + //Given const int customisationId = 100; const int centreId = 101; const int categoryId = 0; @@ -493,9 +495,10 @@ public void Edit_Course_Options_updates_course_options_successfully() } [Test] - public void Edit_Course_Options_get_course_options_for_admin_categoryId() + public void GetCourseOptionsForAdminCategoryId_gets_correct_data_for_valid_centre_and_category_Id() { - const int customisationId = 100; + //Given + const int customisationId = 1379; const int centreId = 101; const int categoryId = 0; @@ -509,11 +512,49 @@ public void Edit_Course_Options_get_course_options_for_admin_categoryId() // Then using (new AssertionScope()) { - updatedCourseOptions?.Active.Should().BeFalse(); + updatedCourseOptions?.Active.Should().BeTrue(); updatedCourseOptions?.DiagObjSelect.Should().BeTrue(); updatedCourseOptions?.SelfRegister.Should().BeTrue(); - updatedCourseOptions?.HideInLearnerPortal.Should().BeFalse(); + updatedCourseOptions?.HideInLearnerPortal.Should().BeTrue(); } } + + [Test] + public void GetCourseOptionsForAdminCategoryId_with_incorrect_centerId_and_correct_customisationId_and_categoryId() + { + //Given + const int customisationId = 1379; + const int centreId = 5; + const int categoryId = 0; + + // When + var updatedCourseOptions = courseDataService.GetCourseOptionsForAdminCategoryId( + customisationId, + centreId, + categoryId + ); + + // Then + updatedCourseOptions.Should().BeNull(); + } + + [Test] + public void GetCourseOptionsForAdminCategoryId_with_incorrect_categoryId_and_correct_customisationId_and_centerId() + { + //Given + const int customisationId = 1379; + const int centreId = 101; + const int categoryId = 10; + + // When + var updatedCourseOptions = courseDataService.GetCourseOptionsForAdminCategoryId( + customisationId, + centreId, + categoryId + ); + + // Then + updatedCourseOptions.Should().BeNull(); + } } } diff --git a/DigitalLearningSolutions.Data/Models/Courses/CourseOptions.cs b/DigitalLearningSolutions.Data/Models/Courses/CourseOptions.cs index 77c0205dd4..66067981bf 100644 --- a/DigitalLearningSolutions.Data/Models/Courses/CourseOptions.cs +++ b/DigitalLearningSolutions.Data/Models/Courses/CourseOptions.cs @@ -1,15 +1,6 @@ namespace DigitalLearningSolutions.Data.Models.Courses { - public interface ICourseOptions - { - public bool Active { get; set; } - public bool SelfRegister { get; set; } - public bool HideInLearnerPortal { get; set; } - public bool DiagObjSelect { get; set; } - public bool DiagAssess { get; set; } - } - - public class CourseOptions : ICourseOptions + public class CourseOptions { public bool Active { get; set; } public bool SelfRegister { get; set; } diff --git a/DigitalLearningSolutions.Web/Controllers/TrackingSystem/CourseSetup/ManageCourseController.cs b/DigitalLearningSolutions.Web/Controllers/TrackingSystem/CourseSetup/ManageCourseController.cs index a0c482fab0..4815f337c2 100644 --- a/DigitalLearningSolutions.Web/Controllers/TrackingSystem/CourseSetup/ManageCourseController.cs +++ b/DigitalLearningSolutions.Web/Controllers/TrackingSystem/CourseSetup/ManageCourseController.cs @@ -107,13 +107,6 @@ public IActionResult EditCourseOptions(int customisationId) var centreId = User.GetCentreId(); var categoryId = User.GetAdminCategoryId()!; - if (!courseService.VerifyAdminUserCanAccessCourse( - customisationId, - centreId, categoryId.GetValueOrDefault())) - { - return NotFound(); - } - var courseOptions = courseService.GetCourseOptionsForAdminCategoryId( customisationId, centreId, @@ -131,17 +124,6 @@ public IActionResult EditCourseOptions( EditCourseOptionsViewModel editCourseOptionsViewModel ) { - var centreId = User.GetCentreId(); - var categoryId = User.GetAdminCategoryId()!; - - if (!courseService.VerifyAdminUserCanAccessCourse( - customisationId, - centreId, - categoryId.GetValueOrDefault())) - { - return NotFound(); - } - var courseOptions = new CourseOptions { Active = editCourseOptionsViewModel.Active, diff --git a/DigitalLearningSolutions.Web/Views/TrackingSystem/CourseSetup/ManageCourse/EditCourseOptions.cshtml b/DigitalLearningSolutions.Web/Views/TrackingSystem/CourseSetup/ManageCourse/EditCourseOptions.cshtml index 7c1877d219..75aad119c5 100644 --- a/DigitalLearningSolutions.Web/Views/TrackingSystem/CourseSetup/ManageCourse/EditCourseOptions.cshtml +++ b/DigitalLearningSolutions.Web/Views/TrackingSystem/CourseSetup/ManageCourse/EditCourseOptions.cshtml @@ -1,35 +1,28 @@ -@inject IConfiguration Configuration; -@using DigitalLearningSolutions.Web.ViewModels.TrackingSystem.CourseSetup.CourseDetails -@using Microsoft.Extensions.Configuration -@using DigitalLearningSolutions.Web.Models.Enums -@model EditCourseOptionsViewModel - +@inject IConfiguration Configuration; +@using DigitalLearningSolutions.Web.ViewModels.TrackingSystem.CourseSetup.CourseDetails +@using Microsoft.Extensions.Configuration +@using DigitalLearningSolutions.Web.Models.Enums +@model EditCourseOptionsViewModel + @{ - ViewData["Title"] = "Edit course options"; - ViewData["Application"] = DlsSubApplication.TrackingSystem.HeaderExtension; - ViewData["HeaderPath"] = DlsSubApplication.TrackingSystem.HeaderPath; - ViewData["HeaderPathName"] = DlsSubApplication.TrackingSystem.HeaderPathName; - var cancelRouteData = new Dictionary { { "customisationId", Model.CustomisationId.ToString() } }; -} - -@section NavMenuItems { - -} - -
-
-

@ViewData["Title"]

- -
- - - - - - - -
-
+ ViewData["Title"] = "Edit course options"; + var cancelRouteData = new Dictionary { { "customisationId", Model.CustomisationId.ToString() } }; +} + +
+
+

@ViewData["Title"]

+ +
+ + + + + + + +
+
From c94ba84ac0634bce489e264a9f9d802278339213 Mon Sep 17 00:00:00 2001 From: showkath10 <90783892+showkath10@users.noreply.github.com> Date: Fri, 29 Oct 2021 00:59:42 +0100 Subject: [PATCH 3/6] HEEDLS-445 Edit course options - tech lead review fix --- .../DataServices/CourseDataServiceTests.cs | 12 +++--- .../ManageCourseControllerTests.cs | 42 +++++++++---------- .../ManageCourse/EditCourseOptions.cshtml | 1 - 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/DigitalLearningSolutions.Data.Tests/DataServices/CourseDataServiceTests.cs b/DigitalLearningSolutions.Data.Tests/DataServices/CourseDataServiceTests.cs index 08b2802839..d43e257f0e 100644 --- a/DigitalLearningSolutions.Data.Tests/DataServices/CourseDataServiceTests.cs +++ b/DigitalLearningSolutions.Data.Tests/DataServices/CourseDataServiceTests.cs @@ -456,7 +456,7 @@ public void UpdateCourseOptions_updates_course_options_successfully() { using var transaction = new TransactionScope(); - //Given + // Given const int customisationId = 100; const int centreId = 101; const int categoryId = 0; @@ -497,7 +497,7 @@ public void UpdateCourseOptions_updates_course_options_successfully() [Test] public void GetCourseOptionsForAdminCategoryId_gets_correct_data_for_valid_centre_and_category_Id() { - //Given + // Given const int customisationId = 1379; const int centreId = 101; const int categoryId = 0; @@ -520,9 +520,9 @@ public void GetCourseOptionsForAdminCategoryId_gets_correct_data_for_valid_centr } [Test] - public void GetCourseOptionsForAdminCategoryId_with_incorrect_centerId_and_correct_customisationId_and_categoryId() + public void GetCourseOptionsForAdminCategoryId_with_incorrect_centerId_and_correct_customisationId_and_categoryId_returns_null() { - //Given + // Given const int customisationId = 1379; const int centreId = 5; const int categoryId = 0; @@ -539,9 +539,9 @@ public void GetCourseOptionsForAdminCategoryId_with_incorrect_centerId_and_corre } [Test] - public void GetCourseOptionsForAdminCategoryId_with_incorrect_categoryId_and_correct_customisationId_and_centerId() + public void GetCourseOptionsForAdminCategoryId_with_incorrect_categoryId_and_correct_customisationId_and_centerId_returns_null() { - //Given + // Given const int customisationId = 1379; const int centreId = 101; const int categoryId = 10; diff --git a/DigitalLearningSolutions.Web.Tests/Controllers/TrackingSystem/CourseSetup/ManageCourseControllerTests.cs b/DigitalLearningSolutions.Web.Tests/Controllers/TrackingSystem/CourseSetup/ManageCourseControllerTests.cs index 22bba252d2..50a8d2e745 100644 --- a/DigitalLearningSolutions.Web.Tests/Controllers/TrackingSystem/CourseSetup/ManageCourseControllerTests.cs +++ b/DigitalLearningSolutions.Web.Tests/Controllers/TrackingSystem/CourseSetup/ManageCourseControllerTests.cs @@ -1,14 +1,20 @@ namespace DigitalLearningSolutions.Web.Tests.Controllers.TrackingSystem.CourseSetup { - using DigitalLearningSolutions.Data.DataServices; using DigitalLearningSolutions.Data.Models.Courses; using DigitalLearningSolutions.Data.Services; using DigitalLearningSolutions.Web.Controllers.TrackingSystem.CourseSetup; + using DigitalLearningSolutions.Web.ServiceFilter; using DigitalLearningSolutions.Web.Tests.ControllerHelpers; using DigitalLearningSolutions.Web.ViewModels.TrackingSystem.CourseSetup.CourseDetails; using FakeItEasy; using FluentAssertions.AspNetCore.Mvc; + using Microsoft.AspNetCore.Http; + using Microsoft.AspNetCore.Mvc; + using Microsoft.AspNetCore.Mvc.Abstractions; + using Microsoft.AspNetCore.Mvc.Filters; + using Microsoft.AspNetCore.Routing; using NUnit.Framework; + using System.Collections.Generic; internal class ManageCourseControllerTests { @@ -185,30 +191,24 @@ public void Edit_Course_Options_page_redirects_to_Index_when_course_details_are_ public void Edit_Course_Options_redirects_to_not_found_page_when_admin_user_cannot_access_course() { // Given - const int customisationId = 1; - A.CallTo( - () => courseService.VerifyAdminUserCanAccessCourse( - customisationId, - A._, - A._ - ) - ).Returns(false); - - A.CallTo( - () => courseService.GetCourseOptionsForAdminCategoryId( - customisationId, - A._, - A._ - ) - ).Returns(new CourseOptions()); - + const int centreId = 101; + var context = new ActionExecutingContext( + new ActionContext( + new DefaultHttpContext(), + new RouteData(new RouteValueDictionary() { { "customisationId", "1" }}), + new ActionDescriptor() + ), + new List(), + new Dictionary(), + new ManageCourseController(A.Fake()).WithDefaultContext(). + WithMockUser(true, centreId: centreId) + ); // When - var result = controller.EditCourseOptions(customisationId); + new VerifyAdminUserCanAccessCourse(courseService).OnActionExecuting(context); // Then - result.Should().BeNotFoundResult(); + context.Result.Should().BeNotFoundResult(); } - } } diff --git a/DigitalLearningSolutions.Web/Views/TrackingSystem/CourseSetup/ManageCourse/EditCourseOptions.cshtml b/DigitalLearningSolutions.Web/Views/TrackingSystem/CourseSetup/ManageCourse/EditCourseOptions.cshtml index 75aad119c5..539231550f 100644 --- a/DigitalLearningSolutions.Web/Views/TrackingSystem/CourseSetup/ManageCourse/EditCourseOptions.cshtml +++ b/DigitalLearningSolutions.Web/Views/TrackingSystem/CourseSetup/ManageCourse/EditCourseOptions.cshtml @@ -1,7 +1,6 @@ @inject IConfiguration Configuration; @using DigitalLearningSolutions.Web.ViewModels.TrackingSystem.CourseSetup.CourseDetails @using Microsoft.Extensions.Configuration -@using DigitalLearningSolutions.Web.Models.Enums @model EditCourseOptionsViewModel @{ From 2daca762cd62ad974cf6adfa15c4a61236055887 Mon Sep 17 00:00:00 2001 From: showkath10 <90783892+showkath10@users.noreply.github.com> Date: Fri, 29 Oct 2021 01:17:46 +0100 Subject: [PATCH 4/6] Merge from previous commit --- .../CourseSetup/ManageCourse/_CourseOptionsExpandable.cshtml | 1 + 1 file changed, 1 insertion(+) diff --git a/DigitalLearningSolutions.Web/Views/TrackingSystem/CourseSetup/ManageCourse/_CourseOptionsExpandable.cshtml b/DigitalLearningSolutions.Web/Views/TrackingSystem/CourseSetup/ManageCourse/_CourseOptionsExpandable.cshtml index 2db87035ba..d30a45bb2f 100644 --- a/DigitalLearningSolutions.Web/Views/TrackingSystem/CourseSetup/ManageCourse/_CourseOptionsExpandable.cshtml +++ b/DigitalLearningSolutions.Web/Views/TrackingSystem/CourseSetup/ManageCourse/_CourseOptionsExpandable.cshtml @@ -41,6 +41,7 @@ From bcf7cf1d2188509b47f87db95073df514e1e408f Mon Sep 17 00:00:00 2001 From: showkath10 <90783892+showkath10@users.noreply.github.com> Date: Fri, 29 Oct 2021 01:42:48 +0100 Subject: [PATCH 5/6] HEEDLS-445 Unit test case fix --- .../TrackingSystem/CourseSetup/ManageCourseControllerTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DigitalLearningSolutions.Web.Tests/Controllers/TrackingSystem/CourseSetup/ManageCourseControllerTests.cs b/DigitalLearningSolutions.Web.Tests/Controllers/TrackingSystem/CourseSetup/ManageCourseControllerTests.cs index 50a8d2e745..a1bae949e2 100644 --- a/DigitalLearningSolutions.Web.Tests/Controllers/TrackingSystem/CourseSetup/ManageCourseControllerTests.cs +++ b/DigitalLearningSolutions.Web.Tests/Controllers/TrackingSystem/CourseSetup/ManageCourseControllerTests.cs @@ -205,7 +205,7 @@ public void Edit_Course_Options_redirects_to_not_found_page_when_admin_user_cann ); // When - new VerifyAdminUserCanAccessCourse(courseService).OnActionExecuting(context); + new VerifyAdminUserCanAccessCourse(A.Fake()).OnActionExecuting(context); // Then context.Result.Should().BeNotFoundResult(); From 5d763c5e00a9e4e5495415cb0a482ddac7cf5414 Mon Sep 17 00:00:00 2001 From: showkath10 <90783892+showkath10@users.noreply.github.com> Date: Fri, 29 Oct 2021 11:46:11 +0100 Subject: [PATCH 6/6] HEEDLS-445 Edit Course Options --- .editorconfig | 1 + .../ManageCourseControllerTests.cs | 24 ------------------- 2 files changed, 1 insertion(+), 24 deletions(-) diff --git a/.editorconfig b/.editorconfig index 31cf658535..8c175e1211 100644 --- a/.editorconfig +++ b/.editorconfig @@ -8,6 +8,7 @@ trim_trailing_whitespace = true encoding = utf-8-bom # ReSharper properties +resharper_csharp_blank_lines_around_single_line_invocable = 1 resharper_csharp_wrap_after_declaration_lpar = true resharper_csharp_wrap_after_invocation_lpar = true resharper_csharp_wrap_arguments_style = chop_if_long diff --git a/DigitalLearningSolutions.Web.Tests/Controllers/TrackingSystem/CourseSetup/ManageCourseControllerTests.cs b/DigitalLearningSolutions.Web.Tests/Controllers/TrackingSystem/CourseSetup/ManageCourseControllerTests.cs index a1bae949e2..d293f6cbce 100644 --- a/DigitalLearningSolutions.Web.Tests/Controllers/TrackingSystem/CourseSetup/ManageCourseControllerTests.cs +++ b/DigitalLearningSolutions.Web.Tests/Controllers/TrackingSystem/CourseSetup/ManageCourseControllerTests.cs @@ -186,29 +186,5 @@ public void Edit_Course_Options_page_redirects_to_Index_when_course_details_are_ result.Should().BeRedirectToActionResult().WithControllerName("ManageCourse").WithActionName("Index"); } - - [Test] - public void Edit_Course_Options_redirects_to_not_found_page_when_admin_user_cannot_access_course() - { - // Given - const int centreId = 101; - var context = new ActionExecutingContext( - new ActionContext( - new DefaultHttpContext(), - new RouteData(new RouteValueDictionary() { { "customisationId", "1" }}), - new ActionDescriptor() - ), - new List(), - new Dictionary(), - new ManageCourseController(A.Fake()).WithDefaultContext(). - WithMockUser(true, centreId: centreId) - ); - - // When - new VerifyAdminUserCanAccessCourse(A.Fake()).OnActionExecuting(context); - - // Then - context.Result.Should().BeNotFoundResult(); - } } }