mirror of
https://github.com/bitwarden/server
synced 2026-02-06 19:53:21 +00:00
Move all event integration code to Dirt (#6757)
* Move all event integration code to Dirt * Format to fix lint
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
using AutoMapper;
|
||||
using Bit.Infrastructure.EntityFramework.AdminConsole.Models;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Dirt.Models;
|
||||
|
||||
public class OrganizationIntegration : Core.Dirt.Entities.OrganizationIntegration
|
||||
{
|
||||
public virtual required Organization Organization { get; set; }
|
||||
}
|
||||
|
||||
public class OrganizationIntegrationMapperProfile : Profile
|
||||
{
|
||||
public OrganizationIntegrationMapperProfile()
|
||||
{
|
||||
CreateMap<Core.Dirt.Entities.OrganizationIntegration, OrganizationIntegration>().ReverseMap();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using AutoMapper;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Dirt.Models;
|
||||
|
||||
public class OrganizationIntegrationConfiguration : Core.Dirt.Entities.OrganizationIntegrationConfiguration
|
||||
{
|
||||
public virtual required OrganizationIntegration OrganizationIntegration { get; set; }
|
||||
}
|
||||
|
||||
public class OrganizationIntegrationConfigurationMapperProfile : Profile
|
||||
{
|
||||
public OrganizationIntegrationConfigurationMapperProfile()
|
||||
{
|
||||
CreateMap<Core.Dirt.Entities.OrganizationIntegrationConfiguration, OrganizationIntegrationConfiguration>().ReverseMap();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using AutoMapper;
|
||||
using Bit.Core.Dirt.Enums;
|
||||
using Bit.Core.Dirt.Models.Data.EventIntegrations;
|
||||
using Bit.Core.Dirt.Repositories;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Infrastructure.EntityFramework.Dirt.Repositories.Queries;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using OrganizationIntegrationConfiguration = Bit.Core.Dirt.Entities.OrganizationIntegrationConfiguration;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Dirt.Repositories;
|
||||
|
||||
public class OrganizationIntegrationConfigurationRepository : Repository<OrganizationIntegrationConfiguration, Dirt.Models.OrganizationIntegrationConfiguration, Guid>, IOrganizationIntegrationConfigurationRepository
|
||||
{
|
||||
public OrganizationIntegrationConfigurationRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper)
|
||||
: base(serviceScopeFactory, mapper, context => context.OrganizationIntegrationConfigurations)
|
||||
{ }
|
||||
|
||||
public async Task<List<OrganizationIntegrationConfigurationDetails>>
|
||||
GetManyByEventTypeOrganizationIdIntegrationType(EventType eventType, Guid organizationId,
|
||||
IntegrationType integrationType)
|
||||
{
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
var query = new OrganizationIntegrationConfigurationDetailsReadManyByEventTypeOrganizationIdIntegrationTypeQuery(
|
||||
organizationId,
|
||||
eventType,
|
||||
integrationType
|
||||
);
|
||||
return await query.Run(dbContext).ToListAsync();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<OrganizationIntegrationConfigurationDetails>> GetAllConfigurationDetailsAsync()
|
||||
{
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
var query = new OrganizationIntegrationConfigurationDetailsReadManyQuery();
|
||||
return await query.Run(dbContext).ToListAsync();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<OrganizationIntegrationConfiguration>> GetManyByIntegrationAsync(
|
||||
Guid organizationIntegrationId)
|
||||
{
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
var query = new OrganizationIntegrationConfigurationReadManyByOrganizationIntegrationIdQuery(
|
||||
organizationIntegrationId
|
||||
);
|
||||
return await query.Run(dbContext).ToListAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using AutoMapper;
|
||||
using Bit.Core.Dirt.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Dirt.Repositories.Queries;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using OrganizationIntegration = Bit.Core.Dirt.Entities.OrganizationIntegration;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Dirt.Repositories;
|
||||
|
||||
public class OrganizationIntegrationRepository :
|
||||
Repository<OrganizationIntegration, Dirt.Models.OrganizationIntegration, Guid>,
|
||||
IOrganizationIntegrationRepository
|
||||
{
|
||||
public OrganizationIntegrationRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper)
|
||||
: base(serviceScopeFactory, mapper, (DatabaseContext context) => context.OrganizationIntegrations)
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<List<OrganizationIntegration>> GetManyByOrganizationAsync(Guid organizationId)
|
||||
{
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
var query = new OrganizationIntegrationReadManyByOrganizationIdQuery(organizationId);
|
||||
return await query.Run(dbContext).ToListAsync();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<OrganizationIntegration?> GetByTeamsConfigurationTenantIdTeamId(
|
||||
string tenantId,
|
||||
string teamId)
|
||||
{
|
||||
using (var scope = ServiceScopeFactory.CreateScope())
|
||||
{
|
||||
var dbContext = GetDatabaseContext(scope);
|
||||
var query = new OrganizationIntegrationReadByTeamsConfigurationTenantIdTeamIdQuery(tenantId: tenantId, teamId: teamId);
|
||||
return await query.Run(dbContext).SingleOrDefaultAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using Bit.Core.Dirt.Enums;
|
||||
using Bit.Core.Dirt.Models.Data.EventIntegrations;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Dirt.Repositories.Queries;
|
||||
|
||||
public class OrganizationIntegrationConfigurationDetailsReadManyByEventTypeOrganizationIdIntegrationTypeQuery(
|
||||
Guid organizationId,
|
||||
EventType eventType,
|
||||
IntegrationType integrationType)
|
||||
: IQuery<OrganizationIntegrationConfigurationDetails>
|
||||
{
|
||||
public IQueryable<OrganizationIntegrationConfigurationDetails> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from oic in dbContext.OrganizationIntegrationConfigurations
|
||||
join oi in dbContext.OrganizationIntegrations on oic.OrganizationIntegrationId equals oi.Id
|
||||
where oi.OrganizationId == organizationId &&
|
||||
oi.Type == integrationType &&
|
||||
(oic.EventType == eventType || oic.EventType == null)
|
||||
select new OrganizationIntegrationConfigurationDetails()
|
||||
{
|
||||
Id = oic.Id,
|
||||
OrganizationId = oi.OrganizationId,
|
||||
OrganizationIntegrationId = oic.OrganizationIntegrationId,
|
||||
IntegrationType = oi.Type,
|
||||
EventType = oic.EventType,
|
||||
Configuration = oic.Configuration,
|
||||
Filters = oic.Filters,
|
||||
IntegrationConfiguration = oi.Configuration,
|
||||
Template = oic.Template
|
||||
};
|
||||
return query;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using Bit.Core.Dirt.Models.Data.EventIntegrations;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Dirt.Repositories.Queries;
|
||||
|
||||
public class OrganizationIntegrationConfigurationDetailsReadManyQuery : IQuery<OrganizationIntegrationConfigurationDetails>
|
||||
{
|
||||
public IQueryable<OrganizationIntegrationConfigurationDetails> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from oic in dbContext.OrganizationIntegrationConfigurations
|
||||
join oi in dbContext.OrganizationIntegrations on oic.OrganizationIntegrationId equals oi.Id into oioic
|
||||
from oi in dbContext.OrganizationIntegrations
|
||||
select new OrganizationIntegrationConfigurationDetails()
|
||||
{
|
||||
Id = oic.Id,
|
||||
OrganizationId = oi.OrganizationId,
|
||||
OrganizationIntegrationId = oic.OrganizationIntegrationId,
|
||||
IntegrationType = oi.Type,
|
||||
EventType = oic.EventType,
|
||||
Configuration = oic.Configuration,
|
||||
Filters = oic.Filters,
|
||||
IntegrationConfiguration = oi.Configuration,
|
||||
Template = oic.Template
|
||||
};
|
||||
return query;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using Bit.Core.Dirt.Entities;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Dirt.Repositories.Queries;
|
||||
|
||||
public class OrganizationIntegrationConfigurationReadManyByOrganizationIntegrationIdQuery : IQuery<OrganizationIntegrationConfiguration>
|
||||
{
|
||||
private readonly Guid _organizationIntegrationId;
|
||||
|
||||
public OrganizationIntegrationConfigurationReadManyByOrganizationIntegrationIdQuery(Guid organizationIntegrationId)
|
||||
{
|
||||
_organizationIntegrationId = organizationIntegrationId;
|
||||
}
|
||||
|
||||
public IQueryable<OrganizationIntegrationConfiguration> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from oic in dbContext.OrganizationIntegrationConfigurations
|
||||
where oic.OrganizationIntegrationId == _organizationIntegrationId
|
||||
select new OrganizationIntegrationConfiguration()
|
||||
{
|
||||
Id = oic.Id,
|
||||
OrganizationIntegrationId = oic.OrganizationIntegrationId,
|
||||
Configuration = oic.Configuration,
|
||||
EventType = oic.EventType,
|
||||
Filters = oic.Filters,
|
||||
Template = oic.Template,
|
||||
RevisionDate = oic.RevisionDate
|
||||
};
|
||||
return query;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
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 OrganizationIntegrationReadByTeamsConfigurationTenantIdTeamIdQuery : IQuery<OrganizationIntegration>
|
||||
{
|
||||
private readonly string _tenantId;
|
||||
private readonly string _teamId;
|
||||
|
||||
public OrganizationIntegrationReadByTeamsConfigurationTenantIdTeamIdQuery(string tenantId, string teamId)
|
||||
{
|
||||
_tenantId = tenantId;
|
||||
_teamId = teamId;
|
||||
}
|
||||
|
||||
public IQueryable<OrganizationIntegration> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query =
|
||||
from oi in dbContext.OrganizationIntegrations
|
||||
where oi.Type == IntegrationType.Teams &&
|
||||
oi.Configuration != null &&
|
||||
oi.Configuration.Contains($"\"TenantId\":\"{_tenantId}\"") &&
|
||||
oi.Configuration.Contains($"\"id\":\"{_teamId}\"")
|
||||
select new OrganizationIntegration()
|
||||
{
|
||||
Id = oi.Id,
|
||||
OrganizationId = oi.OrganizationId,
|
||||
Type = oi.Type,
|
||||
Configuration = oi.Configuration,
|
||||
};
|
||||
return query;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using Bit.Core.Dirt.Entities;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories.Queries;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Dirt.Repositories.Queries;
|
||||
|
||||
public class OrganizationIntegrationReadManyByOrganizationIdQuery : IQuery<OrganizationIntegration>
|
||||
{
|
||||
private readonly Guid _organizationId;
|
||||
|
||||
public OrganizationIntegrationReadManyByOrganizationIdQuery(Guid organizationId)
|
||||
{
|
||||
_organizationId = organizationId;
|
||||
}
|
||||
|
||||
public IQueryable<OrganizationIntegration> Run(DatabaseContext dbContext)
|
||||
{
|
||||
var query = from oi in dbContext.OrganizationIntegrations
|
||||
where oi.OrganizationId == _organizationId
|
||||
select new OrganizationIntegration()
|
||||
{
|
||||
Id = oi.Id,
|
||||
OrganizationId = oi.OrganizationId,
|
||||
Type = oi.Type,
|
||||
Configuration = oi.Configuration,
|
||||
};
|
||||
return query;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user