Skip to content

Commit 8d07f0c

Browse files
authored
Merge pull request #3019 from TechnologyEnhancedLearning/DLS-Release-v1.1.1
Dls release v1.1.1 to DEV
2 parents afe95a7 + 4b0e1f9 commit 8d07f0c

File tree

11 files changed

+82
-49
lines changed

11 files changed

+82
-49
lines changed

DigitalLearningSolutions.Data/DataServices/CourseDataService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ int EnrolOnActivitySelfAssessment(int selfAssessmentId, int candidateId, int sup
139139
public IEnumerable<DelegateAssessmentStatistics> GetDelegateAssessmentStatisticsAtCentre(string searchString, int centreId, string categoryName, string isActive, int? categoryId);
140140

141141
bool IsSelfEnrollmentAllowed(int customisationId);
142-
Customisation? GetCourse(int customisationId);
142+
Customisation? GetCourse(int? customisationId);
143143
}
144144

145145
public class CourseDataService : ICourseDataService
@@ -2024,7 +2024,7 @@ public bool IsSelfEnrollmentAllowed(int customisationId)
20242024
return selfRegister > 0;
20252025
}
20262026

2027-
public Customisation? GetCourse(int customisationId)
2027+
public Customisation? GetCourse(int? customisationId)
20282028
{
20292029
return connection.Query<Customisation>(
20302030
@"SELECT CustomisationID

DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/CandidateAssessmentsDataService.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
public partial class SelfAssessmentDataService
1010
{
11-
public IEnumerable<CurrentSelfAssessment> GetSelfAssessmentsForCandidate(int delegateUserId, int centreId)
11+
public IEnumerable<CurrentSelfAssessment> GetSelfAssessmentsForCandidate(int delegateUserId, int centreId, int? adminCategoryId)
1212
{
1313
return connection.Query<CurrentSelfAssessment>(
1414
@"SELECT SelfAssessment.Id,
@@ -67,7 +67,7 @@ Competencies AS C RIGHT OUTER JOIN
6767
CandidateAssessmentSupervisorVerifications AS casv ON casv.CandidateAssessmentSupervisorID = cas.ID LEFT OUTER JOIN
6868
AdminAccounts AS aaEnrolledBy ON aaEnrolledBy.ID = CA.EnrolledByAdminID LEFT OUTER JOIN
6969
Users AS uEnrolledBy ON uEnrolledBy.ID = aaEnrolledBy.UserID
70-
WHERE (CA.DelegateUserID = @delegateUserId) AND (CA.RemovedDate IS NULL) AND (CA.CompletedDate IS NULL)
70+
WHERE (CA.DelegateUserID = @delegateUserId) AND (CA.RemovedDate IS NULL) AND (CA.CompletedDate IS NULL) AND (ISNULL(@adminCategoryId, 0) = 0 OR sa.CategoryID = @adminCategoryId)
7171
GROUP BY
7272
CA.SelfAssessmentID, SA.Name, SA.Description, SA.IncludesSignposting, SA.SupervisorResultsReview,
7373
SA.ReviewerCommentsLabel, SA.IncludeRequirementsFilters,
@@ -83,7 +83,7 @@ CandidateAssessments AS CA LEFT OUTER JOIN
8383
(casv.Verified IS NOT NULL)
8484
GROUP BY SelfAssessmentID,casv.SignedOff
8585
)Signoff ON SelfAssessment.Id =Signoff.SelfAssessmentID",
86-
new { delegateUserId, centreId }
86+
new { delegateUserId, centreId, adminCategoryId }
8787
);
8888
}
8989

DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/SelfAssessmentDataService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ int competencyId
7272

7373
// CandidateAssessmentsDataService
7474

75-
IEnumerable<CurrentSelfAssessment> GetSelfAssessmentsForCandidate(int delegateUserId, int centreId);
75+
IEnumerable<CurrentSelfAssessment> GetSelfAssessmentsForCandidate(int delegateUserId, int centreId, int? adminCategoryId);
7676

7777
CurrentSelfAssessment? GetSelfAssessmentForCandidateById(int delegateUserId, int selfAssessmentId);
7878

DigitalLearningSolutions.Data/Helpers/FilteringHelper.cs

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ public static string BuildFilterValueString(string group, string propertyName, s
6666
? defaultFilterValue
6767
: AddNewFilterToFilterString(existingFilterString, newFilterToAdd);
6868
}
69-
70-
public static string? GetCategoryAndTopicFilterString(
69+
public static string? GetCategoryAndTopicFilterString(
7170
string? categoryFilterString,
7271
string? topicFilterString
7372
)
@@ -168,7 +167,59 @@ public static string GetFilterValueForRegistrationPrompt(int promptNumber, strin
168167
: answer;
169168
return BuildFilterValueString(group, group.Split('(')[0], propertyValue);
170169
}
170+
public static string? GetValidFilters(string existingFilterString, string newFilterToAdd, IEnumerable<FilterModel> availableFilters, HttpRequest request, string cookieName)
171+
{
172+
var cookieValue = request.Cookies[cookieName];
173+
if (string.IsNullOrEmpty(cookieValue) || cookieValue == EmptyFiltersCookieValue)
174+
{
175+
return existingFilterString;
176+
}
177+
var existingFilters = cookieValue.Split(FilterSeparator);
178+
var validFilterValues = availableFilters
179+
.SelectMany(filter => filter.FilterOptions)
180+
.Select(option => option.FilterValue)
181+
.ToHashSet();
182+
183+
var filteredResults = existingFilters
184+
.Where(entry => IsFilterInvalid(entry, validFilterValues))
185+
.ToList();
186+
var newCookieValue = string.Join(FilterSeparator, filteredResults);
187+
if (string.IsNullOrEmpty(newCookieValue)) return null;
188+
newCookieValue = AddNewFilterToFilterString(newCookieValue, newFilterToAdd);
189+
return RemoveDuplicateFilters( newFilterToAdd, newCookieValue);
190+
}
171191

192+
private static bool IsFilterInvalid(string filterEntry, HashSet<string> validFilterValues)
193+
{
194+
if (validFilterValues.Contains(filterEntry)) return true;
195+
return false;
196+
}
197+
public static string RemoveDuplicateFilters(string newFilterToAdd, string? existingFilterString)
198+
{
199+
if (string.IsNullOrEmpty(existingFilterString))
200+
{
201+
return existingFilterString ?? string.Empty;
202+
}
203+
var selectedFilters = existingFilterString.Split(FilteringHelper.FilterSeparator).ToList();
204+
if (!string.IsNullOrEmpty(newFilterToAdd))
205+
{
206+
var filterHeader = newFilterToAdd.Split(FilteringHelper.Separator)[0];
207+
var dupfilters = selectedFilters.Where(x => x.Contains(filterHeader));
208+
if (dupfilters.Count() > 1)
209+
{
210+
foreach (var filter in selectedFilters)
211+
{
212+
if (filter.Contains(filterHeader))
213+
{
214+
selectedFilters.Remove(filter);
215+
existingFilterString = string.Join(FilteringHelper.FilterSeparator, selectedFilters);
216+
break;
217+
}
218+
}
219+
}
220+
}
221+
return existingFilterString;
222+
}
172223
private static IEnumerable<FilterOptionModel> GetFilterOptionsForPromptWithOptions(Prompt prompt)
173224
{
174225
var group = GetFilterGroupForPrompt(prompt);

DigitalLearningSolutions.Web.Tests/Controllers/LearningPortal/CurrentTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ bool apiIsAccessible
4444

4545
var bannerText = "bannerText";
4646
A.CallTo(() => courseService.GetCurrentCourses(CandidateId)).Returns(currentCourses);
47-
A.CallTo(() => selfAssessmentService.GetSelfAssessmentsForCandidate(DelegateUserId, A<int>._)).Returns(selfAssessments);
47+
A.CallTo(() => selfAssessmentService.GetSelfAssessmentsForCandidate(DelegateUserId, A<int>._, A<int>._)).Returns(selfAssessments);
4848
A.CallTo(() => actionPlanService.GetIncompleteActionPlanResources(DelegateUserId))
4949
.Returns((actionPlanResources, apiIsAccessible));
5050
A.CallTo(() => centresService.GetBannerText(CentreId)).Returns(bannerText);
@@ -426,7 +426,7 @@ public void MarkActionPlanResourceAsComplete_does_not_call_service_with_invalid_
426426
private void GivenCurrentActivitiesAreEmptyLists()
427427
{
428428
A.CallTo(() => courseService.GetCurrentCourses(A<int>._)).Returns(new List<CurrentCourse>());
429-
A.CallTo(() => selfAssessmentService.GetSelfAssessmentsForCandidate(A<int>._, A<int>._))
429+
A.CallTo(() => selfAssessmentService.GetSelfAssessmentsForCandidate(A<int>._, A<int>._, A<int>._))
430430
.Returns(new List<CurrentSelfAssessment>());
431431
A.CallTo(() => actionPlanService.GetIncompleteActionPlanResources(A<int>._))
432432
.Returns((new List<ActionPlanResource>(), false));

DigitalLearningSolutions.Web/Controllers/LearningPortalController/Current.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public async Task<IActionResult> Current(
4444

4545
var centreId = User.GetCentreIdKnownNotNull();
4646
var selfAssessments =
47-
selfAssessmentService.GetSelfAssessmentsForCandidate(delegateUserId, centreId);
47+
selfAssessmentService.GetSelfAssessmentsForCandidate(delegateUserId, centreId, 0);
4848

4949
var (learningResources, apiIsAccessible) =
5050
await GetIncompleteActionPlanResourcesIfSignpostingEnabled(delegateUserId);
@@ -81,7 +81,7 @@ public async Task<IActionResult> AllCurrentItems()
8181
var centreId = User.GetCentreIdKnownNotNull();
8282

8383
var selfAssessment =
84-
selfAssessmentService.GetSelfAssessmentsForCandidate(delegateUserId, centreId);
84+
selfAssessmentService.GetSelfAssessmentsForCandidate(delegateUserId, centreId, 0);
8585

8686
var (learningResources, _) = await GetIncompleteActionPlanResourcesIfSignpostingEnabled(delegateUserId);
8787
var model = new AllCurrentItemsPageViewModel(currentCourses, selfAssessment, learningResources);

DigitalLearningSolutions.Web/Controllers/Register/ClaimAccountController.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -297,22 +297,18 @@ public IActionResult AdminAccountAlreadyExists(string email, string centreName)
297297
return RedirectToAction("AccessDenied", "LearningSolutions");
298298
}
299299

300-
var adminAccounts = userService.GetUserById(loggedInUserId)!.AdminAccounts;
300+
var userEntity = userService.GetUserById(loggedInUserId);
301301

302-
if (adminAccounts.Any())
302+
if (userEntity.DelegateAccounts!.Any(account => account.CentreId == model.CentreId))
303303
{
304-
return RedirectToAction(
305-
"AdminAccountAlreadyExists",
304+
return RedirectToAction("AccountAlreadyExists",
306305
new { email = model.Email, centreName = model.CentreName }
307306
);
308307
}
309308

310-
var delegateAccounts = userService.GetUserById(loggedInUserId)!.DelegateAccounts;
311-
312-
if (delegateAccounts.Any(account => account.CentreId == model.CentreId))
309+
if (userEntity.AdminAccounts!.Any(account => account.CentreId == model.CentreId))
313310
{
314-
return RedirectToAction(
315-
"AccountAlreadyExists",
311+
return RedirectToAction("AdminAccountAlreadyExists",
316312
new { email = model.Email, centreName = model.CentreName }
317313
);
318314
}

DigitalLearningSolutions.Web/Controllers/TrackingSystem/Delegates/ActivityDelegatesController.cs

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ public IActionResult Index(
9595

9696
sortBy ??= DefaultSortByOptions.Name.PropertyName;
9797
sortDirection ??= GenericSortingHelper.Ascending;
98-
99-
existingFilterString = FilteringHelper.GetFilterString(
98+
existingFilterString = FilteringHelper.GetFilterString(
10099
existingFilterString,
101100
newFilterToAdd,
102101
clearFilters,
@@ -142,25 +141,7 @@ public IActionResult Index(
142141
if (!string.IsNullOrEmpty(existingFilterString))
143142
{
144143
var selectedFilters = existingFilterString.Split(FilteringHelper.FilterSeparator).ToList();
145-
146-
if (!string.IsNullOrEmpty(newFilterToAdd))
147-
{
148-
var filterHeader = newFilterToAdd.Split(FilteringHelper.Separator)[0];
149-
var dupfilters = selectedFilters.Where(x => x.Contains(filterHeader));
150-
if (dupfilters.Count() > 1)
151-
{
152-
foreach (var filter in selectedFilters)
153-
{
154-
if (filter.Contains(filterHeader))
155-
{
156-
selectedFilters.Remove(filter);
157-
existingFilterString = string.Join(FilteringHelper.FilterSeparator, selectedFilters);
158-
break;
159-
}
160-
}
161-
}
162-
}
163-
144+
existingFilterString = FilteringHelper.RemoveDuplicateFilters(newFilterToAdd, existingFilterString);
164145
if (selectedFilters.Count > 0)
165146
{
166147
foreach (var filter in selectedFilters)
@@ -276,7 +257,10 @@ public IActionResult Index(
276257
var activityName = isCourseDelegate
277258
? courseService.GetCourseNameAndApplication((int)customisationId).CourseName
278259
: selfAssessmentService.GetSelfAssessmentNameById((int)selfAssessmentId);
279-
260+
if (!string.IsNullOrEmpty(existingFilterString))
261+
{
262+
existingFilterString = FilteringHelper.GetValidFilters( existingFilterString, newFilterToAdd, availableFilters, Request, filterCookieName);
263+
}
280264
if (isCourseDelegate)
281265
{
282266
var result = paginateService.Paginate(
@@ -591,6 +575,7 @@ DelegateAccessRoute accessedVia
591575
return RedirectToAction("Index", "ActivityDelegates", routeData, returnPageQuery.Value.ItemIdToReturnTo);
592576
}
593577
}
578+
594579
}
595580
}
596581

DigitalLearningSolutions.Web/Controllers/TrackingSystem/Delegates/ViewDelegateController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,10 @@ public IActionResult Index(int delegateId, string? callType)
8181
course.LastUpdated = DateHelper.GetLocalDateTime(course.LastUpdated);
8282
course.Completed = course.Completed?.TimeOfDay == TimeSpan.Zero ? course.Completed : DateHelper.GetLocalDateTime(course.Completed);
8383
}
84+
8485

8586
var selfAssessments =
86-
selfAssessmentService.GetSelfAssessmentsForCandidate(delegateEntity.UserAccount.Id, centreId);
87+
selfAssessmentService.GetSelfAssessmentsForCandidate(delegateEntity.UserAccount.Id, centreId, categoryIdFilter);
8788

8889
foreach (var selfassessment in selfAssessments)
8990
{

DigitalLearningSolutions.Web/Services/CourseService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ int diagCompletionThreshold
134134
int GetNumberOfActiveCoursesAtCentreFilteredByCategory(int centreId, int? categoryId);
135135
public IEnumerable<Course> GetApplicationsAvailableToCentre(int centreId);
136136
bool IsSelfEnrollmentAllowed(int customisationId);
137-
Customisation? GetCourse(int customisationId);
137+
Customisation? GetCourse(int? customisationId);
138138
}
139139

140140
public class CourseService : ICourseService
@@ -632,7 +632,7 @@ public bool IsSelfEnrollmentAllowed(int customisationId)
632632
return courseDataService.IsSelfEnrollmentAllowed(customisationId);
633633
}
634634

635-
public Customisation? GetCourse(int customisationId)
635+
public Customisation? GetCourse(int? customisationId)
636636
{
637637
return courseDataService.GetCourse(customisationId);
638638
}

0 commit comments

Comments
 (0)