diff --git a/src/Core/AdminConsole/Models/Data/Organizations/OrganizationIntegrationConfigurationDetails.cs b/src/Core/AdminConsole/Models/Data/Organizations/OrganizationIntegrationConfigurationDetails.cs new file mode 100644 index 0000000000..e00387fcf7 --- /dev/null +++ b/src/Core/AdminConsole/Models/Data/Organizations/OrganizationIntegrationConfigurationDetails.cs @@ -0,0 +1,33 @@ +using System.Text.Json.Nodes; +using Bit.Core.Enums; + +#nullable enable + +namespace Bit.Core.Models.Data.Organizations; + +public class OrganizationIntegrationConfigurationDetails +{ + public Guid Id { get; set; } + public Guid OrganizationIntegrationId { get; set; } + public IntegrationType IntegrationType { get; set; } + public EventType EventType { get; set; } + public string? Configuration { get; set; } + public string? IntegrationConfiguration { get; set; } + public string? Template { get; set; } + + public JsonObject MergedConfiguration + { + get + { + var configJson = JsonNode.Parse(Configuration ?? string.Empty) as JsonObject ?? new JsonObject(); + var integrationJson = JsonNode.Parse(IntegrationConfiguration ?? string.Empty) as JsonObject ?? new JsonObject(); + + foreach (var kvp in configJson) + { + integrationJson[kvp.Key] = kvp.Value; + } + + return integrationJson; + } + } +} diff --git a/src/Core/AdminConsole/Repositories/IOrganizationIntegrationConfigurationRepository.cs b/src/Core/AdminConsole/Repositories/IOrganizationIntegrationConfigurationRepository.cs new file mode 100644 index 0000000000..3d1cb7b952 --- /dev/null +++ b/src/Core/AdminConsole/Repositories/IOrganizationIntegrationConfigurationRepository.cs @@ -0,0 +1,13 @@ +using Bit.Core.AdminConsole.Entities; +using Bit.Core.Enums; +using Bit.Core.Models.Data.Organizations; + +namespace Bit.Core.Repositories; + +public interface IOrganizationIntegrationConfigurationRepository : IRepository +{ + Task> GetConfigurationsAsync( + Guid organizationId, + IntegrationType integrationType, + EventType eventType); +} diff --git a/src/Core/AdminConsole/Repositories/IOrganizationIntegrationRepository.cs b/src/Core/AdminConsole/Repositories/IOrganizationIntegrationRepository.cs new file mode 100644 index 0000000000..cd7700c310 --- /dev/null +++ b/src/Core/AdminConsole/Repositories/IOrganizationIntegrationRepository.cs @@ -0,0 +1,7 @@ +using Bit.Core.AdminConsole.Entities; + +namespace Bit.Core.Repositories; + +public interface IOrganizationIntegrationRepository : IRepository +{ +} diff --git a/src/Infrastructure.Dapper/AdminConsole/Repositories/OrganizationIntegrationConfigurationRepository.cs b/src/Infrastructure.Dapper/AdminConsole/Repositories/OrganizationIntegrationConfigurationRepository.cs new file mode 100644 index 0000000000..1896b8ea3f --- /dev/null +++ b/src/Infrastructure.Dapper/AdminConsole/Repositories/OrganizationIntegrationConfigurationRepository.cs @@ -0,0 +1,43 @@ +using System.Data; +using Bit.Core.AdminConsole.Entities; +using Bit.Core.Enums; +using Bit.Core.Models.Data.Organizations; +using Bit.Core.Repositories; +using Bit.Core.Settings; +using Bit.Infrastructure.Dapper.Repositories; +using Dapper; +using Microsoft.Data.SqlClient; + +namespace Bit.Infrastructure.Dapper.AdminConsole.Repositories; + +public class OrganizationIntegrationConfigurationRepository : Repository, IOrganizationIntegrationConfigurationRepository +{ + public OrganizationIntegrationConfigurationRepository(GlobalSettings globalSettings) + : this(globalSettings.SqlServer.ConnectionString, globalSettings.SqlServer.ReadOnlyConnectionString) + { } + + public OrganizationIntegrationConfigurationRepository(string connectionString, string readOnlyConnectionString) + : base(connectionString, readOnlyConnectionString) + { } + + public async Task> GetConfigurationsAsync( + Guid organizationId, + IntegrationType integrationType, + EventType eventType) + { + using (var connection = new SqlConnection(ConnectionString)) + { + var results = await connection.QueryAsync( + "[dbo].[OrganizationIntegrationConfigurationDetails_ReadManyByEventTypeOrganizationIdIntegrationType]", + new + { + EventType = eventType, + OrganizationId = organizationId, + IntegrationType = integrationType + }, + commandType: CommandType.StoredProcedure); + + return results.ToList(); + } + } +} diff --git a/src/Infrastructure.Dapper/AdminConsole/Repositories/OrganizationIntegrationRepository.cs b/src/Infrastructure.Dapper/AdminConsole/Repositories/OrganizationIntegrationRepository.cs new file mode 100644 index 0000000000..99f0e35378 --- /dev/null +++ b/src/Infrastructure.Dapper/AdminConsole/Repositories/OrganizationIntegrationRepository.cs @@ -0,0 +1,16 @@ +using Bit.Core.AdminConsole.Entities; +using Bit.Core.Repositories; +using Bit.Core.Settings; + +namespace Bit.Infrastructure.Dapper.Repositories; + +public class OrganizationIntegrationRepository : Repository, IOrganizationIntegrationRepository +{ + public OrganizationIntegrationRepository(GlobalSettings globalSettings) + : this(globalSettings.SqlServer.ConnectionString, globalSettings.SqlServer.ReadOnlyConnectionString) + { } + + public OrganizationIntegrationRepository(string connectionString, string readOnlyConnectionString) + : base(connectionString, readOnlyConnectionString) + { } +}