diff --git a/src/Core/Dirt/Reports/Entities/RiskInsightCriticalApplication.cs b/src/Core/Dirt/Reports/Entities/OrganizationApplication.cs similarity index 85% rename from src/Core/Dirt/Reports/Entities/RiskInsightCriticalApplication.cs rename to src/Core/Dirt/Reports/Entities/OrganizationApplication.cs index 7185c6c8a2..0c5ded4be8 100644 --- a/src/Core/Dirt/Reports/Entities/RiskInsightCriticalApplication.cs +++ b/src/Core/Dirt/Reports/Entities/OrganizationApplication.cs @@ -5,7 +5,7 @@ using Bit.Core.Utilities; namespace Bit.Core.Dirt.Reports.Entities; -public class RiskInsightCriticalApplication : ITableObject, IRevisable +public class OrganizationApplication : ITableObject, IRevisable { public Guid Id { get; set; } public Guid OrganizationId { get; set; } diff --git a/src/Core/Dirt/Reports/Entities/RiskInsightReport.cs b/src/Core/Dirt/Reports/Entities/OrganizationReport.cs similarity index 88% rename from src/Core/Dirt/Reports/Entities/RiskInsightReport.cs rename to src/Core/Dirt/Reports/Entities/OrganizationReport.cs index 00957e92a2..fad8a5e83c 100644 --- a/src/Core/Dirt/Reports/Entities/RiskInsightReport.cs +++ b/src/Core/Dirt/Reports/Entities/OrganizationReport.cs @@ -5,7 +5,7 @@ using Bit.Core.Utilities; namespace Bit.Core.Dirt.Reports.Entities; -public class RiskInsightReport : ITableObject, IRevisable +public class OrganizationReport : ITableObject, IRevisable { public Guid Id { get; set; } public Guid OrganizationId { get; set; } diff --git a/src/Core/Dirt/Reports/Repositories/IOrganizationApplicationRepository.cs b/src/Core/Dirt/Reports/Repositories/IOrganizationApplicationRepository.cs new file mode 100644 index 0000000000..593c572a95 --- /dev/null +++ b/src/Core/Dirt/Reports/Repositories/IOrganizationApplicationRepository.cs @@ -0,0 +1,9 @@ +using Bit.Core.Dirt.Reports.Entities; +using Bit.Core.Repositories; + +namespace Bit.Core.Dirt.Reports.Repositories; + +public interface IOrganizationApplicationRepository : IRepository +{ + Task> GetByOrganizationIdAsync(Guid organizationId); +} diff --git a/src/Core/Dirt/Reports/Repositories/IOrganizationReportRepository.cs b/src/Core/Dirt/Reports/Repositories/IOrganizationReportRepository.cs new file mode 100644 index 0000000000..67e697f340 --- /dev/null +++ b/src/Core/Dirt/Reports/Repositories/IOrganizationReportRepository.cs @@ -0,0 +1,10 @@ +using Bit.Core.Dirt.Reports.Entities; +using Bit.Core.Repositories; + +namespace Bit.Core.Dirt.Reports.Repositories; + +public interface IOrganizationReportRepository : IRepository +{ + Task> GetByOrganizationIdAsync(Guid organizationId); +} + diff --git a/src/Core/Dirt/Reports/Repositories/IRiskInsightCriticalApplicationRepository.cs b/src/Core/Dirt/Reports/Repositories/IRiskInsightCriticalApplicationRepository.cs deleted file mode 100644 index ff7f395df0..0000000000 --- a/src/Core/Dirt/Reports/Repositories/IRiskInsightCriticalApplicationRepository.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Bit.Core.Dirt.Reports.Entities; -using Bit.Core.Repositories; - -namespace Bit.Core.Dirt.Reports.Repositories; - -public interface IRiskInsightCriticalApplicationRepository : IRepository -{ - Task> GetByOrganizationIdAsync(Guid organizationId); -} diff --git a/src/Core/Dirt/Reports/Repositories/IRiskInsightReportRepository.cs b/src/Core/Dirt/Reports/Repositories/IRiskInsightReportRepository.cs deleted file mode 100644 index 4918a4c8cc..0000000000 --- a/src/Core/Dirt/Reports/Repositories/IRiskInsightReportRepository.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Bit.Core.Dirt.Reports.Entities; -using Bit.Core.Repositories; - -namespace Bit.Core.Dirt.Reports.Repositories; - -public interface IRiskInsightReportRepository : IRepository -{ - Task> GetByOrganizationIdAsync(Guid organizationId); -} - diff --git a/src/Infrastructure.Dapper/DapperServiceCollectionExtensions.cs b/src/Infrastructure.Dapper/DapperServiceCollectionExtensions.cs index 1c1e4c4a4a..3a6dde6767 100644 --- a/src/Infrastructure.Dapper/DapperServiceCollectionExtensions.cs +++ b/src/Infrastructure.Dapper/DapperServiceCollectionExtensions.cs @@ -69,8 +69,8 @@ public static class DapperServiceCollectionExtensions services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); if (selfHosted) { diff --git a/src/Infrastructure.Dapper/Dirt/RiskInsightCriticalApplicationRepository.cs b/src/Infrastructure.Dapper/Dirt/OrganizationApplicationRepository.cs similarity index 59% rename from src/Infrastructure.Dapper/Dirt/RiskInsightCriticalApplicationRepository.cs rename to src/Infrastructure.Dapper/Dirt/OrganizationApplicationRepository.cs index 09b1161072..dc2ccc59e6 100644 --- a/src/Infrastructure.Dapper/Dirt/RiskInsightCriticalApplicationRepository.cs +++ b/src/Infrastructure.Dapper/Dirt/OrganizationApplicationRepository.cs @@ -8,23 +8,23 @@ using Microsoft.Data.SqlClient; namespace Bit.Infrastructure.Dapper.Dirt; -public class RiskInsightCriticalApplicationRepository : Repository, IRiskInsightCriticalApplicationRepository +public class OrganizationApplicationRepository : Repository, IOrganizationApplicationRepository { - public RiskInsightCriticalApplicationRepository(GlobalSettings globalSettings) + public OrganizationApplicationRepository(GlobalSettings globalSettings) : this(globalSettings.SqlServer.ConnectionString, globalSettings.SqlServer.ReadOnlyConnectionString) { } - public RiskInsightCriticalApplicationRepository(string connectionString, string readOnlyConnectionString) + public OrganizationApplicationRepository(string connectionString, string readOnlyConnectionString) : base(connectionString, readOnlyConnectionString) { } - public async Task> GetByOrganizationIdAsync(Guid organizationId) + public async Task> GetByOrganizationIdAsync(Guid organizationId) { using (var connection = new SqlConnection(ReadOnlyConnectionString)) { - var results = await connection.QueryAsync( + var results = await connection.QueryAsync( $"[{Schema}].[RiskInsightCriticalApplication_ReadByOrganizationId]", new { OrganizationId = organizationId }, commandType: CommandType.StoredProcedure); diff --git a/src/Infrastructure.Dapper/Dirt/RiskInsightReportRepository.cs b/src/Infrastructure.Dapper/Dirt/OrganizationReportRepository.cs similarity index 63% rename from src/Infrastructure.Dapper/Dirt/RiskInsightReportRepository.cs rename to src/Infrastructure.Dapper/Dirt/OrganizationReportRepository.cs index 4edd78bd27..b1d2679200 100644 --- a/src/Infrastructure.Dapper/Dirt/RiskInsightReportRepository.cs +++ b/src/Infrastructure.Dapper/Dirt/OrganizationReportRepository.cs @@ -8,23 +8,23 @@ using Microsoft.Data.SqlClient; namespace Bit.Infrastructure.Dapper.Dirt; -public class RiskInsightReportRepository : Repository, IRiskInsightReportRepository +public class OrganizationReportRepository : Repository, IOrganizationReportRepository { - public RiskInsightReportRepository(GlobalSettings globalSettings) + public OrganizationReportRepository(GlobalSettings globalSettings) : this(globalSettings.SqlServer.ConnectionString, globalSettings.SqlServer.ReadOnlyConnectionString) { } - public RiskInsightReportRepository(string connectionString, string readOnlyConnectionString) + public OrganizationReportRepository(string connectionString, string readOnlyConnectionString) : base(connectionString, readOnlyConnectionString) { } - public async Task> GetByOrganizationIdAsync(Guid organizationId) + public async Task> GetByOrganizationIdAsync(Guid organizationId) { using (var connection = new SqlConnection(ReadOnlyConnectionString)) { - var results = await connection.QueryAsync( + var results = await connection.QueryAsync( $"[{Schema}].[RiskInsightReport_ReadByOrganizationId]", new { OrganizationId = organizationId }, commandType: CommandType.StoredProcedure); diff --git a/src/Infrastructure.EntityFramework/Dirt/Configurations/RiskInsightCriticalApplicationEntityTypeConfiguration.cs b/src/Infrastructure.EntityFramework/Dirt/Configurations/RiskInsightCriticalApplicationEntityTypeConfiguration.cs index dcfaf54856..ff509f67ce 100644 --- a/src/Infrastructure.EntityFramework/Dirt/Configurations/RiskInsightCriticalApplicationEntityTypeConfiguration.cs +++ b/src/Infrastructure.EntityFramework/Dirt/Configurations/RiskInsightCriticalApplicationEntityTypeConfiguration.cs @@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace Bit.Infrastructure.EntityFramework.Dirt.Configurations; -public class RiskInsightCriticalApplicationEntityTypeConfiguration : IEntityTypeConfiguration +public class RiskInsightCriticalApplicationEntityTypeConfiguration : IEntityTypeConfiguration { - public void Configure(EntityTypeBuilder builder) + public void Configure(EntityTypeBuilder builder) { builder .Property(s => s.Id) @@ -19,6 +19,6 @@ public class RiskInsightCriticalApplicationEntityTypeConfiguration : IEntityType .HasIndex(s => s.OrganizationId) .IsClustered(false); - builder.ToTable(nameof(RiskInsightCriticalApplication)); + builder.ToTable(nameof(OrganizationApplication)); } } diff --git a/src/Infrastructure.EntityFramework/Dirt/Configurations/RiskInsightReportEntityTypeConfiguration.cs b/src/Infrastructure.EntityFramework/Dirt/Configurations/RiskInsightReportEntityTypeConfiguration.cs index 943c9b49a3..c17024994b 100644 --- a/src/Infrastructure.EntityFramework/Dirt/Configurations/RiskInsightReportEntityTypeConfiguration.cs +++ b/src/Infrastructure.EntityFramework/Dirt/Configurations/RiskInsightReportEntityTypeConfiguration.cs @@ -4,9 +4,9 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace Bit.Infrastructure.EntityFramework.Dirt.Configurations; -public class RiskInsightReportEntityTypeConfiguration : IEntityTypeConfiguration +public class RiskInsightReportEntityTypeConfiguration : IEntityTypeConfiguration { - public void Configure(EntityTypeBuilder builder) + public void Configure(EntityTypeBuilder builder) { builder .Property(s => s.Id) @@ -19,6 +19,6 @@ public class RiskInsightReportEntityTypeConfiguration : IEntityTypeConfiguration .HasIndex(s => s.OrganizationId) .IsClustered(false); - builder.ToTable(nameof(RiskInsightReport)); + builder.ToTable(nameof(OrganizationReport)); } } diff --git a/src/Infrastructure.EntityFramework/Dirt/Models/OrganizationApplication.cs b/src/Infrastructure.EntityFramework/Dirt/Models/OrganizationApplication.cs new file mode 100644 index 0000000000..68ebdbf9ef --- /dev/null +++ b/src/Infrastructure.EntityFramework/Dirt/Models/OrganizationApplication.cs @@ -0,0 +1,17 @@ +using AutoMapper; +using Bit.Infrastructure.EntityFramework.AdminConsole.Models; + +namespace Bit.Infrastructure.EntityFramework.Dirt.Models; +public class OrganizationApplication : Core.Dirt.Reports.Entities.OrganizationApplication +{ + public virtual Organization Organization { get; set; } +} + +public class OrganizationApplicationProfile : Profile +{ + public OrganizationApplicationProfile() + { + CreateMap() + .ReverseMap(); + } +} diff --git a/src/Infrastructure.EntityFramework/Dirt/Models/OrganizationReport.cs b/src/Infrastructure.EntityFramework/Dirt/Models/OrganizationReport.cs new file mode 100644 index 0000000000..55f377c629 --- /dev/null +++ b/src/Infrastructure.EntityFramework/Dirt/Models/OrganizationReport.cs @@ -0,0 +1,17 @@ +using AutoMapper; +using Bit.Infrastructure.EntityFramework.AdminConsole.Models; + +namespace Bit.Infrastructure.EntityFramework.Dirt.Models; +public class OrganizationReport : Core.Dirt.Reports.Entities.OrganizationReport +{ + public virtual Organization Organization { get; set; } +} + +public class OrganizationReportProfile : Profile +{ + public OrganizationReportProfile() + { + CreateMap() + .ReverseMap(); + } +} diff --git a/src/Infrastructure.EntityFramework/Dirt/Models/RiskInsightCriticalApplication.cs b/src/Infrastructure.EntityFramework/Dirt/Models/RiskInsightCriticalApplication.cs deleted file mode 100644 index 14e80190e7..0000000000 --- a/src/Infrastructure.EntityFramework/Dirt/Models/RiskInsightCriticalApplication.cs +++ /dev/null @@ -1,17 +0,0 @@ -using AutoMapper; -using Bit.Infrastructure.EntityFramework.AdminConsole.Models; - -namespace Bit.Infrastructure.EntityFramework.Dirt.Models; -public class RiskInsightCriticalApplication : Core.Dirt.Reports.Entities.RiskInsightCriticalApplication -{ - public virtual Organization Organization { get; set; } -} - -public class RiskInsightCriticalApplicationProfile : Profile -{ - public RiskInsightCriticalApplicationProfile() - { - CreateMap() - .ReverseMap(); - } -} diff --git a/src/Infrastructure.EntityFramework/Dirt/Models/RiskInsightReport.cs b/src/Infrastructure.EntityFramework/Dirt/Models/RiskInsightReport.cs deleted file mode 100644 index 7b7c7b223c..0000000000 --- a/src/Infrastructure.EntityFramework/Dirt/Models/RiskInsightReport.cs +++ /dev/null @@ -1,17 +0,0 @@ -using AutoMapper; -using Bit.Infrastructure.EntityFramework.AdminConsole.Models; - -namespace Bit.Infrastructure.EntityFramework.Dirt.Models; -public class RiskInsightReport : Core.Dirt.Reports.Entities.RiskInsightReport -{ - public virtual Organization Organization { get; set; } -} - -public class RiskInsightReportProfile : Profile -{ - public RiskInsightReportProfile() - { - CreateMap() - .ReverseMap(); - } -} diff --git a/src/Infrastructure.EntityFramework/Dirt/Repositories/RiskInsightReportRepository.cs b/src/Infrastructure.EntityFramework/Dirt/Repositories/OrganizationApplicationRepository.cs similarity index 54% rename from src/Infrastructure.EntityFramework/Dirt/Repositories/RiskInsightReportRepository.cs rename to src/Infrastructure.EntityFramework/Dirt/Repositories/OrganizationApplicationRepository.cs index e030de721d..1b1940aad8 100644 --- a/src/Infrastructure.EntityFramework/Dirt/Repositories/RiskInsightReportRepository.cs +++ b/src/Infrastructure.EntityFramework/Dirt/Repositories/OrganizationApplicationRepository.cs @@ -5,26 +5,25 @@ using Bit.Infrastructure.EntityFramework.Repositories; using LinqToDB; using Microsoft.Extensions.DependencyInjection; - namespace Bit.Infrastructure.EntityFramework.Dirt.Repositories; -public class RiskInsightReportRepository : - Repository, - IRiskInsightReportRepository +public class OrganizationApplicationRepository : + Repository, + IOrganizationApplicationRepository { - public RiskInsightReportRepository(IServiceScopeFactory serviceScopeFactory, - IMapper mapper) : base(serviceScopeFactory, mapper, (DatabaseContext context) => context.RiskInsightReports) + public OrganizationApplicationRepository(IServiceScopeFactory serviceScopeFactory, + IMapper mapper) : base(serviceScopeFactory, mapper, (DatabaseContext context) => context.OrganizationApplications) { } - public async Task> GetByOrganizationIdAsync(Guid organizationId) + public async Task> GetByOrganizationIdAsync(Guid organizationId) { using (var scope = ServiceScopeFactory.CreateScope()) { var dbContext = GetDatabaseContext(scope); - var results = await dbContext.RiskInsightReports + var results = await dbContext.OrganizationApplications .Where(p => p.OrganizationId == organizationId) .ToListAsync(); - return Mapper.Map>(results); + return Mapper.Map>(results); } } } diff --git a/src/Infrastructure.EntityFramework/Dirt/Repositories/OrganizationReportRepository.cs b/src/Infrastructure.EntityFramework/Dirt/Repositories/OrganizationReportRepository.cs new file mode 100644 index 0000000000..8cc4050d74 --- /dev/null +++ b/src/Infrastructure.EntityFramework/Dirt/Repositories/OrganizationReportRepository.cs @@ -0,0 +1,30 @@ +using AutoMapper; +using Bit.Core.Dirt.Reports.Entities; +using Bit.Core.Dirt.Reports.Repositories; +using Bit.Infrastructure.EntityFramework.Repositories; +using LinqToDB; +using Microsoft.Extensions.DependencyInjection; + + +namespace Bit.Infrastructure.EntityFramework.Dirt.Repositories; + +public class OrganizationReportRepository : + Repository, + IOrganizationReportRepository +{ + public OrganizationReportRepository(IServiceScopeFactory serviceScopeFactory, + IMapper mapper) : base(serviceScopeFactory, mapper, (DatabaseContext context) => context.OrganizationReports) + { } + + public async Task> GetByOrganizationIdAsync(Guid organizationId) + { + using (var scope = ServiceScopeFactory.CreateScope()) + { + var dbContext = GetDatabaseContext(scope); + var results = await dbContext.OrganizationReports + .Where(p => p.OrganizationId == organizationId) + .ToListAsync(); + return Mapper.Map>(results); + } + } +} diff --git a/src/Infrastructure.EntityFramework/Dirt/Repositories/RiskInsightCriticalApplicationRepository.cs b/src/Infrastructure.EntityFramework/Dirt/Repositories/RiskInsightCriticalApplicationRepository.cs deleted file mode 100644 index 9c60a408a1..0000000000 --- a/src/Infrastructure.EntityFramework/Dirt/Repositories/RiskInsightCriticalApplicationRepository.cs +++ /dev/null @@ -1,29 +0,0 @@ -using AutoMapper; -using Bit.Core.Dirt.Reports.Repositories; -using Bit.Infrastructure.EntityFramework.Dirt.Models; -using Bit.Infrastructure.EntityFramework.Repositories; -using LinqToDB; -using Microsoft.Extensions.DependencyInjection; - -namespace Bit.Infrastructure.EntityFramework.Dirt.Repositories; - -public class RiskInsightCriticalApplicationRepository : - Repository, - IRiskInsightCriticalApplicationRepository -{ - public RiskInsightCriticalApplicationRepository(IServiceScopeFactory serviceScopeFactory, - IMapper mapper) : base(serviceScopeFactory, mapper, (DatabaseContext context) => context.RiskInsightCriticalApplications) - { } - - public async Task> GetByOrganizationIdAsync(Guid organizationId) - { - using (var scope = ServiceScopeFactory.CreateScope()) - { - var dbContext = GetDatabaseContext(scope); - var results = await dbContext.RiskInsightCriticalApplications - .Where(p => p.OrganizationId == organizationId) - .ToListAsync(); - return Mapper.Map>(results); - } - } -} diff --git a/src/Infrastructure.EntityFramework/EntityFrameworkServiceCollectionExtensions.cs b/src/Infrastructure.EntityFramework/EntityFrameworkServiceCollectionExtensions.cs index 5214aeb703..2dd6a08595 100644 --- a/src/Infrastructure.EntityFramework/EntityFrameworkServiceCollectionExtensions.cs +++ b/src/Infrastructure.EntityFramework/EntityFrameworkServiceCollectionExtensions.cs @@ -106,8 +106,8 @@ public static class EntityFrameworkServiceCollectionExtensions services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); - services.AddSingleton(); - services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); if (selfHosted) { diff --git a/src/Infrastructure.EntityFramework/Repositories/DatabaseContext.cs b/src/Infrastructure.EntityFramework/Repositories/DatabaseContext.cs index 2616ae68ea..3526c75c8d 100644 --- a/src/Infrastructure.EntityFramework/Repositories/DatabaseContext.cs +++ b/src/Infrastructure.EntityFramework/Repositories/DatabaseContext.cs @@ -15,6 +15,7 @@ using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; using DP = Microsoft.AspNetCore.DataProtection; + #nullable enable namespace Bit.Infrastructure.EntityFramework.Repositories; @@ -82,8 +83,8 @@ public class DatabaseContext : DbContext public DbSet PasswordHealthReportApplications { get; set; } public DbSet SecurityTasks { get; set; } public DbSet OrganizationInstallations { get; set; } - public DbSet RiskInsightReports { get; set; } - public DbSet RiskInsightCriticalApplications { get; set; } + public DbSet OrganizationReports { get; set; } + public DbSet OrganizationApplications { get; set; } protected override void OnModelCreating(ModelBuilder builder) {