1
0
mirror of https://github.com/bitwarden/server synced 2026-01-26 14:23:21 +00:00

Add database support for handling OrganizationConnection migration

This commit is contained in:
Brant DeBow
2025-12-31 16:43:59 -05:00
parent 484a8e42dc
commit 2511591449
6 changed files with 91 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
using Bit.Core.Dirt.Entities;
using Bit.Core.Dirt.Enums;
using Bit.Core.Repositories;
namespace Bit.Core.Dirt.Repositories;
@@ -8,4 +9,6 @@ public interface IOrganizationIntegrationRepository : IRepository<OrganizationIn
Task<List<OrganizationIntegration>> GetManyByOrganizationAsync(Guid organizationId);
Task<OrganizationIntegration?> GetByTeamsConfigurationTenantIdTeamId(string tenantId, string teamId);
Task<OrganizationIntegration?> GetByOrganizationIdTypeAsync(Guid organizationId, IntegrationType type);
}

View File

@@ -1,5 +1,6 @@
using System.Data;
using Bit.Core.Dirt.Entities;
using Bit.Core.Dirt.Enums;
using Bit.Core.Dirt.Repositories;
using Bit.Core.Settings;
using Bit.Infrastructure.Dapper.Repositories;
@@ -43,4 +44,17 @@ public class OrganizationIntegrationRepository : Repository<OrganizationIntegrat
return result;
}
}
public async Task<OrganizationIntegration?> GetByOrganizationIdTypeAsync(Guid organizationId, IntegrationType type)
{
using (var connection = new SqlConnection(ConnectionString))
{
var result = await connection.QuerySingleOrDefaultAsync<OrganizationIntegration>(
"[dbo].[OrganizationIntegration_ReadByOrganizationIdType]",
new { OrganizationId = organizationId, Type = type },
commandType: CommandType.StoredProcedure);
return result;
}
}
}

View File

@@ -1,4 +1,5 @@
using AutoMapper;
using Bit.Core.Dirt.Enums;
using Bit.Core.Dirt.Repositories;
using Bit.Infrastructure.EntityFramework.Dirt.Repositories.Queries;
using Bit.Infrastructure.EntityFramework.Repositories;
@@ -38,4 +39,14 @@ public class OrganizationIntegrationRepository :
return await query.Run(dbContext).SingleOrDefaultAsync();
}
}
public async Task<OrganizationIntegration?> GetByOrganizationIdTypeAsync(Guid organizationId, IntegrationType type)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var query = new OrganizationIntegrationReadByOrganizationIdTypeQuery(organizationId, type);
return await query.Run(dbContext).SingleOrDefaultAsync();
}
}
}

View File

@@ -0,0 +1,32 @@
using Bit.Core.Dirt.Entities;
using Bit.Core.Dirt.Enums;
using Bit.Infrastructure.EntityFramework.Repositories;
using Bit.Infrastructure.EntityFramework.Repositories.Queries;
namespace Bit.Infrastructure.EntityFramework.Dirt.Repositories.Queries;
public class OrganizationIntegrationReadByOrganizationIdTypeQuery : IQuery<OrganizationIntegration>
{
private readonly Guid _organizationId;
private readonly IntegrationType _type;
public OrganizationIntegrationReadByOrganizationIdTypeQuery(Guid organizationId, IntegrationType type)
{
_organizationId = organizationId;
_type = type;
}
public IQueryable<OrganizationIntegration> Run(DatabaseContext dbContext)
{
var query = from oi in dbContext.OrganizationIntegrations
where oi.OrganizationId == _organizationId && oi.Type == _type
select new OrganizationIntegration()
{
Id = oi.Id,
OrganizationId = oi.OrganizationId,
Type = oi.Type,
Configuration = oi.Configuration,
};
return query;
}
}

View File

@@ -0,0 +1,15 @@
CREATE PROCEDURE [dbo].[OrganizationIntegration_ReadByOrganizationIdType]
@OrganizationId UNIQUEIDENTIFIER,
@Type SMALLINT
AS
BEGIN
SET NOCOUNT ON
SELECT
*
FROM
[dbo].[OrganizationIntegrationView]
WHERE
[OrganizationId] = @OrganizationId
AND [Type] = @Type
END

View File

@@ -0,0 +1,16 @@
CREATE OR ALTER PROCEDURE [dbo].[OrganizationIntegration_ReadByOrganizationIdType]
@OrganizationId UNIQUEIDENTIFIER,
@Type SMALLINT
AS
BEGIN
SET NOCOUNT ON
SELECT
*
FROM
[dbo].[OrganizationIntegrationView]
WHERE
[OrganizationId] = @OrganizationId
AND [Type] = @Type
END
GO