diff --git a/src/Core/AdminConsole/Services/Implementations/OrganizationService.cs b/src/Core/AdminConsole/Services/Implementations/OrganizationService.cs index df09a81d8..af951ce5d 100644 --- a/src/Core/AdminConsole/Services/Implementations/OrganizationService.cs +++ b/src/Core/AdminConsole/Services/Implementations/OrganizationService.cs @@ -1421,18 +1421,18 @@ public class OrganizationService : IOrganizationService } // If the organization is using Flexible Collections, prevent use of any deprecated permissions - var organizationAbility = await _applicationCacheService.GetOrganizationAbilityAsync(user.OrganizationId); - if (organizationAbility?.FlexibleCollections == true && user.Type == OrganizationUserType.Manager) + var organization = await _organizationRepository.GetByIdAsync(user.OrganizationId); + if (organization.FlexibleCollections && user.Type == OrganizationUserType.Manager) { throw new BadRequestException("The Manager role has been deprecated by collection enhancements. Use the collection Can Manage permission instead."); } - if (organizationAbility?.FlexibleCollections == true && user.AccessAll) + if (organization.FlexibleCollections && user.AccessAll) { throw new BadRequestException("The AccessAll property has been deprecated by collection enhancements. Assign the user to collections instead."); } - if (organizationAbility?.FlexibleCollections == true && collections?.Any() == true) + if (organization.FlexibleCollections && collections?.Any() == true) { var invalidAssociations = collections.Where(cas => cas.Manage && (cas.ReadOnly || cas.HidePasswords)); if (invalidAssociations.Any()) @@ -1449,7 +1449,6 @@ public class OrganizationService : IOrganizationService var additionalSmSeatsRequired = await _countNewSmSeatsRequiredQuery.CountNewSmSeatsRequiredAsync(user.OrganizationId, 1); if (additionalSmSeatsRequired > 0) { - var organization = await _organizationRepository.GetByIdAsync(user.OrganizationId); var update = new SecretsManagerSubscriptionUpdate(organization, true) .AdjustSeats(additionalSmSeatsRequired); await _updateSecretsManagerSubscriptionCommand.UpdateSubscriptionAsync(update); diff --git a/test/Core.Test/AdminConsole/Services/OrganizationServiceTests.cs b/test/Core.Test/AdminConsole/Services/OrganizationServiceTests.cs index f2e324c6d..e90da135f 100644 --- a/test/Core.Test/AdminConsole/Services/OrganizationServiceTests.cs +++ b/test/Core.Test/AdminConsole/Services/OrganizationServiceTests.cs @@ -15,7 +15,6 @@ using Bit.Core.Enums; using Bit.Core.Exceptions; using Bit.Core.Models.Business; using Bit.Core.Models.Data; -using Bit.Core.Models.Data.Organizations; using Bit.Core.Models.Data.Organizations.OrganizationUsers; using Bit.Core.Models.Mail; using Bit.Core.Models.StaticStore; @@ -1371,7 +1370,7 @@ OrganizationUserInvite invite, SutProvider sutProvider) [Theory, BitAutoData] public async Task SaveUser_WithFlexibleCollections_WhenUpgradingToManager_Throws( - OrganizationAbility organizationAbility, + Organization organization, [OrganizationUser(type: OrganizationUserType.User)] OrganizationUser oldUserData, [OrganizationUser(type: OrganizationUserType.Manager)] OrganizationUser newUserData, [OrganizationUser(type: OrganizationUserType.Owner, status: OrganizationUserStatusType.Confirmed)] OrganizationUser savingUser, @@ -1379,18 +1378,18 @@ OrganizationUserInvite invite, SutProvider sutProvider) IEnumerable groups, SutProvider sutProvider) { - organizationAbility.FlexibleCollections = true; + organization.FlexibleCollections = true; newUserData.Id = oldUserData.Id; newUserData.UserId = oldUserData.UserId; - newUserData.OrganizationId = oldUserData.OrganizationId = savingUser.OrganizationId = organizationAbility.Id; + newUserData.OrganizationId = oldUserData.OrganizationId = savingUser.OrganizationId = organization.Id; newUserData.Permissions = CoreHelpers.ClassToJsonData(new Permissions()); - sutProvider.GetDependency() - .GetOrganizationAbilityAsync(organizationAbility.Id) - .Returns(organizationAbility); + sutProvider.GetDependency() + .GetByIdAsync(organization.Id) + .Returns(organization); sutProvider.GetDependency() - .ManageUsers(organizationAbility.Id) + .ManageUsers(organization.Id) .Returns(true); sutProvider.GetDependency() @@ -1398,7 +1397,7 @@ OrganizationUserInvite invite, SutProvider sutProvider) .Returns(oldUserData); sutProvider.GetDependency() - .GetManyByOrganizationAsync(organizationAbility.Id, OrganizationUserType.Owner) + .GetManyByOrganizationAsync(organization.Id, OrganizationUserType.Owner) .Returns(new List { savingUser }); var exception = await Assert.ThrowsAsync( @@ -1409,7 +1408,7 @@ OrganizationUserInvite invite, SutProvider sutProvider) [Theory, BitAutoData] public async Task SaveUser_WithFlexibleCollections_WithAccessAll_Throws( - OrganizationAbility organizationAbility, + Organization organization, [OrganizationUser(type: OrganizationUserType.User)] OrganizationUser oldUserData, [OrganizationUser(type: OrganizationUserType.User)] OrganizationUser newUserData, [OrganizationUser(type: OrganizationUserType.Owner, status: OrganizationUserStatusType.Confirmed)] OrganizationUser savingUser, @@ -1417,19 +1416,19 @@ OrganizationUserInvite invite, SutProvider sutProvider) IEnumerable groups, SutProvider sutProvider) { - organizationAbility.FlexibleCollections = true; + organization.FlexibleCollections = true; newUserData.Id = oldUserData.Id; newUserData.UserId = oldUserData.UserId; - newUserData.OrganizationId = oldUserData.OrganizationId = savingUser.OrganizationId = organizationAbility.Id; + newUserData.OrganizationId = oldUserData.OrganizationId = savingUser.OrganizationId = organization.Id; newUserData.Permissions = CoreHelpers.ClassToJsonData(new Permissions()); newUserData.AccessAll = true; - sutProvider.GetDependency() - .GetOrganizationAbilityAsync(organizationAbility.Id) - .Returns(organizationAbility); + sutProvider.GetDependency() + .GetByIdAsync(organization.Id) + .Returns(organization); sutProvider.GetDependency() - .ManageUsers(organizationAbility.Id) + .ManageUsers(organization.Id) .Returns(true); sutProvider.GetDependency() @@ -1437,7 +1436,7 @@ OrganizationUserInvite invite, SutProvider sutProvider) .Returns(oldUserData); sutProvider.GetDependency() - .GetManyByOrganizationAsync(organizationAbility.Id, OrganizationUserType.Owner) + .GetManyByOrganizationAsync(organization.Id, OrganizationUserType.Owner) .Returns(new List { savingUser }); var exception = await Assert.ThrowsAsync(