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 @@ -393,13 +393,21 @@ LEFT JOIN UserCentreDetails ucd
public IEnumerable<SupervisorForEnrolDelegate> GetSupervisorForEnrolDelegate(int CustomisationID, int CentreID)
{
return connection.Query<SupervisorForEnrolDelegate>(
$@"SELECT AdminID, Forename + ' ' + Surname + ' (' + Email +')' AS Name, Email FROM AdminUsers AS au
WHERE (Supervisor = 1) AND (CentreID = @CentreID) AND (CategoryID = 0 OR
CategoryID = (SELECT au.CategoryID FROM Applications AS a INNER JOIN
Customisations AS c ON a.ApplicationID = c.ApplicationID
WHERE (c.CustomisationID = @CustomisationID))) AND (Active = 1) AND (Approved = 1)
GROUP BY AdminID, Surname, Forename, Email, CentreName
ORDER BY Surname, Forename",
$@"SELECT aa.ID AS AdminID,
u.FirstName + ' ' + u.LastName + ' (' + COALESCE(ucd.Email, u.PrimaryEmail) +')' AS Name,
COALESCE(ucd.Email, u.PrimaryEmail) AS Email
FROM AdminAccounts AS aa INNER JOIN
Users AS u ON aa.UserID = u.ID INNER JOIN
Centres AS c ON aa.CentreID = c.CentreID LEFT OUTER JOIN
UserCentreDetails AS ucd ON u.ID = ucd.UserID AND c.CentreID = ucd.CentreID
WHERE (aa.IsSupervisor = 1) AND (c.CentreID = @CentreID) AND
(ISNULL(aa.CategoryID, 0) = 0 OR CategoryID =
(SELECT aa.CategoryID FROM Applications AS a INNER JOIN
Customisations AS c ON a.ApplicationID = c.ApplicationID
WHERE (c.CustomisationID = @CustomisationID))) AND
(aa.Active = 1)
GROUP BY aa.ID, u.LastName, u.FirstName, COALESCE(ucd.Email, u.PrimaryEmail), CentreName
ORDER BY u.FirstName, u.LastName",
new { CentreID, CustomisationID });
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,27 @@ public List<AdminUser> GetAdminUsersByCentreId(int centreId)

return users;
}
public List<AdminUser> GetAdminUsersAtCentreForCategory(int centreId, int categoryId)
{
var users = connection.Query<AdminUser>(
@$"SELECT
aa.ID AS Id,
COALESCE(ucd.Email, u.PrimaryEmail) AS EmailAddress,
u.FirstName,
u.LastName
FROM AdminAccounts AS aa INNER JOIN
Users AS u ON aa.UserID = u.ID INNER JOIN
Centres AS c ON c.CentreID = aa.CentreID LEFT OUTER JOIN
UserCentreDetails AS ucd ON u.ID = ucd.UserID AND c.CentreID = ucd.CentreID LEFT OUTER JOIN
CourseCategories AS cc ON cc.CourseCategoryID = aa.CategoryID
WHERE aa.Active = 1 AND aa.CentreId = @centreId AND aa.IsSupervisor = 1 AND
(aa.CategoryId = @categoryId OR aa.CategoryId IS NULL)
ORDER BY u.FirstName, u.LastName",
new { centreId, categoryId }
).ToList();

return users;
}

public int GetNumberOfAdminsAtCentre(int centreId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public interface IUserDataService
AdminUser? GetAdminUserById(int id);

List<AdminUser> GetAdminUsersByCentreId(int centreId);
List<AdminUser> GetAdminUsersAtCentreForCategory(int centreId, int categoryId);

AdminUser? GetAdminUserByEmailAddress(string emailAddress);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using DigitalLearningSolutions.Data.DataServices.UserDataService;
using DigitalLearningSolutions.Data.Exceptions;
using DigitalLearningSolutions.Data.Models;
using DigitalLearningSolutions.Data.Models.User;
using DigitalLearningSolutions.Data.Models.User;
using DigitalLearningSolutions.Data.Utilities;
using DigitalLearningSolutions.Web.Services;
using DigitalLearningSolutions.Web.Tests.TestHelpers;
Expand Down Expand Up @@ -735,15 +735,13 @@ public void GetSupervisorsAtCentreForCategory_returns_expected_admins()
.With(au => au.IsSupervisor = true)
.With(au => au.CategoryId = 2)
.TheRest().With(au => au.IsSupervisor = false).Build().ToList();
A.CallTo(() => userDataService.GetAdminUsersByCentreId(A<int>._)).Returns(adminUsers);
A.CallTo(() => userDataService.GetAdminUsersAtCentreForCategory(A<int>._, A<int>._)).Returns(adminUsers);

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

// Then
result.Should().HaveCount(5);
result.Should().OnlyContain(au => au.IsSupervisor);
result.Should().OnlyContain(au => au.CategoryId == null || au.CategoryId == 1);
result.Should().BeEquivalentTo(adminUsers);
}

[Test]
Expand Down
10 changes: 5 additions & 5 deletions DigitalLearningSolutions.Web/Services/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,8 @@ public IEnumerable<AdminUser> GetSupervisorsAtCentre(int centreId)

public IEnumerable<AdminUser> GetSupervisorsAtCentreForCategory(int centreId, int categoryId)
{
return userDataService.GetAdminUsersByCentreId(centreId).Where(au => au.IsSupervisor)
.Where(au => au.CategoryId == categoryId || au.CategoryId == null);
return userDataService.GetAdminUsersAtCentreForCategory(centreId, categoryId);

}

public bool DelegateUserLearningHubAccountIsLinked(int delegateId)
Expand Down Expand Up @@ -894,15 +894,15 @@ public void ApproveDelegateUsers(params int[] ids)
{
userDataService.ApproveDelegateUsers(ids);
}

public (IEnumerable<AdminEntity>, int) GetAllAdmins(string search, int offset, int rows, int? adminId, string userStatus, string role, int? centreId, int failedLoginThreshold)
{
return userDataService.GetAllAdmins(search, offset, rows, adminId, userStatus, role, centreId, failedLoginThreshold);
}

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)
{
userDataService.UpdateAdminUserAndSpecialPermissions(adminId, isCentreAdmin, isSupervisor, isNominatedSupervisor, isTrainer, isContentCreator, isContentManager,importOnly, categoryId, isCentreManager, isSuperAdmin, isReportsViewer, isLocalWorkforceManager, isFrameworkDeveloper, isWorkforceManager);
userDataService.UpdateAdminUserAndSpecialPermissions(adminId, isCentreAdmin, isSupervisor, isNominatedSupervisor, isTrainer, isContentCreator, isContentManager, importOnly, categoryId, isCentreManager, isSuperAdmin, isReportsViewer, isLocalWorkforceManager, isFrameworkDeveloper, isWorkforceManager);
}

public int GetUserIdFromAdminId(int adminId)
Expand All @@ -929,7 +929,7 @@ public bool IsUserAlreadyAdminAtCentre(int? userId, int centreId)
{
return userDataService.IsUserAlreadyAdminAtCentre(userId, centreId);
}

public IEnumerable<AdminEntity> GetAdminsByCentreId(int centreId)
{
return userDataService.GetAdminsByCentreId(centreId);
Expand Down