Skip to content

Commit 92cda8b

Browse files
ABSinhaakevwhitt-hee
authored andcommitted
TD-4880- undoing Sherif's change for the task TD-4879 since it was supposed to be made for Delegate Activities and not Activity Delegates, adding specific logic to the Self Assessment service layer and showing Unauthorised activity based on return type.
1 parent 4503194 commit 92cda8b

File tree

4 files changed

+29
-20
lines changed

4 files changed

+29
-20
lines changed

DigitalLearningSolutions.Data/DataServices/SelfAssessmentDataService/SelfAssessmentDataService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ LEFT JOIN dbo.CandidateAssessmentSupervisorVerifications AS casv WITH (NOLOCK) O
244244
245245
WHERE sa.ID = @selfAssessmentId
246246
AND da.CentreID = @centreID AND csa.CentreID = @centreID
247-
AND (ca.RemovedDate IS NULL) AND ( aaEnrolledBy.CategoryID IS NULL OR sa.CategoryID = aaEnrolledBy.CategoryID)
247+
AND (ca.RemovedDate IS NULL)
248248
AND ( u.FirstName + ' ' + u.LastName + ' ' + COALESCE(ucd.Email, u.PrimaryEmail) + ' ' + COALESCE(da.CandidateNumber, '') LIKE N'%' + @searchString + N'%')
249249
AND ((@isDelegateActive IS NULL) OR (@isDelegateActive = 1 AND (da.Active = 1)) OR (@isDelegateActive = 0 AND (da.Active = 0)))
250250
AND ((@removed IS NULL) OR (@removed = 1 AND (ca.RemovedDate IS NOT NULL)) OR (@removed = 0 AND (ca.RemovedDate IS NULL)))

DigitalLearningSolutions.Web.Tests/Controllers/TrackingSystem/Delegates/CourseDelegatesControllerTests.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void Index_shows_index_page_when_no_selfAssessmentId_supplied()
9595
var selfAssessmentDelegate = new SelfAssessmentDelegate(6, "Lname");
9696

9797
A.CallTo(() => selfAssessmentDelegatesService.GetSelfAssessmentDelegatesPerPage("", 0, 10, "SearchableName", "Ascending",
98-
6, UserCentreId, null, null, null, null))
98+
6, UserCentreId, null, null, null, null, null))
9999
.Returns((new SelfAssessmentDelegatesData(
100100
new List<SelfAssessmentDelegate> { selfAssessmentDelegate }
101101
), 1)
@@ -137,7 +137,7 @@ public void SelfAssessmentDelegates_Index_returns_ViewResult_with_EmptyDelegates
137137
var selfAssessmentDelegate = new SelfAssessmentDelegate(6, "Lname");
138138

139139
A.CallTo(() => selfAssessmentDelegatesService.GetSelfAssessmentDelegatesPerPage("", 0, 10, "SearchableName", "Ascending",
140-
10, UserCentreId, null, null, null, null))
140+
10, UserCentreId, null, null, null, null, null))
141141
.Returns((new SelfAssessmentDelegatesData(
142142
new List<SelfAssessmentDelegate> { selfAssessmentDelegate }
143143
), 0)
@@ -147,8 +147,7 @@ public void SelfAssessmentDelegates_Index_returns_ViewResult_with_EmptyDelegates
147147
var result = controller.Index(null, 10);
148148

149149
// Then
150-
result.Should().BeViewResult().ModelAs<ActivityDelegatesViewModel>()
151-
.DelegatesDetails?.Delegates?.Should().BeEmpty();
150+
result.Should().BeRedirectToActionResult();
152151
}
153152

154153
[Test]

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,7 @@ public IActionResult Index(
131131

132132
var centreId = User.GetCentreIdKnownNotNull();
133133
var adminCategoryId = User.GetAdminCategoryId();
134-
var selfAssessmentCategoryId = selfAssessmentService.GetSelfAssessmentCategoryId((int)selfAssessmentId);
135134

136-
if (adminCategoryId > 0 && adminCategoryId != selfAssessmentCategoryId)
137-
{
138-
return RedirectToAction("StatusCode", "LearningSolutions", new { code = 403 });
139-
}
140135

141136
bool? isDelegateActive, isProgressLocked, removed, hasCompleted, submitted, signedOff;
142137
isDelegateActive = isProgressLocked = removed = hasCompleted = submitted = signedOff = null;
@@ -216,7 +211,7 @@ public IActionResult Index(
216211
{
217212
var courseDelegatesData = new CourseDelegatesData();
218213
var selfAssessmentDelegatesData = new SelfAssessmentDelegatesData();
219-
var resultCount = 0;
214+
int? resultCount;
220215
if (isCourseDelegate)
221216
{
222217
(courseDelegatesData, resultCount) = courseDelegatesService.GetCoursesAndCourseDelegatesPerPageForCentre(searchString ?? string.Empty, offSet, itemsPerPage ?? 0, sortBy, sortDirection,
@@ -238,14 +233,20 @@ public IActionResult Index(
238233
else
239234
{
240235
(selfAssessmentDelegatesData, resultCount) = selfAssessmentService.GetSelfAssessmentDelegatesPerPage(searchString ?? string.Empty, offSet, itemsPerPage ?? 0, sortBy, sortDirection,
241-
selfAssessmentId, centreId, isDelegateActive, removed, submitted, signedOff);
236+
selfAssessmentId, centreId, isDelegateActive, removed, submitted, signedOff, adminCategoryId);
237+
238+
if (selfAssessmentDelegatesData?.Delegates == null && resultCount == null)
239+
{
240+
//redirect as unauthorized through null comparisions when category Id is a mismatch.
241+
return RedirectToAction("StatusCode", "LearningSolutions", new { code = 403 });
242+
}
242243

243244
if (selfAssessmentDelegatesData?.Delegates?.Count() == 0 && resultCount > 0)
244245
{
245246
page = 1; offSet = 0;
246247
(selfAssessmentDelegatesData, resultCount) = selfAssessmentService.GetSelfAssessmentDelegatesPerPage(searchString ?? string.Empty, offSet, itemsPerPage ?? 0, sortBy, sortDirection,
247-
selfAssessmentId, centreId, isDelegateActive, removed, submitted, signedOff);
248-
}
248+
selfAssessmentId, centreId, isDelegateActive, removed, submitted, signedOff, adminCategoryId);
249+
}
249250

250251
var adminId = User.GetCustomClaimAsRequiredInt(CustomClaimTypes.UserAdminId);
251252

@@ -280,7 +281,7 @@ public IActionResult Index(
280281
{
281282
var result = paginateService.Paginate(
282283
courseDelegatesData.Delegates,
283-
resultCount,
284+
(int)resultCount,
284285
new PaginationOptions(page, itemsPerPage),
285286
new FilterOptions(existingFilterString, availableFilters, CourseDelegateAccountStatusFilterOptions.Active.FilterValue),
286287
searchString,
@@ -298,7 +299,7 @@ public IActionResult Index(
298299
{
299300
var result = paginateService.Paginate(
300301
selfAssessmentDelegatesData.Delegates,
301-
resultCount,
302+
(int)resultCount,
302303
new PaginationOptions(page, itemsPerPage),
303304
new FilterOptions(existingFilterString, availableFilters, CourseDelegateAccountStatusFilterOptions.Active.FilterValue),
304305
searchString,

DigitalLearningSolutions.Web/Services/SelfAssessmentService.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ int delegateUserId
128128
);
129129

130130
void RemoveEnrolment(int selfAssessmentId, int delegateUserId);
131-
public (SelfAssessmentDelegatesData, int) GetSelfAssessmentDelegatesPerPage(string searchString, int offSet, int itemsPerPage, string sortBy, string sortDirection,
132-
int? selfAssessmentId, int centreId, bool? isDelegateActive, bool? removed, bool? submitted, bool? signedOff);
131+
public (SelfAssessmentDelegatesData, int?) GetSelfAssessmentDelegatesPerPage(string searchString, int offSet, int itemsPerPage, string sortBy, string sortDirection,
132+
int? selfAssessmentId, int centreId, bool? isDelegateActive, bool? removed, bool? submitted, bool? signedOff, int? adminCategoryId);
133133
public SelfAssessmentDelegatesData GetSelfAssessmentActivityDelegatesExport(string searchString, int itemsPerPage, string sortBy, string sortDirection,
134134
int? selfAssessmentId, int centreId, bool? isDelegateActive, bool? removed, int currentRun, bool? submitted, bool? signedOff);
135135
public int GetSelfAssessmentActivityDelegatesExportCount(string searchString, string sortBy, string sortDirection,
@@ -448,9 +448,18 @@ public void RemoveEnrolment(int selfAssessmentId, int delegateUserId)
448448
return selfAssessmentDataService.GetSelfAssessmentNameById(selfAssessmentId);
449449
}
450450

451-
public (SelfAssessmentDelegatesData, int) GetSelfAssessmentDelegatesPerPage(string searchString, int offSet, int itemsPerPage, string sortBy, string sortDirection,
452-
int? selfAssessmentId, int centreId, bool? isDelegateActive, bool? removed, bool? submitted, bool? signedOff)
451+
public (SelfAssessmentDelegatesData, int?) GetSelfAssessmentDelegatesPerPage(string searchString, int offSet, int itemsPerPage, string sortBy, string sortDirection,
452+
int? selfAssessmentId, int centreId, bool? isDelegateActive, bool? removed, bool? submitted, bool? signedOff, int? adminCategoryId)
453453
{
454+
455+
var selfAssessmentCategoryId = selfAssessmentDataService.GetSelfAssessmentCategoryId((int)selfAssessmentId);
456+
457+
if (adminCategoryId > 0 && adminCategoryId != selfAssessmentCategoryId)
458+
{
459+
// return null variants of the object when the categoryID mismatches
460+
return (new SelfAssessmentDelegatesData(), null);
461+
}
462+
454463
(var delegateselfAssessments, int resultCount) = selfAssessmentDataService.GetSelfAssessmentDelegates(searchString, offSet, itemsPerPage, sortBy, sortDirection,
455464
selfAssessmentId, centreId, isDelegateActive, removed, submitted, signedOff);
456465

0 commit comments

Comments
 (0)