From 3f443ac49b2f52f0f6a063c636ce97107ef94b0b Mon Sep 17 00:00:00 2001 From: Vincent Salucci <26154748+vincentsalucci@users.noreply.github.com> Date: Mon, 8 Jul 2024 14:40:35 -0500 Subject: [PATCH] [AC-2662] Remove FC MVP from CurrentContext (#4460) * chore: remove EditAssignedCollections from current context, refs AC-2662 * chore: remove DeleteAssignedCollections from CurrentContext, refs AC-2662 * chore: remove ViewAssignedCollections from CurrentContext, refs AC-2662 --- .../Implementations/OrganizationService.cs | 10 ------- src/Core/Context/CurrentContext.cs | 26 ------------------- src/Core/Context/ICurrentContext.cs | 6 ----- .../Implementations/CollectionService.cs | 1 - .../Services/OrganizationServiceTests.cs | 2 -- .../Services/CollectionServiceTests.cs | 24 ----------------- 6 files changed, 69 deletions(-) diff --git a/src/Core/AdminConsole/Services/Implementations/OrganizationService.cs b/src/Core/AdminConsole/Services/Implementations/OrganizationService.cs index 9bcefa3c7..5ada7324a 100644 --- a/src/Core/AdminConsole/Services/Implementations/OrganizationService.cs +++ b/src/Core/AdminConsole/Services/Implementations/OrganizationService.cs @@ -2178,21 +2178,11 @@ public class OrganizationService : IOrganizationService return false; } - if (permissions.DeleteAssignedCollections && !await _currentContext.DeleteAssignedCollections(organizationId)) - { - return false; - } - if (permissions.EditAnyCollection && !await _currentContext.EditAnyCollection(organizationId)) { return false; } - if (permissions.EditAssignedCollections && !await _currentContext.EditAssignedCollections(organizationId)) - { - return false; - } - if (permissions.ManageResetPassword && !await _currentContext.ManageResetPassword(organizationId)) { return false; diff --git a/src/Core/Context/CurrentContext.cs b/src/Core/Context/CurrentContext.cs index 90ad275d0..52eea7e7f 100644 --- a/src/Core/Context/CurrentContext.cs +++ b/src/Core/Context/CurrentContext.cs @@ -336,32 +336,6 @@ public class CurrentContext : ICurrentContext return await EditAnyCollection(orgId) || (org != null && org.Permissions.DeleteAnyCollection); } - public async Task EditAssignedCollections(Guid orgId) - { - return await OrganizationManager(orgId) || (Organizations?.Any(o => o.Id == orgId - && (o.Permissions?.EditAssignedCollections ?? false)) ?? false); - } - - public async Task DeleteAssignedCollections(Guid orgId) - { - return await OrganizationManager(orgId) || (Organizations?.Any(o => o.Id == orgId - && (o.Permissions?.DeleteAssignedCollections ?? false)) ?? false); - } - - public async Task ViewAssignedCollections(Guid orgId) - { - /* - * Required to display the existing collections under which the new collection can be nested. - * Owner, Admin, Manager, and Provider checks are handled via the EditAssigned/DeleteAssigned context calls. - * This entire method will be moved to the CollectionAuthorizationHandler in the future - */ - - var org = GetOrganization(orgId); - return await EditAssignedCollections(orgId) - || await DeleteAssignedCollections(orgId) - || (org != null && org.Permissions.CreateNewCollections); - } - public async Task ManageGroups(Guid orgId) { return await OrganizationAdmin(orgId) || (Organizations?.Any(o => o.Id == orgId diff --git a/src/Core/Context/ICurrentContext.cs b/src/Core/Context/ICurrentContext.cs index 57fa7271b..480d5f7d1 100644 --- a/src/Core/Context/ICurrentContext.cs +++ b/src/Core/Context/ICurrentContext.cs @@ -46,12 +46,6 @@ public interface ICurrentContext Task AccessReports(Guid orgId); Task EditAnyCollection(Guid orgId); Task ViewAllCollections(Guid orgId); - [Obsolete("Pre-Flexible Collections logic.")] - Task EditAssignedCollections(Guid orgId); - [Obsolete("Pre-Flexible Collections logic.")] - Task DeleteAssignedCollections(Guid orgId); - [Obsolete("Pre-Flexible Collections logic.")] - Task ViewAssignedCollections(Guid orgId); Task ManageGroups(Guid orgId); Task ManagePolicies(Guid orgId); Task ManageSso(Guid orgId); diff --git a/src/Core/Services/Implementations/CollectionService.cs b/src/Core/Services/Implementations/CollectionService.cs index d8d248526..24f0cdf04 100644 --- a/src/Core/Services/Implementations/CollectionService.cs +++ b/src/Core/Services/Implementations/CollectionService.cs @@ -114,7 +114,6 @@ public class CollectionService : ICollectionService public async Task> GetOrganizationCollectionsAsync(Guid organizationId) { if ( - !await _currentContext.ViewAssignedCollections(organizationId) && !await _currentContext.ViewAllCollections(organizationId) && !await _currentContext.ManageUsers(organizationId) && !await _currentContext.ManageGroups(organizationId) && diff --git a/test/Core.Test/AdminConsole/Services/OrganizationServiceTests.cs b/test/Core.Test/AdminConsole/Services/OrganizationServiceTests.cs index 06a8e6abe..d1d6394d5 100644 --- a/test/Core.Test/AdminConsole/Services/OrganizationServiceTests.cs +++ b/test/Core.Test/AdminConsole/Services/OrganizationServiceTests.cs @@ -979,9 +979,7 @@ OrganizationUserInvite invite, SutProvider sutProvider) currentContext.ManageSso(organization.Id).Returns(true); currentContext.AccessEventLogs(organization.Id).Returns(true); currentContext.AccessImportExport(organization.Id).Returns(true); - currentContext.DeleteAssignedCollections(organization.Id).Returns(true); currentContext.EditAnyCollection(organization.Id).Returns(true); - currentContext.EditAssignedCollections(organization.Id).Returns(true); currentContext.ManageResetPassword(organization.Id).Returns(true); currentContext.GetOrganization(organization.Id) .Returns(new CurrentContextOrganization() diff --git a/test/Core.Test/Services/CollectionServiceTests.cs b/test/Core.Test/Services/CollectionServiceTests.cs index 1981d681f..d64e648f3 100644 --- a/test/Core.Test/Services/CollectionServiceTests.cs +++ b/test/Core.Test/Services/CollectionServiceTests.cs @@ -181,27 +181,6 @@ public class CollectionServiceTest .LogOrganizationUserEventAsync(default, default); } - [Theory, BitAutoData] - public async Task GetOrganizationCollectionsAsync_WithViewAssignedCollectionsTrue_ReturnsAssignedCollections( - CollectionDetails collectionDetails, Guid organizationId, Guid userId, SutProvider sutProvider) - { - collectionDetails.OrganizationId = organizationId; - - sutProvider.GetDependency().UserId.Returns(userId); - sutProvider.GetDependency() - .GetManyByUserIdAsync(userId, Arg.Any()) - .Returns(new List { collectionDetails }); - sutProvider.GetDependency().ViewAssignedCollections(organizationId).Returns(true); - - var result = await sutProvider.Sut.GetOrganizationCollectionsAsync(organizationId); - - Assert.Single(result); - Assert.Equal(collectionDetails, result.First()); - - await sutProvider.GetDependency().DidNotReceiveWithAnyArgs().GetManyByOrganizationIdAsync(default); - await sutProvider.GetDependency().Received(1).GetManyByUserIdAsync(userId, Arg.Any()); - } - [Theory, BitAutoData] public async Task GetOrganizationCollectionsAsync_WithViewAllCollectionsTrue_ReturnsAllOrganizationCollections( Collection collection, Guid organizationId, Guid userId, SutProvider sutProvider) @@ -210,7 +189,6 @@ public class CollectionServiceTest sutProvider.GetDependency() .GetManyByOrganizationIdAsync(organizationId) .Returns(new List { collection }); - sutProvider.GetDependency().ViewAssignedCollections(organizationId).Returns(true); sutProvider.GetDependency().ViewAllCollections(organizationId).Returns(true); var result = await sutProvider.Sut.GetOrganizationCollectionsAsync(organizationId); @@ -226,8 +204,6 @@ public class CollectionServiceTest public async Task GetOrganizationCollectionsAsync_WithViewAssignedCollectionsFalse_ThrowsBadRequestException( Guid organizationId, SutProvider sutProvider) { - sutProvider.GetDependency().ViewAssignedCollections(organizationId).Returns(false); - await Assert.ThrowsAsync(() => sutProvider.Sut.GetOrganizationCollectionsAsync(organizationId)); await sutProvider.GetDependency().DidNotReceiveWithAnyArgs().GetManyByOrganizationIdAsync(default);