Skip to content

Commit 016519b

Browse files
committed
TD-4591-Modified SQL query to get center email first if exists.
1 parent 9d07715 commit 016519b

File tree

5 files changed

+45
-17
lines changed

5 files changed

+45
-17
lines changed

DigitalLearningSolutions.Data/DataServices/SupervisorDataService.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -393,13 +393,21 @@ LEFT JOIN UserCentreDetails ucd
393393
public IEnumerable<SupervisorForEnrolDelegate> GetSupervisorForEnrolDelegate(int CustomisationID, int CentreID)
394394
{
395395
return connection.Query<SupervisorForEnrolDelegate>(
396-
$@"SELECT AdminID, Forename + ' ' + Surname + ' (' + Email +')' AS Name, Email FROM AdminUsers AS au
397-
WHERE (Supervisor = 1) AND (CentreID = @CentreID) AND (CategoryID = 0 OR
398-
CategoryID = (SELECT au.CategoryID FROM Applications AS a INNER JOIN
399-
Customisations AS c ON a.ApplicationID = c.ApplicationID
400-
WHERE (c.CustomisationID = @CustomisationID))) AND (Active = 1) AND (Approved = 1)
401-
GROUP BY AdminID, Surname, Forename, Email, CentreName
402-
ORDER BY Surname, Forename",
396+
$@"SELECT aa.ID AS AdminID,
397+
u.FirstName + ' ' + u.LastName + ' (' + COALESCE(ucd.Email, u.PrimaryEmail) +')' AS Name,
398+
COALESCE(ucd.Email, u.PrimaryEmail) AS Email
399+
FROM AdminAccounts AS aa INNER JOIN
400+
Users AS u ON aa.UserID = u.ID INNER JOIN
401+
Centres AS c ON aa.CentreID = c.CentreID LEFT OUTER JOIN
402+
UserCentreDetails AS ucd ON u.ID = ucd.UserID AND c.CentreID = ucd.CentreID
403+
WHERE (aa.IsSupervisor = 1) AND (c.CentreID = @CentreID) AND
404+
(ISNULL(aa.CategoryID, 0) = 0 OR CategoryID =
405+
(SELECT aa.CategoryID FROM Applications AS a INNER JOIN
406+
Customisations AS c ON a.ApplicationID = c.ApplicationID
407+
WHERE (c.CustomisationID = @CustomisationID))) AND
408+
(aa.Active = 1)
409+
GROUP BY aa.ID, u.LastName, u.FirstName, COALESCE(ucd.Email, u.PrimaryEmail), CentreName
410+
ORDER BY u.FirstName, u.LastName",
403411
new { CentreID, CustomisationID });
404412
}
405413

DigitalLearningSolutions.Data/DataServices/UserDataService/AdminUserDataService.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,27 @@ public List<AdminUser> GetAdminUsersByCentreId(int centreId)
225225

226226
return users;
227227
}
228+
public List<AdminUser> GetAdminUsersAtCentreForCategory(int centreId, int categoryId)
229+
{
230+
var users = connection.Query<AdminUser>(
231+
@$"SELECT
232+
aa.ID AS Id,
233+
COALESCE(ucd.Email, u.PrimaryEmail) AS EmailAddress,
234+
u.FirstName,
235+
u.LastName
236+
FROM AdminAccounts AS aa INNER JOIN
237+
Users AS u ON aa.UserID = u.ID INNER JOIN
238+
Centres AS c ON c.CentreID = aa.CentreID LEFT OUTER JOIN
239+
UserCentreDetails AS ucd ON u.ID = ucd.UserID AND c.CentreID = ucd.CentreID LEFT OUTER JOIN
240+
CourseCategories AS cc ON cc.CourseCategoryID = aa.CategoryID
241+
WHERE aa.Active = 1 AND aa.CentreId = @centreId AND aa.IsSupervisor = 1 AND
242+
(aa.CategoryId = @categoryId OR aa.CategoryId IS NULL)
243+
ORDER BY u.FirstName, u.LastName",
244+
new { centreId, categoryId }
245+
).ToList();
246+
247+
return users;
248+
}
228249

229250
public int GetNumberOfAdminsAtCentre(int centreId)
230251
{

DigitalLearningSolutions.Data/DataServices/UserDataService/UserDataService.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public interface IUserDataService
2525
AdminUser? GetAdminUserById(int id);
2626

2727
List<AdminUser> GetAdminUsersByCentreId(int centreId);
28+
List<AdminUser> GetAdminUsersAtCentreForCategory(int centreId, int categoryId);
2829

2930
AdminUser? GetAdminUserByEmailAddress(string emailAddress);
3031

DigitalLearningSolutions.Web.Tests/Services/UserServiceTests.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
using DigitalLearningSolutions.Data.DataServices.UserDataService;
99
using DigitalLearningSolutions.Data.Exceptions;
1010
using DigitalLearningSolutions.Data.Models;
11-
using DigitalLearningSolutions.Data.Models.User;
11+
using DigitalLearningSolutions.Data.Models.User;
1212
using DigitalLearningSolutions.Data.Utilities;
1313
using DigitalLearningSolutions.Web.Services;
1414
using DigitalLearningSolutions.Web.Tests.TestHelpers;
@@ -735,15 +735,13 @@ public void GetSupervisorsAtCentreForCategory_returns_expected_admins()
735735
.With(au => au.IsSupervisor = true)
736736
.With(au => au.CategoryId = 2)
737737
.TheRest().With(au => au.IsSupervisor = false).Build().ToList();
738-
A.CallTo(() => userDataService.GetAdminUsersByCentreId(A<int>._)).Returns(adminUsers);
738+
A.CallTo(() => userDataService.GetAdminUsersAtCentreForCategory(A<int>._, A<int>._)).Returns(adminUsers);
739739

740740
// When
741741
var result = userService.GetSupervisorsAtCentreForCategory(1, 1).ToList();
742742

743743
// Then
744-
result.Should().HaveCount(5);
745-
result.Should().OnlyContain(au => au.IsSupervisor);
746-
result.Should().OnlyContain(au => au.CategoryId == null || au.CategoryId == 1);
744+
result.Should().BeEquivalentTo(adminUsers);
747745
}
748746

749747
[Test]

DigitalLearningSolutions.Web/Services/UserService.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,8 @@ public IEnumerable<AdminUser> GetSupervisorsAtCentre(int centreId)
317317

318318
public IEnumerable<AdminUser> GetSupervisorsAtCentreForCategory(int centreId, int categoryId)
319319
{
320-
return userDataService.GetAdminUsersByCentreId(centreId).Where(au => au.IsSupervisor)
321-
.Where(au => au.CategoryId == categoryId || au.CategoryId == null);
320+
return userDataService.GetAdminUsersAtCentreForCategory(centreId, categoryId);
321+
322322
}
323323

324324
public bool DelegateUserLearningHubAccountIsLinked(int delegateId)
@@ -894,15 +894,15 @@ public void ApproveDelegateUsers(params int[] ids)
894894
{
895895
userDataService.ApproveDelegateUsers(ids);
896896
}
897-
897+
898898
public (IEnumerable<AdminEntity>, int) GetAllAdmins(string search, int offset, int rows, int? adminId, string userStatus, string role, int? centreId, int failedLoginThreshold)
899899
{
900900
return userDataService.GetAllAdmins(search, offset, rows, adminId, userStatus, role, centreId, failedLoginThreshold);
901901
}
902902

903903
public void UpdateAdminUserAndSpecialPermissions(int adminId, bool isCentreAdmin, bool isSupervisor, bool isNominatedSupervisor, bool isTrainer, bool isContentCreator, bool isContentManager, bool importOnly, int? categoryId, bool isCentreManager, bool isSuperAdmin, bool isReportsViewer, bool isLocalWorkforceManager, bool isFrameworkDeveloper, bool isWorkforceManager)
904904
{
905-
userDataService.UpdateAdminUserAndSpecialPermissions(adminId, isCentreAdmin, isSupervisor, isNominatedSupervisor, isTrainer, isContentCreator, isContentManager,importOnly, categoryId, isCentreManager, isSuperAdmin, isReportsViewer, isLocalWorkforceManager, isFrameworkDeveloper, isWorkforceManager);
905+
userDataService.UpdateAdminUserAndSpecialPermissions(adminId, isCentreAdmin, isSupervisor, isNominatedSupervisor, isTrainer, isContentCreator, isContentManager, importOnly, categoryId, isCentreManager, isSuperAdmin, isReportsViewer, isLocalWorkforceManager, isFrameworkDeveloper, isWorkforceManager);
906906
}
907907

908908
public int GetUserIdFromAdminId(int adminId)
@@ -929,7 +929,7 @@ public bool IsUserAlreadyAdminAtCentre(int? userId, int centreId)
929929
{
930930
return userDataService.IsUserAlreadyAdminAtCentre(userId, centreId);
931931
}
932-
932+
933933
public IEnumerable<AdminEntity> GetAdminsByCentreId(int centreId)
934934
{
935935
return userDataService.GetAdminsByCentreId(centreId);

0 commit comments

Comments
 (0)