Skip to content

Commit 2511591

Browse files
Add database support for handling OrganizationConnection migration
1 parent 484a8e4 commit 2511591

File tree

6 files changed

+91
-0
lines changed

6 files changed

+91
-0
lines changed

src/Core/Dirt/Repositories/IOrganizationIntegrationRepository.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Bit.Core.Dirt.Entities;
2+
using Bit.Core.Dirt.Enums;
23
using Bit.Core.Repositories;
34

45
namespace Bit.Core.Dirt.Repositories;
@@ -8,4 +9,6 @@ public interface IOrganizationIntegrationRepository : IRepository<OrganizationIn
89
Task<List<OrganizationIntegration>> GetManyByOrganizationAsync(Guid organizationId);
910

1011
Task<OrganizationIntegration?> GetByTeamsConfigurationTenantIdTeamId(string tenantId, string teamId);
12+
13+
Task<OrganizationIntegration?> GetByOrganizationIdTypeAsync(Guid organizationId, IntegrationType type);
1114
}

src/Infrastructure.Dapper/Dirt/Repositories/OrganizationIntegrationRepository.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Data;
22
using Bit.Core.Dirt.Entities;
3+
using Bit.Core.Dirt.Enums;
34
using Bit.Core.Dirt.Repositories;
45
using Bit.Core.Settings;
56
using Bit.Infrastructure.Dapper.Repositories;
@@ -43,4 +44,17 @@ public async Task<List<OrganizationIntegration>> GetManyByOrganizationAsync(Guid
4344
return result;
4445
}
4546
}
47+
48+
public async Task<OrganizationIntegration?> GetByOrganizationIdTypeAsync(Guid organizationId, IntegrationType type)
49+
{
50+
using (var connection = new SqlConnection(ConnectionString))
51+
{
52+
var result = await connection.QuerySingleOrDefaultAsync<OrganizationIntegration>(
53+
"[dbo].[OrganizationIntegration_ReadByOrganizationIdType]",
54+
new { OrganizationId = organizationId, Type = type },
55+
commandType: CommandType.StoredProcedure);
56+
57+
return result;
58+
}
59+
}
4660
}

src/Infrastructure.EntityFramework/Dirt/Repositories/OrganizationIntegrationRepository.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using AutoMapper;
2+
using Bit.Core.Dirt.Enums;
23
using Bit.Core.Dirt.Repositories;
34
using Bit.Infrastructure.EntityFramework.Dirt.Repositories.Queries;
45
using Bit.Infrastructure.EntityFramework.Repositories;
@@ -38,4 +39,14 @@ public async Task<List<OrganizationIntegration>> GetManyByOrganizationAsync(Guid
3839
return await query.Run(dbContext).SingleOrDefaultAsync();
3940
}
4041
}
42+
43+
public async Task<OrganizationIntegration?> GetByOrganizationIdTypeAsync(Guid organizationId, IntegrationType type)
44+
{
45+
using (var scope = ServiceScopeFactory.CreateScope())
46+
{
47+
var dbContext = GetDatabaseContext(scope);
48+
var query = new OrganizationIntegrationReadByOrganizationIdTypeQuery(organizationId, type);
49+
return await query.Run(dbContext).SingleOrDefaultAsync();
50+
}
51+
}
4152
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using Bit.Core.Dirt.Entities;
2+
using Bit.Core.Dirt.Enums;
3+
using Bit.Infrastructure.EntityFramework.Repositories;
4+
using Bit.Infrastructure.EntityFramework.Repositories.Queries;
5+
6+
namespace Bit.Infrastructure.EntityFramework.Dirt.Repositories.Queries;
7+
8+
public class OrganizationIntegrationReadByOrganizationIdTypeQuery : IQuery<OrganizationIntegration>
9+
{
10+
private readonly Guid _organizationId;
11+
private readonly IntegrationType _type;
12+
13+
public OrganizationIntegrationReadByOrganizationIdTypeQuery(Guid organizationId, IntegrationType type)
14+
{
15+
_organizationId = organizationId;
16+
_type = type;
17+
}
18+
19+
public IQueryable<OrganizationIntegration> Run(DatabaseContext dbContext)
20+
{
21+
var query = from oi in dbContext.OrganizationIntegrations
22+
where oi.OrganizationId == _organizationId && oi.Type == _type
23+
select new OrganizationIntegration()
24+
{
25+
Id = oi.Id,
26+
OrganizationId = oi.OrganizationId,
27+
Type = oi.Type,
28+
Configuration = oi.Configuration,
29+
};
30+
return query;
31+
}
32+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CREATE PROCEDURE [dbo].[OrganizationIntegration_ReadByOrganizationIdType]
2+
@OrganizationId UNIQUEIDENTIFIER,
3+
@Type SMALLINT
4+
AS
5+
BEGIN
6+
SET NOCOUNT ON
7+
8+
SELECT
9+
*
10+
FROM
11+
[dbo].[OrganizationIntegrationView]
12+
WHERE
13+
[OrganizationId] = @OrganizationId
14+
AND [Type] = @Type
15+
END
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CREATE OR ALTER PROCEDURE [dbo].[OrganizationIntegration_ReadByOrganizationIdType]
2+
@OrganizationId UNIQUEIDENTIFIER,
3+
@Type SMALLINT
4+
AS
5+
BEGIN
6+
SET NOCOUNT ON
7+
8+
SELECT
9+
*
10+
FROM
11+
[dbo].[OrganizationIntegrationView]
12+
WHERE
13+
[OrganizationId] = @OrganizationId
14+
AND [Type] = @Type
15+
END
16+
GO

0 commit comments

Comments
 (0)