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 @@ -163,7 +163,7 @@ public void UpdateAdminUserPermissions_updates_user()
try
{
// When
userDataService.UpdateAdminUserPermissions(7, true, true, true, true, true, true, true, 1);
userDataService.UpdateAdminUserPermissions(7, true, true, true, true, true, true, true, 1, false);
var updatedUser = userDataService.GetAdminUserById(7)!;

// Then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ public void PromoteDelegateToAdmin_throws_AdminCreationFailedException_if_delega
{
// Given
var delegateUser = UserTestHelper.GetDefaultDelegateUser(firstName: null);
var adminRoles = new AdminRoles(true, true, true, true, true, true, true);
var adminRoles = new AdminRoles(true, true, true, true, true, true, true, false);
A.CallTo(() => userDataService.GetDelegateUserById(A<int>._)).Returns(delegateUser);

// When
Expand All @@ -636,7 +636,7 @@ public void PromoteDelegateToAdmin_throws_AdminCreationFailedException_if_delega
{
// Given
var delegateUser = UserTestHelper.GetDefaultDelegateUser(emailAddress: null);
var adminRoles = new AdminRoles(true, true, true, true, true, true, true);
var adminRoles = new AdminRoles(true, true, true, true, true, true, true, false);
A.CallTo(() => userDataService.GetDelegateUserById(A<int>._)).Returns(delegateUser);

// When
Expand All @@ -655,7 +655,7 @@ public void
// Given
var delegateUser = UserTestHelper.GetDefaultDelegateUser();
var adminUser = UserTestHelper.GetDefaultAdminUser();
var adminRoles = new AdminRoles(true, true, true, true, true, true, true);
var adminRoles = new AdminRoles(true, true, true, true, true, true, true, false);
A.CallTo(() => userDataService.GetDelegateUserById(A<int>._)).Returns(delegateUser);
A.CallTo(() => userDataService.GetAdminUserByEmailAddress(A<string>._)).Returns(adminUser);

Expand All @@ -675,7 +675,8 @@ public void
adminRoles.IsContentCreator || adminUser.IsContentCreator,
adminRoles.IsContentManager || adminUser.IsContentManager,
adminRoles.ImportOnly || adminUser.ImportOnly,
adminUser.CategoryId
adminUser.CategoryId,
adminRoles.IsCentreManager || adminUser.IsCentreManager
)
).MustHaveHappenedOnceExactly();
}
Expand All @@ -688,7 +689,7 @@ public void
// Given
var delegateUser = UserTestHelper.GetDefaultDelegateUser();
var adminUser = UserTestHelper.GetDefaultAdminUser(centreId: 3, active: false);
var adminRoles = new AdminRoles(true, true, true, true, true, true, true);
var adminRoles = new AdminRoles(true, true, true, true, true, true, true, false);
A.CallTo(() => userDataService.GetDelegateUserById(A<int>._)).Returns(delegateUser);
A.CallTo(() => userDataService.GetAdminUserByEmailAddress(A<string>._)).Returns(adminUser);

Expand All @@ -712,7 +713,7 @@ public void PromoteDelegateToAdmin_updates_existing_admin_if_inactive_admin_at_s
const int categoryId = 1;
var delegateUser = UserTestHelper.GetDefaultDelegateUser();
var adminUser = UserTestHelper.GetDefaultAdminUser(active: false);
var adminRoles = new AdminRoles(true, true, true, true, true, true, true);
var adminRoles = new AdminRoles(true, true, true, true, true, true, true, true);
A.CallTo(() => userDataService.GetDelegateUserById(A<int>._)).Returns(delegateUser);
A.CallTo(() => userDataService.GetAdminUserByEmailAddress(A<string>._)).Returns(adminUser);

Expand Down Expand Up @@ -744,7 +745,8 @@ public void PromoteDelegateToAdmin_updates_existing_admin_if_inactive_admin_at_s
adminRoles.IsContentCreator,
adminRoles.IsContentManager,
adminRoles.ImportOnly,
categoryId
categoryId,
adminRoles.IsCentreManager
)
).MustHaveHappenedOnceExactly();
}
Expand All @@ -755,7 +757,7 @@ public void PromoteDelegateToAdmin_calls_data_service_with_expected_value()
{
// Given
var delegateUser = UserTestHelper.GetDefaultDelegateUser();
var adminRoles = new AdminRoles(true, true, true, true, true, true, true);
var adminRoles = new AdminRoles(true, true, true, true, true, true, true, true);
A.CallTo(() => userDataService.GetDelegateUserById(A<int>._)).Returns(delegateUser);
A.CallTo(() => userDataService.GetAdminUserByEmailAddress(A<string>._)).Returns(null);

Expand Down Expand Up @@ -837,7 +839,8 @@ private void UpdateToExistingAdminAccountMustNotHaveHappened()
A<bool>._,
A<bool>._,
A<bool>._,
A<int>._
A<int>._,
A<bool>._
)
).MustNotHaveHappened();
}
Expand Down
12 changes: 7 additions & 5 deletions DigitalLearningSolutions.Data.Tests/Services/UserServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ public void UpdateAdminUserPermissions_edits_roles_when_spaces_available()
);
var numberOfAdmins = CentreContractAdminUsageTestHelper.GetDefaultNumberOfAdministrators();
GivenAdminDataReturned(numberOfAdmins, currentAdminUser);
var adminRoles = new AdminRoles(true, true, true, true, true, true, true);
var adminRoles = new AdminRoles(true, true, true, true, true, true, true, true);

// When
userService.UpdateAdminUserPermissions(currentAdminUser.Id, adminRoles, 0);
Expand All @@ -816,7 +816,7 @@ bool importOnly

var numberOfAdmins = GetFullCentreContractAdminUsage();
GivenAdminDataReturned(numberOfAdmins, currentAdminUser);
var adminRoles = new AdminRoles(true, true, true, true, true, true, importOnly);
var adminRoles = new AdminRoles(true, true, true, true, true, true, importOnly, true);

// When
userService.UpdateAdminUserPermissions(currentAdminUser.Id, adminRoles, 0);
Expand Down Expand Up @@ -845,7 +845,7 @@ bool newImportOnly
);
var numberOfAdmins = GetFullCentreContractAdminUsage();
GivenAdminDataReturned(numberOfAdmins, currentAdminUser);
var adminRoles = new AdminRoles(true, true, newIsContentCreator, true, newIsTrainer, true, newImportOnly);
var adminRoles = new AdminRoles(true, true, newIsContentCreator, true, newIsTrainer, true, newImportOnly, true);

// Then
Assert.Throws<AdminRoleFullException>(
Expand Down Expand Up @@ -1318,7 +1318,8 @@ int categoryId
adminRoles.IsContentCreator,
adminRoles.IsContentManager,
adminRoles.ImportOnly,
categoryId
categoryId,
adminRoles.IsCentreManager
)
).MustHaveHappened();
}
Expand All @@ -1335,7 +1336,8 @@ private void AssertAdminPermissionUpdateMustNotHaveHappened()
A<bool>._,
A<bool>._,
A<bool>._,
A<int>._
A<int>._,
A<bool>._
)
).MustNotHaveHappened();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public static class CentreContractAdminUsageTestHelper
{
public static CentreContractAdminUsage GetDefaultNumberOfAdministrators(
int admins = 1,
int centreManager=1,
int supervisors = 2,
int trainers = 3,
int ccLicences = 4,
Expand All @@ -23,6 +24,7 @@ public static CentreContractAdminUsage GetDefaultNumberOfAdministrators(
SupervisorCount = supervisors,
TrainerCount = trainers,
CcLicenceCount = ccLicences,
CentreManagerCheckCount= centreManager,
CmsAdministratorCount = cmsAdministrators,
CmsManagerCount = cmsManagers,
TrainerSpots = trainerSpots,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ public void UpdateAdminUserPermissions(
bool isContentCreator,
bool isContentManager,
bool importOnly,
int categoryId
int categoryId,
bool isCentreManager
)
{
connection.Execute(
Expand All @@ -131,7 +132,8 @@ int categoryId
ContentCreator = @isContentCreator,
ContentManager = @isContentManager,
ImportOnly = @importOnly,
CategoryID = @categoryId
CategoryID = @categoryId,
IsCentreManager = @isCentreManager
WHERE AdminID = @adminId",
new
{
Expand All @@ -144,6 +146,7 @@ int categoryId
importOnly,
categoryId,
adminId,
isCentreManager
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ void UpdateAdminUserPermissions(
bool isContentCreator,
bool isContentManager,
bool importOnly,
int categoryId
int categoryId,
bool isCentreManager
);

void UpdateAdminUserFailedLoginCount(int adminId, int updatedCount);
Expand Down
5 changes: 4 additions & 1 deletion DigitalLearningSolutions.Data/Models/AdminRoles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public AdminRoles(
bool isContentCreator,
bool isTrainer,
bool isContentManager,
bool importOnly
bool importOnly,
bool isCentreManager
)
{
IsCentreAdmin = isCentreAdmin;
Expand All @@ -19,6 +20,7 @@ bool importOnly
IsTrainer = isTrainer;
IsContentManager = isContentManager;
ImportOnly = importOnly;
IsCentreManager = isCentreManager;
}

public bool IsCentreAdmin { get; set; }
Expand All @@ -28,6 +30,7 @@ bool importOnly
public bool IsContentCreator { get; set; }
public bool IsContentManager { get; set; }
public bool ImportOnly { get; set; }
public bool IsCentreManager { get; set; }

public bool IsCmsAdministrator => IsContentManager && ImportOnly;
public bool IsCmsManager => IsContentManager && !ImportOnly;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public CentreContractAdminUsage(Centre centreDetails, List<AdminUser> adminUsers
AdminCount = adminUsers.Count(a => a.IsCentreAdmin);
SupervisorCount = adminUsers.Count(a => a.IsSupervisor);
NominatedSupervisorCount = adminUsers.Count(a => a.IsNominatedSupervisor);
CentreManagerCheckCount = adminUsers.Count(a => a.IsCentreManager);
TrainerCount = adminUsers.Count(a => a.IsTrainer);
CmsAdministratorCount = adminUsers.Count(a => a.IsCmsAdministrator);
CmsManagerCount = adminUsers.Count(a => a.IsCmsManager);
Expand All @@ -27,6 +28,7 @@ public CentreContractAdminUsage(Centre centreDetails, List<AdminUser> adminUsers
public int AdminCount { get; set; }
public int SupervisorCount { get; set; }
public int NominatedSupervisorCount { get; set; }
public int CentreManagerCheckCount { get; set; }
public int TrainerCount { get; set; }
public int CmsAdministratorCount { get; set; }
public int CmsManagerCount { get; set; }
Expand Down
6 changes: 4 additions & 2 deletions DigitalLearningSolutions.Data/Services/RegistrationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ public void PromoteDelegateToAdmin(AdminRoles adminRoles, int categoryId, int de
adminRoles.IsContentCreator,
adminRoles.IsContentManager,
adminRoles.ImportOnly,
categoryId
categoryId,
adminRoles.IsCentreManager
);
}
else if (adminUser?.Active == true && adminUser.CentreId == delegateUser.CentreId)
Expand All @@ -194,7 +195,8 @@ public void PromoteDelegateToAdmin(AdminRoles adminRoles, int categoryId, int de
adminRoles.IsContentCreator || adminUser.IsContentCreator,
adminRoles.IsContentManager || adminUser.IsContentManager,
adminRoles.ImportOnly = adminRoles.ImportOnly || adminUser.ImportOnly,
adminUser.CategoryId
adminUser.CategoryId,
adminRoles.IsCentreManager || adminUser.IsCentreManager
);
}
else if (adminUser == null)
Expand Down
3 changes: 2 additions & 1 deletion DigitalLearningSolutions.Data/Services/UserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ int categoryId
adminRoles.IsContentCreator,
adminRoles.IsContentManager,
adminRoles.ImportOnly,
categoryId
categoryId,
adminRoles.IsCentreManager
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public void ViewModel_populates_expected_values()
{
// Given
var numberOfAdmins = CentreContractAdminUsageTestHelper.GetDefaultNumberOfAdministrators(
7,
6,
1,
admins: 7,
supervisors: 6,
trainers: 1,
trainerSpots: 15,
cmsAdministrators: 3,
cmsAdministratorSpots: 12,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void EditRolesViewModel_sets_up_all_checkboxes_and_inputs_when_under_limi
// Then
using (new AssertionScope())
{
result.Checkboxes.Count.Should().Be(5);
result.Checkboxes.Count.Should().Be(6);
result.Radios.Count.Should().Be(3);
result.Checkboxes.Contains(AdminRoleInputs.CentreAdminCheckbox).Should().BeTrue();
result.Checkboxes.Contains(AdminRoleInputs.SupervisorCheckbox).Should().BeTrue();
Expand Down Expand Up @@ -159,7 +159,7 @@ public void
// Then
using (new AssertionScope())
{
result.Checkboxes.Count.Should().Be(4);
result.Checkboxes.Count.Should().Be(5);
result.Checkboxes.Contains(AdminRoleInputs.TrainerCheckbox).Should().BeFalse();
result.NotAllRolesDisplayed.Should().BeTrue();
}
Expand All @@ -185,7 +185,7 @@ public void EditRolesViewModel_does_set_up_Trainer_checkbox_when_its_limit_is_re
// Then
using (new AssertionScope())
{
result.Checkboxes.Count.Should().Be(5);
result.Checkboxes.Count.Should().Be(6);
result.Checkboxes.Contains(AdminRoleInputs.TrainerCheckbox).Should().BeTrue();
result.NotAllRolesDisplayed.Should().BeFalse();
}
Expand All @@ -212,7 +212,7 @@ public void
// Then
using (new AssertionScope())
{
result.Checkboxes.Count.Should().Be(4);
result.Checkboxes.Count.Should().Be(5);
result.Checkboxes.Contains(AdminRoleInputs.ContentCreatorCheckbox).Should().BeFalse();
result.NotAllRolesDisplayed.Should().BeTrue();
}
Expand All @@ -239,7 +239,7 @@ public void
// Then
using (new AssertionScope())
{
result.Checkboxes.Count.Should().Be(5);
result.Checkboxes.Count.Should().Be(6);
result.Checkboxes.Contains(AdminRoleInputs.ContentCreatorCheckbox).Should().BeTrue();
result.NotAllRolesDisplayed.Should().BeFalse();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ public IActionResult ConfirmNominateSupervisor(SupervisorDelegateViewModel super
{
var categoryId = User.GetAdminCourseCategoryFilter();
var supervisorDelegateDetail = supervisorService.GetSupervisorDelegateDetailsById(supervisorDelegate.Id, GetAdminID(), 0);
var adminRoles = new AdminRoles(false, false, true, false, false, false, false);
var adminRoles = new AdminRoles(false, false, true, false, false, false, false, false);
if (supervisorDelegateDetail.CandidateID != null)
{
registrationService.PromoteDelegateToAdmin(adminRoles, (categoryId ?? 0), (int)supervisorDelegateDetail.CandidateID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public AdminRolesFormData(User user)
public bool IsCentreAdmin { get; set; }
public bool IsSupervisor { get; set; }
public bool IsNominatedSupervisor { get; set; }
public bool IsCenterManager { get; set; }
public bool IsTrainer { get; set; }
public bool IsContentCreator { get; set; }
public ContentManagementRole ContentManagementRole { get; set; }
Expand All @@ -34,7 +35,8 @@ public AdminRoles GetAdminRoles()
IsContentCreator,
IsTrainer,
ContentManagementRole.IsContentManager,
ContentManagementRole.ImportOnly
ContentManagementRole.ImportOnly,
IsCenterManager
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ public abstract class AdminRolesViewModel : AdminRolesFormData
{
private const int MaxNumberOfCmsRoleRadios = 3;
private const int MinNumberOfCmsRoleRadios = 1;
private const int MaxNumberOfRoleCheckboxes = 5;
private const int MaxNumberOfRoleCheckboxes = 6;

public readonly List<CheckboxListItemViewModel> Checkboxes = new List<CheckboxListItemViewModel>
{
AdminRoleInputs.CentreManagerCheckbox,
AdminRoleInputs.CentreAdminCheckbox,
AdminRoleInputs.SupervisorCheckbox,
AdminRoleInputs.NominatedSupervisorCheckbox
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ public class AdminRoleInputs
"Manage delegates, courses and course groups. Enrol users on courses. View reports."
);

public static CheckboxListItemViewModel CentreManagerCheckbox = new CheckboxListItemViewModel(
nameof(EditRolesViewModel.IsCenterManager),
"Centre manager",
"Manages user access permissions for administrators at the centre, sees all support tickets for the centre in addition to having all of the permissions of a centre administrator."
);

public static CheckboxListItemViewModel SupervisorCheckbox = new CheckboxListItemViewModel(
nameof(EditRolesViewModel.IsSupervisor),
"Supervisor",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ReturnPageQuery returnPageQuery
{
IsCentreAdmin = user.IsCentreAdmin;
IsSupervisor = user.IsSupervisor;
IsCenterManager = user.IsCentreManager;
IsNominatedSupervisor = user.IsNominatedSupervisor;
IsTrainer = user.IsTrainer;
IsContentCreator = user.IsContentCreator;
Expand Down