mirror of
https://github.com/bitwarden/server.git
synced 2024-11-22 12:15:36 +01:00
[AC-432] Changed ProviderOrganization_ReadByOrganizationIds to only get count
This commit is contained in:
parent
735775e002
commit
4daebe4f47
@ -373,8 +373,8 @@ public class ProviderService : IProviderService
|
|||||||
throw new BadRequestException("Provider must be of type Reseller in order to assign Organizations to it.");
|
throw new BadRequestException("Provider must be of type Reseller in order to assign Organizations to it.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var existingProviderOrganizations = await _providerOrganizationRepository.GetManyByOrganizationIdsAsync(organizationIds);
|
var existingProviderOrganizationsCount = await _providerOrganizationRepository.GetCountByOrganizationIdsAsync(organizationIds);
|
||||||
if (existingProviderOrganizations.Any())
|
if (existingProviderOrganizationsCount > 0)
|
||||||
{
|
{
|
||||||
throw new BadRequestException("Organizations must not be assigned to any Provider.");
|
throw new BadRequestException("Organizations must not be assigned to any Provider.");
|
||||||
}
|
}
|
||||||
|
@ -9,5 +9,5 @@ public interface IProviderOrganizationRepository : IRepository<ProviderOrganizat
|
|||||||
Task<ICollection<ProviderOrganizationOrganizationDetails>> GetManyDetailsByProviderAsync(Guid providerId);
|
Task<ICollection<ProviderOrganizationOrganizationDetails>> GetManyDetailsByProviderAsync(Guid providerId);
|
||||||
Task<ProviderOrganization> GetByOrganizationId(Guid organizationId);
|
Task<ProviderOrganization> GetByOrganizationId(Guid organizationId);
|
||||||
Task<IEnumerable<ProviderOrganizationProviderDetails>> GetManyByUserAsync(Guid userId);
|
Task<IEnumerable<ProviderOrganizationProviderDetails>> GetManyByUserAsync(Guid userId);
|
||||||
Task<IEnumerable<ProviderOrganization>> GetManyByOrganizationIdsAsync(IEnumerable<Guid> organizationIds);
|
Task<int> GetCountByOrganizationIdsAsync(IEnumerable<Guid> organizationIds);
|
||||||
}
|
}
|
||||||
|
@ -99,17 +99,17 @@ public class ProviderOrganizationRepository : Repository<ProviderOrganization, G
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<ProviderOrganization>> GetManyByOrganizationIdsAsync(
|
public async Task<int> GetCountByOrganizationIdsAsync(
|
||||||
IEnumerable<Guid> organizationIds)
|
IEnumerable<Guid> organizationIds)
|
||||||
{
|
{
|
||||||
using (var connection = new SqlConnection(ConnectionString))
|
using (var connection = new SqlConnection(ConnectionString))
|
||||||
{
|
{
|
||||||
var results = await connection.QueryAsync<ProviderOrganization>(
|
var results = await connection.ExecuteScalarAsync<int>(
|
||||||
$"[{Schema}].[ProviderOrganization_ReadByOrganizationIds]",
|
$"[{Schema}].[ProviderOrganization_ReadCountByOrganizationIds]",
|
||||||
new { Ids = organizationIds.ToGuidIdArrayTVP() },
|
new { Ids = organizationIds.ToGuidIdArrayTVP() },
|
||||||
commandType: CommandType.StoredProcedure);
|
commandType: CommandType.StoredProcedure);
|
||||||
|
|
||||||
return results.ToList();
|
return results;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,15 +68,9 @@ public class ProviderOrganizationRepository :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<ProviderOrganization>> GetManyByOrganizationIdsAsync(IEnumerable<Guid> organizationIds)
|
public async Task<int> GetCountByOrganizationIdsAsync(IEnumerable<Guid> organizationIds)
|
||||||
{
|
{
|
||||||
using (var scope = ServiceScopeFactory.CreateScope())
|
var query = new ProviderOrganizationCountByOrganizationIdsQuery(organizationIds);
|
||||||
{
|
return await GetCountFromQuery(query);
|
||||||
var dbContext = GetDatabaseContext(scope);
|
|
||||||
var query = from po in dbContext.ProviderOrganizations
|
|
||||||
where organizationIds.Contains(po.OrganizationId)
|
|
||||||
select po;
|
|
||||||
return await query.ToListAsync();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
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,7 @@
|
|||||||
<Build Include="dbo\Stored Procedures\Policy_Update.sql" />
|
<Build Include="dbo\Stored Procedures\Policy_Update.sql" />
|
||||||
<Build Include="dbo\Stored Procedures\ProviderOrganizationOrganizationDetails_ReadByProviderId.sql" />
|
<Build Include="dbo\Stored Procedures\ProviderOrganizationOrganizationDetails_ReadByProviderId.sql" />
|
||||||
<Build Include="dbo\Stored Procedures\ProviderOrganizationProviderDetails_ReadByUserId.sql" />
|
<Build Include="dbo\Stored Procedures\ProviderOrganizationProviderDetails_ReadByUserId.sql" />
|
||||||
<Build Include="dbo\Stored Procedures\ProviderOrganization_ReadByOrganizationIds.sql" />
|
<Build Include="dbo\Stored Procedures\ProviderOrganization_ReadCountByOrganizationIds.sql" />
|
||||||
<Build Include="dbo\Stored Procedures\Provider_ReadByOrganizationId.sql" />
|
<Build Include="dbo\Stored Procedures\Provider_ReadByOrganizationId.sql" />
|
||||||
<Build Include="dbo\Stored Procedures\Organization_UnassignedToProviderSearch.sql" />
|
<Build Include="dbo\Stored Procedures\Organization_UnassignedToProviderSearch.sql" />
|
||||||
<Build Include="dbo\Stored Procedures\ProviderOrganization_Create.sql" />
|
<Build Include="dbo\Stored Procedures\ProviderOrganization_Create.sql" />
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
CREATE PROCEDURE [dbo].[ProviderOrganization_ReadByOrganizationIds]
|
CREATE PROCEDURE [dbo].[ProviderOrganization_ReadCountByOrganizationIds]
|
||||||
@Ids AS [dbo].[GuidIdArray] READONLY
|
@Ids AS [dbo].[GuidIdArray] READONLY
|
||||||
AS
|
AS
|
||||||
BEGIN
|
BEGIN
|
||||||
@ -10,7 +10,7 @@ BEGIN
|
|||||||
END
|
END
|
||||||
|
|
||||||
SELECT
|
SELECT
|
||||||
*
|
COUNT(1)
|
||||||
FROM
|
FROM
|
||||||
[dbo].[ProviderOrganizationView]
|
[dbo].[ProviderOrganizationView]
|
||||||
WHERE
|
WHERE
|
@ -53,7 +53,7 @@ BEGIN
|
|||||||
END
|
END
|
||||||
GO
|
GO
|
||||||
|
|
||||||
CREATE OR ALTER PROCEDURE [dbo].[ProviderOrganization_ReadByOrganizationIds]
|
CREATE OR ALTER PROCEDURE [dbo].[ProviderOrganization_ReadCountByOrganizationIds]
|
||||||
@Ids AS [dbo].[GuidIdArray] READONLY
|
@Ids AS [dbo].[GuidIdArray] READONLY
|
||||||
AS
|
AS
|
||||||
BEGIN
|
BEGIN
|
||||||
@ -65,7 +65,7 @@ BEGIN
|
|||||||
END
|
END
|
||||||
|
|
||||||
SELECT
|
SELECT
|
||||||
*
|
COUNT(1)
|
||||||
FROM
|
FROM
|
||||||
[dbo].[ProviderOrganizationView]
|
[dbo].[ProviderOrganizationView]
|
||||||
WHERE
|
WHERE
|
||||||
|
Loading…
Reference in New Issue
Block a user