mirror of
https://github.com/bitwarden/server
synced 2025-12-16 00:03:54 +00:00
Create PlayData table and services
Shift from seeded data tracking that is all server-side to play ids and x-play-id headers that are appended from the clients to track entities added by tests.
This commit is contained in:
42
src/Core/Entities/PlayData.cs
Normal file
42
src/Core/Entities/PlayData.cs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using Bit.Core.AdminConsole.Entities;
|
||||||
|
using Bit.Core.Utilities;
|
||||||
|
|
||||||
|
namespace Bit.Core.Entities;
|
||||||
|
|
||||||
|
public class PlayData : ITableObject<Guid>
|
||||||
|
{
|
||||||
|
public Guid Id { get; set; }
|
||||||
|
[MaxLength(256)]
|
||||||
|
public string PlayId { get; init; } = null!;
|
||||||
|
public Guid? UserId { get; init; }
|
||||||
|
public Guid? OrganizationId { get; init; }
|
||||||
|
public DateTime CreationDate { get; init; }
|
||||||
|
|
||||||
|
protected PlayData() { }
|
||||||
|
|
||||||
|
public void SetNewId()
|
||||||
|
{
|
||||||
|
Id = CoreHelpers.GenerateComb();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PlayData Create(User user, string playId)
|
||||||
|
{
|
||||||
|
return new PlayData
|
||||||
|
{
|
||||||
|
PlayId = playId,
|
||||||
|
UserId = user.Id,
|
||||||
|
CreationDate = DateTime.UtcNow
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PlayData Create(Organization organization, string playId)
|
||||||
|
{
|
||||||
|
return new PlayData
|
||||||
|
{
|
||||||
|
PlayId = playId,
|
||||||
|
OrganizationId = organization.Id,
|
||||||
|
CreationDate = DateTime.UtcNow
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
11
src/Core/Repositories/IPlayDataRepository.cs
Normal file
11
src/Core/Repositories/IPlayDataRepository.cs
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
using Bit.Core.Entities;
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
|
namespace Bit.Core.Repositories;
|
||||||
|
|
||||||
|
public interface IPlayDataRepository : IRepository<PlayData, Guid>
|
||||||
|
{
|
||||||
|
Task<ICollection<PlayData>> GetByPlayIdAsync(string playId);
|
||||||
|
Task DeleteByPlayIdAsync(string playId);
|
||||||
|
}
|
||||||
7
src/Core/Services/IPlayIdService.cs
Normal file
7
src/Core/Services/IPlayIdService.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Bit.Core.Services;
|
||||||
|
|
||||||
|
public interface IPlayIdService
|
||||||
|
{
|
||||||
|
string? PlayId { get; set; }
|
||||||
|
bool InPlay(out string playId);
|
||||||
|
}
|
||||||
13
src/Core/Services/Implementations/PlayIdService.cs
Normal file
13
src/Core/Services/Implementations/PlayIdService.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
|
||||||
|
namespace Bit.Core.Services;
|
||||||
|
|
||||||
|
public class PlayIdService(IHostEnvironment hostEnvironment) : IPlayIdService
|
||||||
|
{
|
||||||
|
public string? PlayId { get; set; }
|
||||||
|
public bool InPlay(out string playId)
|
||||||
|
{
|
||||||
|
playId = PlayId ?? string.Empty;
|
||||||
|
return !string.IsNullOrEmpty(PlayId) && hostEnvironment.IsDevelopment();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ using Bit.Core.Entities;
|
|||||||
using Bit.Core.Models.Data.Organizations;
|
using Bit.Core.Models.Data.Organizations;
|
||||||
using Bit.Core.Models.Data.Organizations.OrganizationUsers;
|
using Bit.Core.Models.Data.Organizations.OrganizationUsers;
|
||||||
using Bit.Core.Repositories;
|
using Bit.Core.Repositories;
|
||||||
|
using Bit.Core.Services;
|
||||||
using Bit.Core.Settings;
|
using Bit.Core.Settings;
|
||||||
using Dapper;
|
using Dapper;
|
||||||
using Microsoft.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
@@ -17,16 +18,37 @@ namespace Bit.Infrastructure.Dapper.Repositories;
|
|||||||
|
|
||||||
public class OrganizationRepository : Repository<Organization, Guid>, IOrganizationRepository
|
public class OrganizationRepository : Repository<Organization, Guid>, IOrganizationRepository
|
||||||
{
|
{
|
||||||
|
private readonly IPlayIdService _playIdService;
|
||||||
|
private readonly IPlayDataRepository _playDataRepository;
|
||||||
private readonly ILogger<OrganizationRepository> _logger;
|
private readonly ILogger<OrganizationRepository> _logger;
|
||||||
|
|
||||||
public OrganizationRepository(
|
public OrganizationRepository(
|
||||||
|
IPlayIdService playIdService,
|
||||||
|
IPlayDataRepository playDataRepository,
|
||||||
GlobalSettings globalSettings,
|
GlobalSettings globalSettings,
|
||||||
ILogger<OrganizationRepository> logger)
|
ILogger<OrganizationRepository> logger)
|
||||||
: base(globalSettings.SqlServer.ConnectionString, globalSettings.SqlServer.ReadOnlyConnectionString)
|
: base(globalSettings.SqlServer.ConnectionString, globalSettings.SqlServer.ReadOnlyConnectionString)
|
||||||
{
|
{
|
||||||
|
_playIdService = playIdService;
|
||||||
|
_playDataRepository = playDataRepository;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override async Task<Organization> CreateAsync(Organization obj)
|
||||||
|
{
|
||||||
|
await base.CreateAsync(obj);
|
||||||
|
|
||||||
|
if (_playIdService.InPlay(out var playId))
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Associating organization {OrganizationId} with Play ID {PlayId}",
|
||||||
|
obj.Id, playId);
|
||||||
|
|
||||||
|
await _playDataRepository.CreateAsync(PlayData.Create(obj, playId));
|
||||||
|
}
|
||||||
|
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<Organization?> GetByIdentifierAsync(string identifier)
|
public async Task<Organization?> GetByIdentifierAsync(string identifier)
|
||||||
{
|
{
|
||||||
using (var connection = new SqlConnection(ConnectionString))
|
using (var connection = new SqlConnection(ConnectionString))
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ public static class DapperServiceCollectionExtensions
|
|||||||
services.AddSingleton<IOrganizationRepository, OrganizationRepository>();
|
services.AddSingleton<IOrganizationRepository, OrganizationRepository>();
|
||||||
services.AddSingleton<IOrganizationSponsorshipRepository, OrganizationSponsorshipRepository>();
|
services.AddSingleton<IOrganizationSponsorshipRepository, OrganizationSponsorshipRepository>();
|
||||||
services.AddSingleton<IOrganizationUserRepository, OrganizationUserRepository>();
|
services.AddSingleton<IOrganizationUserRepository, OrganizationUserRepository>();
|
||||||
|
services.AddSingleton<IPlayDataRepository, PlayDataRepository>();
|
||||||
services.AddSingleton<IPolicyRepository, PolicyRepository>();
|
services.AddSingleton<IPolicyRepository, PolicyRepository>();
|
||||||
services.AddSingleton<IProviderOrganizationRepository, ProviderOrganizationRepository>();
|
services.AddSingleton<IProviderOrganizationRepository, ProviderOrganizationRepository>();
|
||||||
services.AddSingleton<IProviderRepository, ProviderRepository>();
|
services.AddSingleton<IProviderRepository, ProviderRepository>();
|
||||||
|
|||||||
45
src/Infrastructure.Dapper/Repositories/PlayDataRepository.cs
Normal file
45
src/Infrastructure.Dapper/Repositories/PlayDataRepository.cs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
using System.Data;
|
||||||
|
using Bit.Core.Entities;
|
||||||
|
using Bit.Core.Repositories;
|
||||||
|
using Bit.Core.Settings;
|
||||||
|
using Dapper;
|
||||||
|
using Microsoft.Data.SqlClient;
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
|
namespace Bit.Infrastructure.Dapper.Repositories;
|
||||||
|
|
||||||
|
public class PlayDataRepository : Repository<PlayData, Guid>, IPlayDataRepository
|
||||||
|
{
|
||||||
|
public PlayDataRepository(GlobalSettings globalSettings)
|
||||||
|
: this(globalSettings.SqlServer.ConnectionString, globalSettings.SqlServer.ReadOnlyConnectionString)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
public PlayDataRepository(string connectionString, string readOnlyConnectionString)
|
||||||
|
: base(connectionString, readOnlyConnectionString)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
public async Task<ICollection<PlayData>> GetByPlayIdAsync(string playId)
|
||||||
|
{
|
||||||
|
using (var connection = new SqlConnection(ConnectionString))
|
||||||
|
{
|
||||||
|
var results = await connection.QueryAsync<PlayData>(
|
||||||
|
"[dbo].[PlayData_ReadByPlayId]",
|
||||||
|
new { PlayId = playId },
|
||||||
|
commandType: CommandType.StoredProcedure);
|
||||||
|
|
||||||
|
return results.ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task DeleteByPlayIdAsync(string playId)
|
||||||
|
{
|
||||||
|
using (var connection = new SqlConnection(ConnectionString))
|
||||||
|
{
|
||||||
|
await connection.ExecuteAsync(
|
||||||
|
"[dbo].[PlayData_DeleteByPlayId]",
|
||||||
|
new { PlayId = playId },
|
||||||
|
commandType: CommandType.StoredProcedure);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,10 +5,12 @@ using Bit.Core.Entities;
|
|||||||
using Bit.Core.KeyManagement.UserKey;
|
using Bit.Core.KeyManagement.UserKey;
|
||||||
using Bit.Core.Models.Data;
|
using Bit.Core.Models.Data;
|
||||||
using Bit.Core.Repositories;
|
using Bit.Core.Repositories;
|
||||||
|
using Bit.Core.Services;
|
||||||
using Bit.Core.Settings;
|
using Bit.Core.Settings;
|
||||||
using Dapper;
|
using Dapper;
|
||||||
using Microsoft.AspNetCore.DataProtection;
|
using Microsoft.AspNetCore.DataProtection;
|
||||||
using Microsoft.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
#nullable enable
|
#nullable enable
|
||||||
|
|
||||||
@@ -16,14 +18,23 @@ namespace Bit.Infrastructure.Dapper.Repositories;
|
|||||||
|
|
||||||
public class UserRepository : Repository<User, Guid>, IUserRepository
|
public class UserRepository : Repository<User, Guid>, IUserRepository
|
||||||
{
|
{
|
||||||
|
private readonly IPlayIdService _playIdService;
|
||||||
|
private readonly IPlayDataRepository _playDataRepository;
|
||||||
private readonly IDataProtector _dataProtector;
|
private readonly IDataProtector _dataProtector;
|
||||||
|
private readonly ILogger<UserRepository> _logger;
|
||||||
|
|
||||||
public UserRepository(
|
public UserRepository(
|
||||||
|
IPlayIdService playIdService,
|
||||||
GlobalSettings globalSettings,
|
GlobalSettings globalSettings,
|
||||||
IDataProtectionProvider dataProtectionProvider)
|
IPlayDataRepository playDataRepository,
|
||||||
|
IDataProtectionProvider dataProtectionProvider,
|
||||||
|
ILogger<UserRepository> logger)
|
||||||
: base(globalSettings.SqlServer.ConnectionString, globalSettings.SqlServer.ReadOnlyConnectionString)
|
: base(globalSettings.SqlServer.ConnectionString, globalSettings.SqlServer.ReadOnlyConnectionString)
|
||||||
{
|
{
|
||||||
|
_playIdService = playIdService;
|
||||||
|
_playDataRepository = playDataRepository;
|
||||||
_dataProtector = dataProtectionProvider.CreateProtector(Constants.DatabaseFieldProtectorPurpose);
|
_dataProtector = dataProtectionProvider.CreateProtector(Constants.DatabaseFieldProtectorPurpose);
|
||||||
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override async Task<User?> GetByIdAsync(Guid id)
|
public override async Task<User?> GetByIdAsync(Guid id)
|
||||||
@@ -153,6 +164,15 @@ public class UserRepository : Repository<User, Guid>, IUserRepository
|
|||||||
public override async Task<User> CreateAsync(User user)
|
public override async Task<User> CreateAsync(User user)
|
||||||
{
|
{
|
||||||
await ProtectDataAndSaveAsync(user, async () => await base.CreateAsync(user));
|
await ProtectDataAndSaveAsync(user, async () => await base.CreateAsync(user));
|
||||||
|
|
||||||
|
if (_playIdService.InPlay(out var playId))
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Associating user {UserId} with Play ID {PlayId}",
|
||||||
|
user.Id, playId);
|
||||||
|
|
||||||
|
await _playDataRepository.CreateAsync(PlayData.Create(user, playId));
|
||||||
|
}
|
||||||
|
|
||||||
return user;
|
return user;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ using Bit.Core.Enums;
|
|||||||
using Bit.Core.Models.Data.Organizations;
|
using Bit.Core.Models.Data.Organizations;
|
||||||
using Bit.Core.Models.Data.Organizations.OrganizationUsers;
|
using Bit.Core.Models.Data.Organizations.OrganizationUsers;
|
||||||
using Bit.Core.Repositories;
|
using Bit.Core.Repositories;
|
||||||
|
using Bit.Core.Services;
|
||||||
using LinqToDB.Tools;
|
using LinqToDB.Tools;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
@@ -21,14 +22,35 @@ namespace Bit.Infrastructure.EntityFramework.Repositories;
|
|||||||
public class OrganizationRepository : Repository<Core.AdminConsole.Entities.Organization, Organization, Guid>, IOrganizationRepository
|
public class OrganizationRepository : Repository<Core.AdminConsole.Entities.Organization, Organization, Guid>, IOrganizationRepository
|
||||||
{
|
{
|
||||||
private readonly ILogger<OrganizationRepository> _logger;
|
private readonly ILogger<OrganizationRepository> _logger;
|
||||||
|
private readonly IPlayIdService _playIdService;
|
||||||
|
private readonly IPlayDataRepository _playDataRepository;
|
||||||
|
|
||||||
public OrganizationRepository(
|
public OrganizationRepository(
|
||||||
IServiceScopeFactory serviceScopeFactory,
|
IServiceScopeFactory serviceScopeFactory,
|
||||||
IMapper mapper,
|
IMapper mapper,
|
||||||
ILogger<OrganizationRepository> logger)
|
ILogger<OrganizationRepository> logger,
|
||||||
|
IPlayIdService playIdService,
|
||||||
|
IPlayDataRepository playDataRepository)
|
||||||
: base(serviceScopeFactory, mapper, context => context.Organizations)
|
: base(serviceScopeFactory, mapper, context => context.Organizations)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_playIdService = playIdService;
|
||||||
|
_playDataRepository = playDataRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<Core.AdminConsole.Entities.Organization> CreateAsync(Core.AdminConsole.Entities.Organization organization)
|
||||||
|
{
|
||||||
|
var createdOrganization = await base.CreateAsync(organization);
|
||||||
|
|
||||||
|
if (_playIdService.InPlay(out var playId))
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Associating organization {OrganizationId} with Play ID {PlayId}",
|
||||||
|
organization.Id, playId);
|
||||||
|
|
||||||
|
await _playDataRepository.CreateAsync(Core.Entities.PlayData.Create(organization, playId));
|
||||||
|
}
|
||||||
|
|
||||||
|
return createdOrganization;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<Core.AdminConsole.Entities.Organization> GetByIdentifierAsync(string identifier)
|
public async Task<Core.AdminConsole.Entities.Organization> GetByIdentifierAsync(string identifier)
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
using Bit.Infrastructure.EntityFramework.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
|
|
||||||
|
namespace Bit.Infrastructure.EntityFramework.Configurations;
|
||||||
|
|
||||||
|
public class PlayDataEntityTypeConfiguration : IEntityTypeConfiguration<PlayData>
|
||||||
|
{
|
||||||
|
public void Configure(EntityTypeBuilder<PlayData> builder)
|
||||||
|
{
|
||||||
|
builder
|
||||||
|
.Property(pd => pd.Id)
|
||||||
|
.ValueGeneratedNever();
|
||||||
|
|
||||||
|
builder
|
||||||
|
.HasIndex(pd => pd.PlayId)
|
||||||
|
.IsClustered(false);
|
||||||
|
|
||||||
|
builder
|
||||||
|
.HasIndex(pd => pd.UserId)
|
||||||
|
.IsClustered(false);
|
||||||
|
|
||||||
|
builder
|
||||||
|
.HasIndex(pd => pd.OrganizationId)
|
||||||
|
.IsClustered(false);
|
||||||
|
|
||||||
|
builder
|
||||||
|
.HasOne(pd => pd.User)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey(pd => pd.UserId)
|
||||||
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
|
||||||
|
builder
|
||||||
|
.HasOne(pd => pd.Organization)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey(pd => pd.OrganizationId)
|
||||||
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
|
||||||
|
builder
|
||||||
|
.ToTable(nameof(PlayData))
|
||||||
|
.HasCheckConstraint(
|
||||||
|
"CK_PlayData_UserOrOrganization",
|
||||||
|
"([UserId] IS NOT NULL AND [OrganizationId] IS NULL) OR ([UserId] IS NULL AND [OrganizationId] IS NOT NULL)"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -88,6 +88,7 @@ public static class EntityFrameworkServiceCollectionExtensions
|
|||||||
services.AddSingleton<IOrganizationRepository, OrganizationRepository>();
|
services.AddSingleton<IOrganizationRepository, OrganizationRepository>();
|
||||||
services.AddSingleton<IOrganizationSponsorshipRepository, OrganizationSponsorshipRepository>();
|
services.AddSingleton<IOrganizationSponsorshipRepository, OrganizationSponsorshipRepository>();
|
||||||
services.AddSingleton<IOrganizationUserRepository, OrganizationUserRepository>();
|
services.AddSingleton<IOrganizationUserRepository, OrganizationUserRepository>();
|
||||||
|
services.AddSingleton<IPlayDataRepository, PlayDataRepository>();
|
||||||
services.AddSingleton<IPolicyRepository, PolicyRepository>();
|
services.AddSingleton<IPolicyRepository, PolicyRepository>();
|
||||||
services.AddSingleton<IProviderOrganizationRepository, ProviderOrganizationRepository>();
|
services.AddSingleton<IProviderOrganizationRepository, ProviderOrganizationRepository>();
|
||||||
services.AddSingleton<IProviderRepository, ProviderRepository>();
|
services.AddSingleton<IProviderRepository, ProviderRepository>();
|
||||||
|
|||||||
19
src/Infrastructure.EntityFramework/Models/PlayData.cs
Normal file
19
src/Infrastructure.EntityFramework/Models/PlayData.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#nullable enable
|
||||||
|
|
||||||
|
using AutoMapper;
|
||||||
|
|
||||||
|
namespace Bit.Infrastructure.EntityFramework.Models;
|
||||||
|
|
||||||
|
public class PlayData : Core.Entities.PlayData
|
||||||
|
{
|
||||||
|
public virtual User? User { get; set; }
|
||||||
|
public virtual AdminConsole.Models.Organization? Organization { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class PlayDataMapperProfile : Profile
|
||||||
|
{
|
||||||
|
public PlayDataMapperProfile()
|
||||||
|
{
|
||||||
|
CreateMap<Core.Entities.PlayData, PlayData>().ReverseMap();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -57,6 +57,7 @@ public class DatabaseContext : DbContext
|
|||||||
public DbSet<OrganizationApiKey> OrganizationApiKeys { get; set; }
|
public DbSet<OrganizationApiKey> OrganizationApiKeys { get; set; }
|
||||||
public DbSet<OrganizationSponsorship> OrganizationSponsorships { get; set; }
|
public DbSet<OrganizationSponsorship> OrganizationSponsorships { get; set; }
|
||||||
public DbSet<OrganizationConnection> OrganizationConnections { get; set; }
|
public DbSet<OrganizationConnection> OrganizationConnections { get; set; }
|
||||||
|
public DbSet<PlayData> PlayData { get; set; }
|
||||||
public DbSet<OrganizationIntegration> OrganizationIntegrations { get; set; }
|
public DbSet<OrganizationIntegration> OrganizationIntegrations { get; set; }
|
||||||
public DbSet<OrganizationIntegrationConfiguration> OrganizationIntegrationConfigurations { get; set; }
|
public DbSet<OrganizationIntegrationConfiguration> OrganizationIntegrationConfigurations { get; set; }
|
||||||
public DbSet<OrganizationUser> OrganizationUsers { get; set; }
|
public DbSet<OrganizationUser> OrganizationUsers { get; set; }
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
using AutoMapper;
|
||||||
|
using Bit.Core.Repositories;
|
||||||
|
using Bit.Infrastructure.EntityFramework.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
|
namespace Bit.Infrastructure.EntityFramework.Repositories;
|
||||||
|
|
||||||
|
public class PlayDataRepository : Repository<Core.Entities.PlayData, PlayData, Guid>, IPlayDataRepository
|
||||||
|
{
|
||||||
|
public PlayDataRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper)
|
||||||
|
: base(serviceScopeFactory, mapper, (DatabaseContext context) => context.PlayData)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
public async Task<ICollection<Core.Entities.PlayData>> GetByPlayIdAsync(string playId)
|
||||||
|
{
|
||||||
|
using (var scope = ServiceScopeFactory.CreateScope())
|
||||||
|
{
|
||||||
|
var dbContext = GetDatabaseContext(scope);
|
||||||
|
var playDataEntities = await GetDbSet(dbContext)
|
||||||
|
.Where(pd => pd.PlayId == playId)
|
||||||
|
.ToListAsync();
|
||||||
|
return Mapper.Map<List<Core.Entities.PlayData>>(playDataEntities);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task DeleteByPlayIdAsync(string playId)
|
||||||
|
{
|
||||||
|
using (var scope = ServiceScopeFactory.CreateScope())
|
||||||
|
{
|
||||||
|
var dbContext = GetDatabaseContext(scope);
|
||||||
|
var entities = await GetDbSet(dbContext)
|
||||||
|
.Where(pd => pd.PlayId == playId)
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
dbContext.PlayData.RemoveRange(entities);
|
||||||
|
await dbContext.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,9 +2,11 @@
|
|||||||
using Bit.Core.KeyManagement.UserKey;
|
using Bit.Core.KeyManagement.UserKey;
|
||||||
using Bit.Core.Models.Data;
|
using Bit.Core.Models.Data;
|
||||||
using Bit.Core.Repositories;
|
using Bit.Core.Repositories;
|
||||||
|
using Bit.Core.Services;
|
||||||
using Bit.Infrastructure.EntityFramework.Models;
|
using Bit.Infrastructure.EntityFramework.Models;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
#nullable enable
|
#nullable enable
|
||||||
|
|
||||||
@@ -12,9 +14,37 @@ namespace Bit.Infrastructure.EntityFramework.Repositories;
|
|||||||
|
|
||||||
public class UserRepository : Repository<Core.Entities.User, User, Guid>, IUserRepository
|
public class UserRepository : Repository<Core.Entities.User, User, Guid>, IUserRepository
|
||||||
{
|
{
|
||||||
public UserRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper)
|
private readonly IPlayIdService _playIdService;
|
||||||
|
private readonly IPlayDataRepository _playDataRepository;
|
||||||
|
private readonly ILogger<UserRepository> _logger;
|
||||||
|
|
||||||
|
public UserRepository(
|
||||||
|
IServiceScopeFactory serviceScopeFactory,
|
||||||
|
IMapper mapper,
|
||||||
|
IPlayIdService playIdService,
|
||||||
|
IPlayDataRepository playDataRepository,
|
||||||
|
ILogger<UserRepository> logger)
|
||||||
: base(serviceScopeFactory, mapper, (DatabaseContext context) => context.Users)
|
: base(serviceScopeFactory, mapper, (DatabaseContext context) => context.Users)
|
||||||
{ }
|
{
|
||||||
|
_playIdService = playIdService;
|
||||||
|
_playDataRepository = playDataRepository;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override async Task<Core.Entities.User> CreateAsync(Core.Entities.User user)
|
||||||
|
{
|
||||||
|
var createdUser = await base.CreateAsync(user);
|
||||||
|
|
||||||
|
if (_playIdService.InPlay(out var playId))
|
||||||
|
{
|
||||||
|
_logger.LogInformation("Associating user {UserId} with Play ID {PlayId}",
|
||||||
|
user.Id, playId);
|
||||||
|
|
||||||
|
await _playDataRepository.CreateAsync(Core.Entities.PlayData.Create(user, playId));
|
||||||
|
}
|
||||||
|
|
||||||
|
return createdUser;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<Core.Entities.User?> GetByEmailAsync(string email)
|
public async Task<Core.Entities.User?> GetByEmailAsync(string email)
|
||||||
{
|
{
|
||||||
|
|||||||
17
src/SharedWeb/Utilities/PlayIdMiddleware.cs
Normal file
17
src/SharedWeb/Utilities/PlayIdMiddleware.cs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
using Bit.Core.Services;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
|
||||||
|
namespace Bit.SharedWeb.Utilities;
|
||||||
|
|
||||||
|
public sealed class PlayIdMiddleware(RequestDelegate next)
|
||||||
|
{
|
||||||
|
public Task Invoke(HttpContext context, IPlayIdService playIdService)
|
||||||
|
{
|
||||||
|
if (context.Request.Headers.TryGetValue("x-play-id", out var playId))
|
||||||
|
{
|
||||||
|
playIdService.PlayId = playId;
|
||||||
|
}
|
||||||
|
|
||||||
|
return next(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -114,6 +114,10 @@ public static class ServiceCollectionExtensions
|
|||||||
services.AddKeyedSingleton<IGrantRepository, Core.Auth.Repositories.Cosmos.GrantRepository>("cosmos");
|
services.AddKeyedSingleton<IGrantRepository, Core.Auth.Repositories.Cosmos.GrantRepository>("cosmos");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Include PlayIdService for tracking Play Ids in repositories
|
||||||
|
services.AddScoped<IPlayIdService, PlayIdService>();
|
||||||
|
|
||||||
|
|
||||||
return provider;
|
return provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -638,6 +642,7 @@ public static class ServiceCollectionExtensions
|
|||||||
IWebHostEnvironment env, GlobalSettings globalSettings)
|
IWebHostEnvironment env, GlobalSettings globalSettings)
|
||||||
{
|
{
|
||||||
app.UseMiddleware<RequestLoggingMiddleware>();
|
app.UseMiddleware<RequestLoggingMiddleware>();
|
||||||
|
app.UseMiddleware<PlayIdMiddleware>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void UseForwardedHeaders(this IApplicationBuilder app, IGlobalSettings globalSettings)
|
public static void UseForwardedHeaders(this IApplicationBuilder app, IGlobalSettings globalSettings)
|
||||||
|
|||||||
27
src/Sql/dbo/Stored Procedures/PlayData_Create.sql
Normal file
27
src/Sql/dbo/Stored Procedures/PlayData_Create.sql
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
CREATE PROCEDURE [dbo].[PlayData_Create]
|
||||||
|
@Id UNIQUEIDENTIFIER OUTPUT,
|
||||||
|
@PlayId NVARCHAR(256),
|
||||||
|
@UserId UNIQUEIDENTIFIER,
|
||||||
|
@OrganizationId UNIQUEIDENTIFIER,
|
||||||
|
@CreationDate DATETIME2(7)
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
INSERT INTO [dbo].[PlayData]
|
||||||
|
(
|
||||||
|
[Id],
|
||||||
|
[PlayId],
|
||||||
|
[UserId],
|
||||||
|
[OrganizationId],
|
||||||
|
[CreationDate]
|
||||||
|
)
|
||||||
|
VALUES
|
||||||
|
(
|
||||||
|
@Id,
|
||||||
|
@PlayId,
|
||||||
|
@UserId,
|
||||||
|
@OrganizationId,
|
||||||
|
@CreationDate
|
||||||
|
)
|
||||||
|
END
|
||||||
12
src/Sql/dbo/Stored Procedures/PlayData_DeleteByPlayId.sql
Normal file
12
src/Sql/dbo/Stored Procedures/PlayData_DeleteByPlayId.sql
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
CREATE PROCEDURE [dbo].[PlayData_DeleteByPlayId]
|
||||||
|
@PlayId NVARCHAR(256)
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
DELETE
|
||||||
|
FROM
|
||||||
|
[dbo].[PlayData]
|
||||||
|
WHERE
|
||||||
|
[PlayId] = @PlayId
|
||||||
|
END
|
||||||
13
src/Sql/dbo/Stored Procedures/PlayData_ReadByPlayId.sql
Normal file
13
src/Sql/dbo/Stored Procedures/PlayData_ReadByPlayId.sql
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
CREATE PROCEDURE [dbo].[PlayData_ReadByPlayId]
|
||||||
|
@PlayId NVARCHAR(256)
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
[dbo].[PlayData]
|
||||||
|
WHERE
|
||||||
|
[PlayId] = @PlayId
|
||||||
|
END
|
||||||
23
src/Sql/dbo/Tables/PlayData.sql
Normal file
23
src/Sql/dbo/Tables/PlayData.sql
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
CREATE TABLE [dbo].[PlayData] (
|
||||||
|
[Id] UNIQUEIDENTIFIER NOT NULL,
|
||||||
|
[PlayId] NVARCHAR (256) NOT NULL,
|
||||||
|
[UserId] UNIQUEIDENTIFIER NULL,
|
||||||
|
[OrganizationId] UNIQUEIDENTIFIER NULL,
|
||||||
|
[CreationDate] DATETIME2 (7) NOT NULL,
|
||||||
|
CONSTRAINT [PK_PlayData] PRIMARY KEY CLUSTERED ([Id] ASC),
|
||||||
|
CONSTRAINT [FK_PlayData_User] FOREIGN KEY ([UserId]) REFERENCES [dbo].[User] ([Id]),
|
||||||
|
CONSTRAINT [FK_PlayData_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id]),
|
||||||
|
CONSTRAINT [CK_PlayData_UserOrOrganization] CHECK (([UserId] IS NOT NULL AND [OrganizationId] IS NULL) OR ([UserId] IS NULL AND [OrganizationId] IS NOT NULL))
|
||||||
|
);
|
||||||
|
|
||||||
|
GO
|
||||||
|
CREATE NONCLUSTERED INDEX [IX_PlayData_PlayId]
|
||||||
|
ON [dbo].[PlayData]([PlayId] ASC);
|
||||||
|
|
||||||
|
GO
|
||||||
|
CREATE NONCLUSTERED INDEX [IX_PlayData_UserId]
|
||||||
|
ON [dbo].[PlayData]([UserId] ASC);
|
||||||
|
|
||||||
|
GO
|
||||||
|
CREATE NONCLUSTERED INDEX [IX_PlayData_OrganizationId]
|
||||||
|
ON [dbo].[PlayData]([OrganizationId] ASC);
|
||||||
86
util/Migrator/DbScripts/2025-11-04_00_PlayData.sql
Normal file
86
util/Migrator/DbScripts/2025-11-04_00_PlayData.sql
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
-- Create PlayData table
|
||||||
|
IF OBJECT_ID('dbo.PlayData') IS NULL
|
||||||
|
BEGIN
|
||||||
|
CREATE TABLE [dbo].[PlayData] (
|
||||||
|
[Id] UNIQUEIDENTIFIER NOT NULL,
|
||||||
|
[PlayId] NVARCHAR (256) NOT NULL,
|
||||||
|
[UserId] UNIQUEIDENTIFIER NULL,
|
||||||
|
[OrganizationId] UNIQUEIDENTIFIER NULL,
|
||||||
|
[CreationDate] DATETIME2 (7) NOT NULL,
|
||||||
|
CONSTRAINT [PK_PlayData] PRIMARY KEY CLUSTERED ([Id] ASC),
|
||||||
|
CONSTRAINT [FK_PlayData_User] FOREIGN KEY ([UserId]) REFERENCES [dbo].[User] ([Id]),
|
||||||
|
CONSTRAINT [FK_PlayData_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id]),
|
||||||
|
CONSTRAINT [CK_PlayData_UserOrOrganization] CHECK (([UserId] IS NOT NULL AND [OrganizationId] IS NULL) OR ([UserId] IS NULL AND [OrganizationId] IS NOT NULL))
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE NONCLUSTERED INDEX [IX_PlayData_PlayId]
|
||||||
|
ON [dbo].[PlayData]([PlayId] ASC);
|
||||||
|
|
||||||
|
CREATE NONCLUSTERED INDEX [IX_PlayData_UserId]
|
||||||
|
ON [dbo].[PlayData]([UserId] ASC);
|
||||||
|
|
||||||
|
CREATE NONCLUSTERED INDEX [IX_PlayData_OrganizationId]
|
||||||
|
ON [dbo].[PlayData]([OrganizationId] ASC);
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
-- Create PlayData_Create stored procedure
|
||||||
|
CREATE OR ALTER PROCEDURE [dbo].[PlayData_Create]
|
||||||
|
@Id UNIQUEIDENTIFIER OUTPUT,
|
||||||
|
@PlayId NVARCHAR(256),
|
||||||
|
@UserId UNIQUEIDENTIFIER,
|
||||||
|
@OrganizationId UNIQUEIDENTIFIER,
|
||||||
|
@CreationDate DATETIME2(7)
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
INSERT INTO [dbo].[PlayData]
|
||||||
|
(
|
||||||
|
[Id],
|
||||||
|
[PlayId],
|
||||||
|
[UserId],
|
||||||
|
[OrganizationId],
|
||||||
|
[CreationDate]
|
||||||
|
)
|
||||||
|
VALUES
|
||||||
|
(
|
||||||
|
@Id,
|
||||||
|
@PlayId,
|
||||||
|
@UserId,
|
||||||
|
@OrganizationId,
|
||||||
|
@CreationDate
|
||||||
|
)
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
-- Create PlayData_ReadByPlayId stored procedure
|
||||||
|
CREATE OR ALTER PROCEDURE [dbo].[PlayData_ReadByPlayId]
|
||||||
|
@PlayId NVARCHAR(256)
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
*
|
||||||
|
FROM
|
||||||
|
[dbo].[PlayData]
|
||||||
|
WHERE
|
||||||
|
[PlayId] = @PlayId
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
-- Create PlayData_DeleteByPlayId stored procedure
|
||||||
|
CREATE OR ALTER PROCEDURE [dbo].[PlayData_DeleteByPlayId]
|
||||||
|
@PlayId NVARCHAR(256)
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
DELETE
|
||||||
|
FROM
|
||||||
|
[dbo].[PlayData]
|
||||||
|
WHERE
|
||||||
|
[PlayId] = @PlayId
|
||||||
|
END
|
||||||
|
GO
|
||||||
3479
util/MySqlMigrations/Migrations/20251105002110_2025-11-04_00_PlayData.Designer.cs
generated
Normal file
3479
util/MySqlMigrations/Migrations/20251105002110_2025-11-04_00_PlayData.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,101 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Bit.MySqlMigrations.Migrations;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class _20251104_00_PlayData : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AlterColumn<short>(
|
||||||
|
name: "WaitTimeDays",
|
||||||
|
table: "EmergencyAccess",
|
||||||
|
type: "smallint",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(int),
|
||||||
|
oldType: "int");
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "PlayData",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
||||||
|
PlayId = table.Column<string>(type: "varchar(256)", maxLength: 256, nullable: false)
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||||
|
UserId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
|
||||||
|
OrganizationId = table.Column<Guid>(type: "char(36)", nullable: true, collation: "ascii_general_ci"),
|
||||||
|
CreationDate = table.Column<DateTime>(type: "datetime(6)", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_PlayData", x => x.Id);
|
||||||
|
table.CheckConstraint("CK_PlayData_UserOrOrganization", "([UserId] IS NOT NULL AND [OrganizationId] IS NULL) OR ([UserId] IS NULL AND [OrganizationId] IS NOT NULL)");
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_PlayData_Organization_OrganizationId",
|
||||||
|
column: x => x.OrganizationId,
|
||||||
|
principalTable: "Organization",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_PlayData_User_UserId",
|
||||||
|
column: x => x.UserId,
|
||||||
|
principalTable: "User",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
})
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4");
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "SeededData",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<Guid>(type: "char(36)", nullable: false, collation: "ascii_general_ci"),
|
||||||
|
RecipeName = table.Column<string>(type: "longtext", nullable: false)
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||||
|
Data = table.Column<string>(type: "longtext", nullable: false)
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4"),
|
||||||
|
CreationDate = table.Column<DateTime>(type: "datetime(6)", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_SeededData", x => x.Id);
|
||||||
|
})
|
||||||
|
.Annotation("MySql:CharSet", "utf8mb4");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_PlayData_OrganizationId",
|
||||||
|
table: "PlayData",
|
||||||
|
column: "OrganizationId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_PlayData_PlayId",
|
||||||
|
table: "PlayData",
|
||||||
|
column: "PlayId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_PlayData_UserId",
|
||||||
|
table: "PlayData",
|
||||||
|
column: "UserId");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "PlayData");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "SeededData");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<int>(
|
||||||
|
name: "WaitTimeDays",
|
||||||
|
table: "EmergencyAccess",
|
||||||
|
type: "int",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(short),
|
||||||
|
oldType: "smallint");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -620,8 +620,8 @@ namespace Bit.MySqlMigrations.Migrations
|
|||||||
b.Property<byte>("Type")
|
b.Property<byte>("Type")
|
||||||
.HasColumnType("tinyint unsigned");
|
.HasColumnType("tinyint unsigned");
|
||||||
|
|
||||||
b.Property<int>("WaitTimeDays")
|
b.Property<short>("WaitTimeDays")
|
||||||
.HasColumnType("int");
|
.HasColumnType("smallint");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
@@ -1585,6 +1585,64 @@ namespace Bit.MySqlMigrations.Migrations
|
|||||||
b.ToTable("OrganizationUser", (string)null);
|
b.ToTable("OrganizationUser", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayData", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.HasColumnType("char(36)");
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreationDate")
|
||||||
|
.HasColumnType("datetime(6)");
|
||||||
|
|
||||||
|
b.Property<Guid?>("OrganizationId")
|
||||||
|
.HasColumnType("char(36)");
|
||||||
|
|
||||||
|
b.Property<string>("PlayId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("varchar(256)");
|
||||||
|
|
||||||
|
b.Property<Guid?>("UserId")
|
||||||
|
.HasColumnType("char(36)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("OrganizationId")
|
||||||
|
.HasAnnotation("SqlServer:Clustered", false);
|
||||||
|
|
||||||
|
b.HasIndex("PlayId")
|
||||||
|
.HasAnnotation("SqlServer:Clustered", false);
|
||||||
|
|
||||||
|
b.HasIndex("UserId")
|
||||||
|
.HasAnnotation("SqlServer:Clustered", false);
|
||||||
|
|
||||||
|
b.ToTable("PlayData", null, t =>
|
||||||
|
{
|
||||||
|
t.HasCheckConstraint("CK_PlayData_UserOrOrganization", "([UserId] IS NOT NULL AND [OrganizationId] IS NULL) OR ([UserId] IS NULL AND [OrganizationId] IS NOT NULL)");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.SeededData", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("char(36)");
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreationDate")
|
||||||
|
.HasColumnType("datetime(6)");
|
||||||
|
|
||||||
|
b.Property<string>("Data")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.Property<string>("RecipeName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("longtext");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("SeededData");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Send", b =>
|
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Send", b =>
|
||||||
{
|
{
|
||||||
b.Property<Guid>("Id")
|
b.Property<Guid>("Id")
|
||||||
@@ -2958,6 +3016,23 @@ namespace Bit.MySqlMigrations.Migrations
|
|||||||
b.Navigation("User");
|
b.Navigation("User");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayData", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", "Organization")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("OrganizationId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
|
||||||
|
b.HasOne("Bit.Infrastructure.EntityFramework.Models.User", "User")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
|
||||||
|
b.Navigation("Organization");
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Send", b =>
|
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Send", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", "Organization")
|
b.HasOne("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", "Organization")
|
||||||
|
|||||||
3485
util/PostgresMigrations/Migrations/20251105002123_2025-11-04_00_PlayData.Designer.cs
generated
Normal file
3485
util/PostgresMigrations/Migrations/20251105002123_2025-11-04_00_PlayData.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,96 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Bit.PostgresMigrations.Migrations;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class _20251104_00_PlayData : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AlterColumn<short>(
|
||||||
|
name: "WaitTimeDays",
|
||||||
|
table: "EmergencyAccess",
|
||||||
|
type: "smallint",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(int),
|
||||||
|
oldType: "integer");
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "PlayData",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
PlayId = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: false),
|
||||||
|
UserId = table.Column<Guid>(type: "uuid", nullable: true),
|
||||||
|
OrganizationId = table.Column<Guid>(type: "uuid", nullable: true),
|
||||||
|
CreationDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_PlayData", x => x.Id);
|
||||||
|
table.CheckConstraint("CK_PlayData_UserOrOrganization", "([UserId] IS NOT NULL AND [OrganizationId] IS NULL) OR ([UserId] IS NULL AND [OrganizationId] IS NOT NULL)");
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_PlayData_Organization_OrganizationId",
|
||||||
|
column: x => x.OrganizationId,
|
||||||
|
principalTable: "Organization",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_PlayData_User_UserId",
|
||||||
|
column: x => x.UserId,
|
||||||
|
principalTable: "User",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "SeededData",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
RecipeName = table.Column<string>(type: "text", nullable: false),
|
||||||
|
Data = table.Column<string>(type: "text", nullable: false),
|
||||||
|
CreationDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_SeededData", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_PlayData_OrganizationId",
|
||||||
|
table: "PlayData",
|
||||||
|
column: "OrganizationId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_PlayData_PlayId",
|
||||||
|
table: "PlayData",
|
||||||
|
column: "PlayId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_PlayData_UserId",
|
||||||
|
table: "PlayData",
|
||||||
|
column: "UserId");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "PlayData");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "SeededData");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<int>(
|
||||||
|
name: "WaitTimeDays",
|
||||||
|
table: "EmergencyAccess",
|
||||||
|
type: "integer",
|
||||||
|
nullable: false,
|
||||||
|
oldClrType: typeof(short),
|
||||||
|
oldType: "smallint");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -623,8 +623,8 @@ namespace Bit.PostgresMigrations.Migrations
|
|||||||
b.Property<byte>("Type")
|
b.Property<byte>("Type")
|
||||||
.HasColumnType("smallint");
|
.HasColumnType("smallint");
|
||||||
|
|
||||||
b.Property<int>("WaitTimeDays")
|
b.Property<short>("WaitTimeDays")
|
||||||
.HasColumnType("integer");
|
.HasColumnType("smallint");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
@@ -1590,6 +1590,64 @@ namespace Bit.PostgresMigrations.Migrations
|
|||||||
b.ToTable("OrganizationUser", (string)null);
|
b.ToTable("OrganizationUser", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayData", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreationDate")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<Guid?>("OrganizationId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("PlayId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<Guid?>("UserId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("OrganizationId")
|
||||||
|
.HasAnnotation("SqlServer:Clustered", false);
|
||||||
|
|
||||||
|
b.HasIndex("PlayId")
|
||||||
|
.HasAnnotation("SqlServer:Clustered", false);
|
||||||
|
|
||||||
|
b.HasIndex("UserId")
|
||||||
|
.HasAnnotation("SqlServer:Clustered", false);
|
||||||
|
|
||||||
|
b.ToTable("PlayData", null, t =>
|
||||||
|
{
|
||||||
|
t.HasCheckConstraint("CK_PlayData_UserOrOrganization", "([UserId] IS NOT NULL AND [OrganizationId] IS NULL) OR ([UserId] IS NULL AND [OrganizationId] IS NOT NULL)");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.SeededData", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreationDate")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Data")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("RecipeName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("SeededData");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Send", b =>
|
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Send", b =>
|
||||||
{
|
{
|
||||||
b.Property<Guid>("Id")
|
b.Property<Guid>("Id")
|
||||||
@@ -2964,6 +3022,23 @@ namespace Bit.PostgresMigrations.Migrations
|
|||||||
b.Navigation("User");
|
b.Navigation("User");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayData", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", "Organization")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("OrganizationId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
|
||||||
|
b.HasOne("Bit.Infrastructure.EntityFramework.Models.User", "User")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
|
||||||
|
b.Navigation("Organization");
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Send", b =>
|
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Send", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", "Organization")
|
b.HasOne("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", "Organization")
|
||||||
|
|||||||
3468
util/SqliteMigrations/Migrations/20251105002117_2025-11-04_00_PlayData.Designer.cs
generated
Normal file
3468
util/SqliteMigrations/Migrations/20251105002117_2025-11-04_00_PlayData.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,80 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Bit.SqliteMigrations.Migrations;
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class _20251104_00_PlayData : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "PlayData",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||||
|
PlayId = table.Column<string>(type: "TEXT", maxLength: 256, nullable: false),
|
||||||
|
UserId = table.Column<Guid>(type: "TEXT", nullable: true),
|
||||||
|
OrganizationId = table.Column<Guid>(type: "TEXT", nullable: true),
|
||||||
|
CreationDate = table.Column<DateTime>(type: "TEXT", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_PlayData", x => x.Id);
|
||||||
|
table.CheckConstraint("CK_PlayData_UserOrOrganization", "([UserId] IS NOT NULL AND [OrganizationId] IS NULL) OR ([UserId] IS NULL AND [OrganizationId] IS NOT NULL)");
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_PlayData_Organization_OrganizationId",
|
||||||
|
column: x => x.OrganizationId,
|
||||||
|
principalTable: "Organization",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_PlayData_User_UserId",
|
||||||
|
column: x => x.UserId,
|
||||||
|
principalTable: "User",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "SeededData",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||||
|
RecipeName = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
Data = table.Column<string>(type: "TEXT", nullable: false),
|
||||||
|
CreationDate = table.Column<DateTime>(type: "TEXT", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_SeededData", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_PlayData_OrganizationId",
|
||||||
|
table: "PlayData",
|
||||||
|
column: "OrganizationId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_PlayData_PlayId",
|
||||||
|
table: "PlayData",
|
||||||
|
column: "PlayId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_PlayData_UserId",
|
||||||
|
table: "PlayData",
|
||||||
|
column: "UserId");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "PlayData");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "SeededData");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -615,7 +615,7 @@ namespace Bit.SqliteMigrations.Migrations
|
|||||||
b.Property<byte>("Type")
|
b.Property<byte>("Type")
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.Property<int>("WaitTimeDays")
|
b.Property<short>("WaitTimeDays")
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
@@ -1574,6 +1574,64 @@ namespace Bit.SqliteMigrations.Migrations
|
|||||||
b.ToTable("OrganizationUser", (string)null);
|
b.ToTable("OrganizationUser", (string)null);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayData", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreationDate")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<Guid?>("OrganizationId")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("PlayId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<Guid?>("UserId")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("OrganizationId")
|
||||||
|
.HasAnnotation("SqlServer:Clustered", false);
|
||||||
|
|
||||||
|
b.HasIndex("PlayId")
|
||||||
|
.HasAnnotation("SqlServer:Clustered", false);
|
||||||
|
|
||||||
|
b.HasIndex("UserId")
|
||||||
|
.HasAnnotation("SqlServer:Clustered", false);
|
||||||
|
|
||||||
|
b.ToTable("PlayData", null, t =>
|
||||||
|
{
|
||||||
|
t.HasCheckConstraint("CK_PlayData_UserOrOrganization", "([UserId] IS NOT NULL AND [OrganizationId] IS NULL) OR ([UserId] IS NULL AND [OrganizationId] IS NOT NULL)");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.SeededData", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreationDate")
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("Data")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.Property<string>("RecipeName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("TEXT");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("SeededData");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Send", b =>
|
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Send", b =>
|
||||||
{
|
{
|
||||||
b.Property<Guid>("Id")
|
b.Property<Guid>("Id")
|
||||||
@@ -2947,6 +3005,23 @@ namespace Bit.SqliteMigrations.Migrations
|
|||||||
b.Navigation("User");
|
b.Navigation("User");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.PlayData", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", "Organization")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("OrganizationId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
|
||||||
|
b.HasOne("Bit.Infrastructure.EntityFramework.Models.User", "User")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
|
||||||
|
b.Navigation("Organization");
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Send", b =>
|
modelBuilder.Entity("Bit.Infrastructure.EntityFramework.Models.Send", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", "Organization")
|
b.HasOne("Bit.Infrastructure.EntityFramework.AdminConsole.Models.Organization", "Organization")
|
||||||
|
|||||||
Reference in New Issue
Block a user