diff --git a/src/Core/AdminConsole/Services/Implementations/OrganizationService.cs b/src/Core/AdminConsole/Services/Implementations/OrganizationService.cs index 6850ab013..43890919e 100644 --- a/src/Core/AdminConsole/Services/Implementations/OrganizationService.cs +++ b/src/Core/AdminConsole/Services/Implementations/OrganizationService.cs @@ -64,6 +64,8 @@ public class OrganizationService : IOrganizationService private readonly IDataProtectorTokenFactory _orgUserInviteTokenDataFactory; private readonly IFeatureService _featureService; + private bool FlexibleCollectionsIsEnabled => _featureService.IsEnabled(FeatureFlagKeys.FlexibleCollections, _currentContext); + public OrganizationService( IOrganizationRepository organizationRepository, IOrganizationUserRepository organizationUserRepository, @@ -1968,6 +1970,11 @@ public class OrganizationService : IOrganizationService { throw new BadRequestException("Custom users can only grant the same custom permissions that they have."); } + + if (FlexibleCollectionsIsEnabled && newType == OrganizationUserType.Manager && oldType is not OrganizationUserType.Manager) + { + throw new BadRequestException("Manager role is deprecated after Flexible Collections."); + } } private async Task ValidateOrganizationCustomPermissionsEnabledAsync(Guid organizationId, OrganizationUserType newType) diff --git a/src/Core/Context/CurrentContext.cs b/src/Core/Context/CurrentContext.cs index ea0235ca2..478edda0d 100644 --- a/src/Core/Context/CurrentContext.cs +++ b/src/Core/Context/CurrentContext.cs @@ -283,6 +283,11 @@ public class CurrentContext : ICurrentContext public async Task OrganizationManager(Guid orgId) { + if (FlexibleCollectionsIsEnabled) + { + throw new FeatureUnavailableException("Flexible Collections is ON when it should be OFF."); + } + return await OrganizationAdmin(orgId) || (Organizations?.Any(o => o.Id == orgId && o.Type == OrganizationUserType.Manager) ?? false); } diff --git a/src/Core/Context/ICurrentContext.cs b/src/Core/Context/ICurrentContext.cs index 2d3990f32..57fa7271b 100644 --- a/src/Core/Context/ICurrentContext.cs +++ b/src/Core/Context/ICurrentContext.cs @@ -36,6 +36,7 @@ public interface ICurrentContext Task OrganizationUser(Guid orgId); + [Obsolete("Manager role is deprecated after Flexible Collections.")] Task OrganizationManager(Guid orgId); Task OrganizationAdmin(Guid orgId); Task OrganizationOwner(Guid orgId); diff --git a/test/Core.Test/AdminConsole/Services/OrganizationServiceTests.cs b/test/Core.Test/AdminConsole/Services/OrganizationServiceTests.cs index 147ecac1c..00a94efed 100644 --- a/test/Core.Test/AdminConsole/Services/OrganizationServiceTests.cs +++ b/test/Core.Test/AdminConsole/Services/OrganizationServiceTests.cs @@ -826,6 +826,26 @@ public class OrganizationServiceTests }); } + [Theory, BitAutoData] + public async Task InviteUser_WithFCEnabled_WhenInvitingManager_Throws(Organization organization, OrganizationUserInvite invite, + OrganizationUser invitor, SutProvider sutProvider) + { + invite.Type = OrganizationUserType.Manager; + + sutProvider.GetDependency() + .IsEnabled(FeatureFlagKeys.FlexibleCollections, Arg.Any()) + .Returns(true); + + sutProvider.GetDependency() + .ManageUsers(organization.Id) + .Returns(true); + + var exception = await Assert.ThrowsAsync( + () => sutProvider.Sut.InviteUsersAsync(organization.Id, invitor.UserId, new (OrganizationUserInvite, string)[] { (invite, null) })); + + Assert.Contains("manager role is deprecated", exception.Message.ToLowerInvariant()); + } + private void InviteUserHelper_ArrangeValidPermissions(Organization organization, OrganizationUser savingUser, SutProvider sutProvider) { @@ -1106,6 +1126,38 @@ public class OrganizationServiceTests Assert.Contains("custom users can not manage admins or owners", exception.Message.ToLowerInvariant()); } + [Theory, BitAutoData] + public async Task SaveUser_WithFCEnabled_WhenUpgradingToManager_Throws( + Organization organization, + [OrganizationUser(type: OrganizationUserType.User)] OrganizationUser oldUserData, + [OrganizationUser(type: OrganizationUserType.Manager)] OrganizationUser newUserData, + IEnumerable collections, + IEnumerable groups, + SutProvider sutProvider) + { + sutProvider.GetDependency() + .IsEnabled(FeatureFlagKeys.FlexibleCollections, Arg.Any()) + .Returns(true); + + sutProvider.GetDependency() + .ManageUsers(organization.Id) + .Returns(true); + + sutProvider.GetDependency() + .GetByIdAsync(oldUserData.Id) + .Returns(oldUserData); + + newUserData.Id = oldUserData.Id; + newUserData.UserId = oldUserData.UserId; + newUserData.OrganizationId = oldUserData.OrganizationId = organization.Id; + newUserData.Permissions = CoreHelpers.ClassToJsonData(new Permissions()); + + var exception = await Assert.ThrowsAsync( + () => sutProvider.Sut.SaveUserAsync(newUserData, oldUserData.UserId, collections, groups)); + + Assert.Contains("manager role is deprecated", exception.Message.ToLowerInvariant()); + } + [Theory, BitAutoData] public async Task DeleteUser_InvalidUser(OrganizationUser organizationUser, OrganizationUser deletingUser, SutProvider sutProvider)