mirror of
https://github.com/bitwarden/server.git
synced 2025-07-12 05:13:58 -05:00
[PM-11127] Write OrganizationInstallation
record when license is retrieved (#5090)
* Add SQL files * Add SQL Server migration * Add Core entity * Add Dapper repository * Add EF repository * Add EF migrations * Save OrganizationInstallation during GetLicense invocation * Run dotnet format
This commit is contained in:
@ -0,0 +1,29 @@
|
||||
using Bit.Infrastructure.EntityFramework.Billing.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Billing.Configurations;
|
||||
|
||||
public class OrganizationInstallationEntityTypeConfiguration : IEntityTypeConfiguration<OrganizationInstallation>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<OrganizationInstallation> builder)
|
||||
{
|
||||
builder
|
||||
.Property(oi => oi.Id)
|
||||
.ValueGeneratedNever();
|
||||
|
||||
builder
|
||||
.HasKey(oi => oi.Id)
|
||||
.IsClustered();
|
||||
|
||||
builder
|
||||
.HasIndex(oi => oi.OrganizationId)
|
||||
.IsClustered(false);
|
||||
|
||||
builder
|
||||
.HasIndex(oi => oi.InstallationId)
|
||||
.IsClustered(false);
|
||||
|
||||
builder.ToTable(nameof(OrganizationInstallation));
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using AutoMapper;
|
||||
using Bit.Infrastructure.EntityFramework.AdminConsole.Models;
|
||||
using Bit.Infrastructure.EntityFramework.Models;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Billing.Models;
|
||||
|
||||
public class OrganizationInstallation : Core.Billing.Entities.OrganizationInstallation
|
||||
{
|
||||
public virtual Installation Installation { get; set; }
|
||||
public virtual Organization Organization { get; set; }
|
||||
}
|
||||
|
||||
public class OrganizationInstallationMapperProfile : Profile
|
||||
{
|
||||
public OrganizationInstallationMapperProfile()
|
||||
{
|
||||
CreateMap<Core.Billing.Entities.OrganizationInstallation, OrganizationInstallation>().ReverseMap();
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
using AutoMapper;
|
||||
using Bit.Core.Billing.Entities;
|
||||
using Bit.Core.Billing.Repositories;
|
||||
using Bit.Infrastructure.EntityFramework.Repositories;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using EFOrganizationInstallation = Bit.Infrastructure.EntityFramework.Billing.Models.OrganizationInstallation;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.Billing.Repositories;
|
||||
|
||||
public class OrganizationInstallationRepository(
|
||||
IMapper mapper,
|
||||
IServiceScopeFactory serviceScopeFactory) : Repository<OrganizationInstallation, EFOrganizationInstallation, Guid>(
|
||||
serviceScopeFactory,
|
||||
mapper,
|
||||
context => context.OrganizationInstallations), IOrganizationInstallationRepository
|
||||
{
|
||||
public async Task<OrganizationInstallation> GetByInstallationIdAsync(Guid installationId)
|
||||
{
|
||||
using var serviceScope = ServiceScopeFactory.CreateScope();
|
||||
|
||||
var databaseContext = GetDatabaseContext(serviceScope);
|
||||
|
||||
var query =
|
||||
from organizationInstallation in databaseContext.OrganizationInstallations
|
||||
where organizationInstallation.Id == installationId
|
||||
select organizationInstallation;
|
||||
|
||||
return await query.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<ICollection<OrganizationInstallation>> GetByOrganizationIdAsync(Guid organizationId)
|
||||
{
|
||||
using var serviceScope = ServiceScopeFactory.CreateScope();
|
||||
|
||||
var databaseContext = GetDatabaseContext(serviceScope);
|
||||
|
||||
var query =
|
||||
from organizationInstallation in databaseContext.OrganizationInstallations
|
||||
where organizationInstallation.OrganizationId == organizationId
|
||||
select organizationInstallation;
|
||||
|
||||
return await query.ToArrayAsync();
|
||||
}
|
||||
}
|
@ -78,6 +78,7 @@ public class DatabaseContext : DbContext
|
||||
public DbSet<ClientOrganizationMigrationRecord> ClientOrganizationMigrationRecords { get; set; }
|
||||
public DbSet<PasswordHealthReportApplication> PasswordHealthReportApplications { get; set; }
|
||||
public DbSet<SecurityTask> SecurityTasks { get; set; }
|
||||
public DbSet<OrganizationInstallation> OrganizationInstallations { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
|
Reference in New Issue
Block a user