Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ int EnrolOnActivitySelfAssessment(int selfAssessmentId, int candidateId, int sup
public IEnumerable<DelegateAssessmentStatistics> GetDelegateAssessmentStatisticsAtCentre(string searchString, int centreId, string categoryName, string isActive, int? categoryId);

bool IsSelfEnrollmentAllowed(int customisationId);
Customisation? GetCourse(int customisationId);
Customisation? GetCourse(int? customisationId);
}

public class CourseDataService : ICourseDataService
Expand Down Expand Up @@ -2024,7 +2024,7 @@ public bool IsSelfEnrollmentAllowed(int customisationId)
return selfRegister > 0;
}

public Customisation? GetCourse(int customisationId)
public Customisation? GetCourse(int? customisationId)
{
return connection.Query<Customisation>(
@"SELECT CustomisationID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public partial class SelfAssessmentDataService
{
public IEnumerable<CurrentSelfAssessment> GetSelfAssessmentsForCandidate(int delegateUserId, int centreId)
public IEnumerable<CurrentSelfAssessment> GetSelfAssessmentsForCandidate(int delegateUserId, int centreId, int? adminCategoryId)
{
return connection.Query<CurrentSelfAssessment>(
@"SELECT SelfAssessment.Id,
Expand Down Expand Up @@ -67,7 +67,7 @@ Competencies AS C RIGHT OUTER JOIN
CandidateAssessmentSupervisorVerifications AS casv ON casv.CandidateAssessmentSupervisorID = cas.ID LEFT OUTER JOIN
AdminAccounts AS aaEnrolledBy ON aaEnrolledBy.ID = CA.EnrolledByAdminID LEFT OUTER JOIN
Users AS uEnrolledBy ON uEnrolledBy.ID = aaEnrolledBy.UserID
WHERE (CA.DelegateUserID = @delegateUserId) AND (CA.RemovedDate IS NULL) AND (CA.CompletedDate IS NULL)
WHERE (CA.DelegateUserID = @delegateUserId) AND (CA.RemovedDate IS NULL) AND (CA.CompletedDate IS NULL) AND (ISNULL(@adminCategoryId, 0) = 0 OR sa.CategoryID = @adminCategoryId)
GROUP BY
CA.SelfAssessmentID, SA.Name, SA.Description, SA.IncludesSignposting, SA.SupervisorResultsReview,
SA.ReviewerCommentsLabel, SA.IncludeRequirementsFilters,
Expand All @@ -83,7 +83,7 @@ CandidateAssessments AS CA LEFT OUTER JOIN
(casv.Verified IS NOT NULL)
GROUP BY SelfAssessmentID,casv.SignedOff
)Signoff ON SelfAssessment.Id =Signoff.SelfAssessmentID",
new { delegateUserId, centreId }
new { delegateUserId, centreId, adminCategoryId }
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ int competencyId

// CandidateAssessmentsDataService

IEnumerable<CurrentSelfAssessment> GetSelfAssessmentsForCandidate(int delegateUserId, int centreId);
IEnumerable<CurrentSelfAssessment> GetSelfAssessmentsForCandidate(int delegateUserId, int centreId, int? adminCategoryId);

CurrentSelfAssessment? GetSelfAssessmentForCandidateById(int delegateUserId, int selfAssessmentId);

Expand Down
55 changes: 53 additions & 2 deletions DigitalLearningSolutions.Data/Helpers/FilteringHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ public static string BuildFilterValueString(string group, string propertyName, s
? defaultFilterValue
: AddNewFilterToFilterString(existingFilterString, newFilterToAdd);
}

public static string? GetCategoryAndTopicFilterString(
public static string? GetCategoryAndTopicFilterString(
string? categoryFilterString,
string? topicFilterString
)
Expand Down Expand Up @@ -168,7 +167,59 @@ public static string GetFilterValueForRegistrationPrompt(int promptNumber, strin
: answer;
return BuildFilterValueString(group, group.Split('(')[0], propertyValue);
}
public static string? GetValidFilters(string existingFilterString, string newFilterToAdd, IEnumerable<FilterModel> availableFilters, HttpRequest request, string cookieName)
{
var cookieValue = request.Cookies[cookieName];
if (string.IsNullOrEmpty(cookieValue) || cookieValue == EmptyFiltersCookieValue)
{
return existingFilterString;
}
var existingFilters = cookieValue.Split(FilterSeparator);
var validFilterValues = availableFilters
.SelectMany(filter => filter.FilterOptions)
.Select(option => option.FilterValue)
.ToHashSet();

var filteredResults = existingFilters
.Where(entry => IsFilterInvalid(entry, validFilterValues))
.ToList();
var newCookieValue = string.Join(FilterSeparator, filteredResults);
if (string.IsNullOrEmpty(newCookieValue)) return null;
newCookieValue = AddNewFilterToFilterString(newCookieValue, newFilterToAdd);
return RemoveDuplicateFilters( newFilterToAdd, newCookieValue);
}

private static bool IsFilterInvalid(string filterEntry, HashSet<string> validFilterValues)
{
if (validFilterValues.Contains(filterEntry)) return true;
return false;
}
public static string RemoveDuplicateFilters(string newFilterToAdd, string? existingFilterString)
{
if (string.IsNullOrEmpty(existingFilterString))
{
return existingFilterString ?? string.Empty;
}
var selectedFilters = existingFilterString.Split(FilteringHelper.FilterSeparator).ToList();
if (!string.IsNullOrEmpty(newFilterToAdd))
{
var filterHeader = newFilterToAdd.Split(FilteringHelper.Separator)[0];
var dupfilters = selectedFilters.Where(x => x.Contains(filterHeader));
if (dupfilters.Count() > 1)
{
foreach (var filter in selectedFilters)
{
if (filter.Contains(filterHeader))
{
selectedFilters.Remove(filter);
existingFilterString = string.Join(FilteringHelper.FilterSeparator, selectedFilters);
break;
}
}
}
}
return existingFilterString;
}
private static IEnumerable<FilterOptionModel> GetFilterOptionsForPromptWithOptions(Prompt prompt)
{
var group = GetFilterGroupForPrompt(prompt);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ bool apiIsAccessible

var bannerText = "bannerText";
A.CallTo(() => courseService.GetCurrentCourses(CandidateId)).Returns(currentCourses);
A.CallTo(() => selfAssessmentService.GetSelfAssessmentsForCandidate(DelegateUserId, A<int>._)).Returns(selfAssessments);
A.CallTo(() => selfAssessmentService.GetSelfAssessmentsForCandidate(DelegateUserId, A<int>._, A<int>._)).Returns(selfAssessments);
A.CallTo(() => actionPlanService.GetIncompleteActionPlanResources(DelegateUserId))
.Returns((actionPlanResources, apiIsAccessible));
A.CallTo(() => centresService.GetBannerText(CentreId)).Returns(bannerText);
Expand Down Expand Up @@ -426,7 +426,7 @@ public void MarkActionPlanResourceAsComplete_does_not_call_service_with_invalid_
private void GivenCurrentActivitiesAreEmptyLists()
{
A.CallTo(() => courseService.GetCurrentCourses(A<int>._)).Returns(new List<CurrentCourse>());
A.CallTo(() => selfAssessmentService.GetSelfAssessmentsForCandidate(A<int>._, A<int>._))
A.CallTo(() => selfAssessmentService.GetSelfAssessmentsForCandidate(A<int>._, A<int>._, A<int>._))
.Returns(new List<CurrentSelfAssessment>());
A.CallTo(() => actionPlanService.GetIncompleteActionPlanResources(A<int>._))
.Returns((new List<ActionPlanResource>(), false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public async Task<IActionResult> Current(

var centreId = User.GetCentreIdKnownNotNull();
var selfAssessments =
selfAssessmentService.GetSelfAssessmentsForCandidate(delegateUserId, centreId);
selfAssessmentService.GetSelfAssessmentsForCandidate(delegateUserId, centreId, 0);

var (learningResources, apiIsAccessible) =
await GetIncompleteActionPlanResourcesIfSignpostingEnabled(delegateUserId);
Expand Down Expand Up @@ -81,7 +81,7 @@ public async Task<IActionResult> AllCurrentItems()
var centreId = User.GetCentreIdKnownNotNull();

var selfAssessment =
selfAssessmentService.GetSelfAssessmentsForCandidate(delegateUserId, centreId);
selfAssessmentService.GetSelfAssessmentsForCandidate(delegateUserId, centreId, 0);

var (learningResources, _) = await GetIncompleteActionPlanResourcesIfSignpostingEnabled(delegateUserId);
var model = new AllCurrentItemsPageViewModel(currentCourses, selfAssessment, learningResources);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,22 +297,18 @@ public IActionResult AdminAccountAlreadyExists(string email, string centreName)
return RedirectToAction("AccessDenied", "LearningSolutions");
}

var adminAccounts = userService.GetUserById(loggedInUserId)!.AdminAccounts;
var userEntity = userService.GetUserById(loggedInUserId);

if (adminAccounts.Any())
if (userEntity.DelegateAccounts!.Any(account => account.CentreId == model.CentreId))
{
return RedirectToAction(
"AdminAccountAlreadyExists",
return RedirectToAction("AccountAlreadyExists",
new { email = model.Email, centreName = model.CentreName }
);
}

var delegateAccounts = userService.GetUserById(loggedInUserId)!.DelegateAccounts;

if (delegateAccounts.Any(account => account.CentreId == model.CentreId))
if (userEntity.AdminAccounts!.Any(account => account.CentreId == model.CentreId))
{
return RedirectToAction(
"AccountAlreadyExists",
return RedirectToAction("AdminAccountAlreadyExists",
new { email = model.Email, centreName = model.CentreName }
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ public IActionResult Index(

sortBy ??= DefaultSortByOptions.Name.PropertyName;
sortDirection ??= GenericSortingHelper.Ascending;

existingFilterString = FilteringHelper.GetFilterString(
existingFilterString = FilteringHelper.GetFilterString(
existingFilterString,
newFilterToAdd,
clearFilters,
Expand Down Expand Up @@ -142,25 +141,7 @@ public IActionResult Index(
if (!string.IsNullOrEmpty(existingFilterString))
{
var selectedFilters = existingFilterString.Split(FilteringHelper.FilterSeparator).ToList();

if (!string.IsNullOrEmpty(newFilterToAdd))
{
var filterHeader = newFilterToAdd.Split(FilteringHelper.Separator)[0];
var dupfilters = selectedFilters.Where(x => x.Contains(filterHeader));
if (dupfilters.Count() > 1)
{
foreach (var filter in selectedFilters)
{
if (filter.Contains(filterHeader))
{
selectedFilters.Remove(filter);
existingFilterString = string.Join(FilteringHelper.FilterSeparator, selectedFilters);
break;
}
}
}
}

existingFilterString = FilteringHelper.RemoveDuplicateFilters(newFilterToAdd, existingFilterString);
if (selectedFilters.Count > 0)
{
foreach (var filter in selectedFilters)
Expand Down Expand Up @@ -276,7 +257,10 @@ public IActionResult Index(
var activityName = isCourseDelegate
? courseService.GetCourseNameAndApplication((int)customisationId).CourseName
: selfAssessmentService.GetSelfAssessmentNameById((int)selfAssessmentId);

if (!string.IsNullOrEmpty(existingFilterString))
{
existingFilterString = FilteringHelper.GetValidFilters( existingFilterString, newFilterToAdd, availableFilters, Request, filterCookieName);
}
if (isCourseDelegate)
{
var result = paginateService.Paginate(
Expand Down Expand Up @@ -591,6 +575,7 @@ DelegateAccessRoute accessedVia
return RedirectToAction("Index", "ActivityDelegates", routeData, returnPageQuery.Value.ItemIdToReturnTo);
}
}

}
}

Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ public IActionResult Index(int delegateId, string? callType)
course.LastUpdated = DateHelper.GetLocalDateTime(course.LastUpdated);
course.Completed = course.Completed?.TimeOfDay == TimeSpan.Zero ? course.Completed : DateHelper.GetLocalDateTime(course.Completed);
}


var selfAssessments =
selfAssessmentService.GetSelfAssessmentsForCandidate(delegateEntity.UserAccount.Id, centreId);
selfAssessmentService.GetSelfAssessmentsForCandidate(delegateEntity.UserAccount.Id, centreId, categoryIdFilter);

foreach (var selfassessment in selfAssessments)
{
Expand Down
4 changes: 2 additions & 2 deletions DigitalLearningSolutions.Web/Services/CourseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ int diagCompletionThreshold
int GetNumberOfActiveCoursesAtCentreFilteredByCategory(int centreId, int? categoryId);
public IEnumerable<Course> GetApplicationsAvailableToCentre(int centreId);
bool IsSelfEnrollmentAllowed(int customisationId);
Customisation? GetCourse(int customisationId);
Customisation? GetCourse(int? customisationId);
}

public class CourseService : ICourseService
Expand Down Expand Up @@ -632,7 +632,7 @@ public bool IsSelfEnrollmentAllowed(int customisationId)
return courseDataService.IsSelfEnrollmentAllowed(customisationId);
}

public Customisation? GetCourse(int customisationId)
public Customisation? GetCourse(int? customisationId)
{
return courseDataService.GetCourse(customisationId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public interface ISelfAssessmentService
//Self Assessments
string? GetSelfAssessmentNameById(int selfAssessmentId);
// Candidate Assessments
IEnumerable<CurrentSelfAssessment> GetSelfAssessmentsForCandidate(int delegateUserId, int centreId);
IEnumerable<CurrentSelfAssessment> GetSelfAssessmentsForCandidate(int delegateUserId, int centreId, int? adminCategoryId);

CurrentSelfAssessment? GetSelfAssessmentForCandidateById(int delegateUserId, int selfAssessmentId);

Expand Down Expand Up @@ -404,9 +404,9 @@ public IEnumerable<Competency> GetCandidateAssessmentOptionalCompetencies(int se
return selfAssessmentDataService.GetCandidateAssessmentOptionalCompetencies(selfAssessmentId, delegateUserId);
}

public IEnumerable<CurrentSelfAssessment> GetSelfAssessmentsForCandidate(int delegateUserId, int centreId)
public IEnumerable<CurrentSelfAssessment> GetSelfAssessmentsForCandidate(int delegateUserId, int centreId, int? adminCategoryId)
{
return selfAssessmentDataService.GetSelfAssessmentsForCandidate(delegateUserId, centreId);
return selfAssessmentDataService.GetSelfAssessmentsForCandidate(delegateUserId, centreId, adminCategoryId);
}

public IEnumerable<Competency> GetMostRecentResults(int selfAssessmentId, int delegateId)
Expand Down
Loading