mirror of
https://github.com/bitwarden/server.git
synced 2024-11-21 12:05:42 +01:00
[AC-432] Replaced IProviderOrganizationRepository.GetCountByOrganizationIdsAsync with call to IProviderOrganizationRepository.GetByOrganizationId
This commit is contained in:
parent
4daebe4f47
commit
ee6e095e88
@ -373,10 +373,13 @@ public class ProviderService : IProviderService
|
||||
throw new BadRequestException("Provider must be of type Reseller in order to assign Organizations to it.");
|
||||
}
|
||||
|
||||
var existingProviderOrganizationsCount = await _providerOrganizationRepository.GetCountByOrganizationIdsAsync(organizationIds);
|
||||
if (existingProviderOrganizationsCount > 0)
|
||||
foreach (var orgId in organizationIds)
|
||||
{
|
||||
throw new BadRequestException("Organizations must not be assigned to any Provider.");
|
||||
var providerOrganization = await _providerOrganizationRepository.GetByOrganizationId(orgId);
|
||||
if (providerOrganization != null)
|
||||
{
|
||||
throw new BadRequestException("Organizations must not be assigned to any Provider.");
|
||||
}
|
||||
}
|
||||
|
||||
var providerOrganizationsToInsert = organizationIds.Select(orgId => new ProviderOrganization { ProviderId = providerId, OrganizationId = orgId });
|
||||
|
@ -9,5 +9,4 @@ public interface IProviderOrganizationRepository : IRepository<ProviderOrganizat
|
||||
Task<ICollection<ProviderOrganizationOrganizationDetails>> GetManyDetailsByProviderAsync(Guid providerId);
|
||||
Task<ProviderOrganization> GetByOrganizationId(Guid organizationId);
|
||||
Task<IEnumerable<ProviderOrganizationProviderDetails>> GetManyByUserAsync(Guid userId);
|
||||
Task<int> GetCountByOrganizationIdsAsync(IEnumerable<Guid> organizationIds);
|
||||
}
|
||||
|
@ -99,20 +99,6 @@ public class ProviderOrganizationRepository : Repository<ProviderOrganization, G
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<int> GetCountByOrganizationIdsAsync(
|
||||
IEnumerable<Guid> organizationIds)
|
||||
{
|
||||
using (var connection = new SqlConnection(ConnectionString))
|
||||
{
|
||||
var results = await connection.ExecuteScalarAsync<int>(
|
||||
$"[{Schema}].[ProviderOrganization_ReadCountByOrganizationIds]",
|
||||
new { Ids = organizationIds.ToGuidIdArrayTVP() },
|
||||
commandType: CommandType.StoredProcedure);
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
private DataTable BuildProviderOrganizationsTable(SqlBulkCopy bulkCopy, IEnumerable<ProviderOrganization> providerOrganizations)
|
||||
{
|
||||
var po = providerOrganizations.FirstOrDefault();
|
||||
|
@ -67,10 +67,4 @@ public class ProviderOrganizationRepository :
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<int> GetCountByOrganizationIdsAsync(IEnumerable<Guid> organizationIds)
|
||||
{
|
||||
var query = new ProviderOrganizationCountByOrganizationIdsQuery(organizationIds);
|
||||
return await GetCountFromQuery(query);
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
using Bit.Core.Entities.Provider;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
public class ProviderOrganizationCountByOrganizationIdsQuery : IQuery<ProviderOrganization>
|
||||
{
|
||||
private readonly IEnumerable<Guid> _organizationIds;
|
||||
|
||||
public ProviderOrganizationCountByOrganizationIdsQuery(IEnumerable<Guid> organizationIds)
|
||||
{
|
||||
_organizationIds = organizationIds;
|
||||
}
|
||||
|
||||
public IQueryable<ProviderOrganization> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from po in dbContext.ProviderOrganizations
|
||||
where _organizationIds.Contains(po.OrganizationId)
|
||||
select po;
|
||||
return query;
|
||||
}
|
||||
}
|
@ -264,7 +264,6 @@
|
||||
<Build Include="dbo\Stored Procedures\Policy_Update.sql" />
|
||||
<Build Include="dbo\Stored Procedures\ProviderOrganizationOrganizationDetails_ReadByProviderId.sql" />
|
||||
<Build Include="dbo\Stored Procedures\ProviderOrganizationProviderDetails_ReadByUserId.sql" />
|
||||
<Build Include="dbo\Stored Procedures\ProviderOrganization_ReadCountByOrganizationIds.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Provider_ReadByOrganizationId.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Organization_UnassignedToProviderSearch.sql" />
|
||||
<Build Include="dbo\Stored Procedures\ProviderOrganization_Create.sql" />
|
||||
|
@ -1,18 +0,0 @@
|
||||
CREATE PROCEDURE [dbo].[ProviderOrganization_ReadCountByOrganizationIds]
|
||||
@Ids AS [dbo].[GuidIdArray] READONLY
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
IF (SELECT COUNT(1) FROM @Ids) < 1
|
||||
BEGIN
|
||||
RETURN(-1)
|
||||
END
|
||||
|
||||
SELECT
|
||||
COUNT(1)
|
||||
FROM
|
||||
[dbo].[ProviderOrganizationView]
|
||||
WHERE
|
||||
[OrganizationId] IN (SELECT [Id] FROM @Ids)
|
||||
END
|
@ -52,23 +52,3 @@ BEGIN
|
||||
END
|
||||
END
|
||||
GO
|
||||
|
||||
CREATE OR ALTER PROCEDURE [dbo].[ProviderOrganization_ReadCountByOrganizationIds]
|
||||
@Ids AS [dbo].[GuidIdArray] READONLY
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
IF (SELECT COUNT(1) FROM @Ids) < 1
|
||||
BEGIN
|
||||
RETURN(-1)
|
||||
END
|
||||
|
||||
SELECT
|
||||
COUNT(1)
|
||||
FROM
|
||||
[dbo].[ProviderOrganizationView]
|
||||
WHERE
|
||||
[OrganizationId] IN (SELECT [Id] FROM @Ids)
|
||||
END
|
||||
GO
|
Loading…
Reference in New Issue
Block a user