mirror of
https://github.com/bitwarden/server
synced 2026-01-05 01:53:17 +00:00
Organization integrations and configuration database schemas (#5553)
* Organization integrations and configuration database schemas * Format EF files
This commit is contained in:
18
src/Core/AdminConsole/Entities/OrganizationIntegration.cs
Normal file
18
src/Core/AdminConsole/Entities/OrganizationIntegration.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Utilities;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Bit.Core.AdminConsole.Entities;
|
||||
|
||||
public class OrganizationIntegration : ITableObject<Guid>
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public Guid OrganizationId { get; set; }
|
||||
public IntegrationType Type { get; set; }
|
||||
public string? Configuration { get; set; }
|
||||
public DateTime CreationDate { get; set; } = DateTime.UtcNow;
|
||||
public DateTime RevisionDate { get; set; } = DateTime.UtcNow;
|
||||
public void SetNewId() => Id = CoreHelpers.GenerateComb();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using Bit.Core.Entities;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Utilities;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Bit.Core.AdminConsole.Entities;
|
||||
|
||||
public class OrganizationIntegrationConfiguration : ITableObject<Guid>
|
||||
{
|
||||
public Guid Id { get; set; }
|
||||
public Guid OrganizationIntegrationId { get; set; }
|
||||
public EventType EventType { get; set; }
|
||||
public string? Configuration { get; set; }
|
||||
public string? Template { get; set; }
|
||||
public DateTime CreationDate { get; set; } = DateTime.UtcNow;
|
||||
public DateTime RevisionDate { get; set; } = DateTime.UtcNow;
|
||||
public void SetNewId() => Id = CoreHelpers.GenerateComb();
|
||||
}
|
||||
7
src/Core/AdminConsole/Enums/IntegrationType.cs
Normal file
7
src/Core/AdminConsole/Enums/IntegrationType.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Bit.Core.Enums;
|
||||
|
||||
public enum IntegrationType : int
|
||||
{
|
||||
Slack = 1,
|
||||
Webhook = 2,
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using Bit.Infrastructure.EntityFramework.AdminConsole.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.AdminConsole.Configurations;
|
||||
|
||||
public class OrganizationIntegrationConfigurationEntityTypeConfiguration : IEntityTypeConfiguration<OrganizationIntegrationConfiguration>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<OrganizationIntegrationConfiguration> builder)
|
||||
{
|
||||
builder
|
||||
.Property(p => p.Id)
|
||||
.ValueGeneratedNever();
|
||||
|
||||
builder.ToTable(nameof(OrganizationIntegrationConfiguration));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using Bit.Infrastructure.EntityFramework.AdminConsole.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.AdminConsole.Configurations;
|
||||
|
||||
public class OrganizationIntegrationEntityTypeConfiguration : IEntityTypeConfiguration<OrganizationIntegration>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<OrganizationIntegration> builder)
|
||||
{
|
||||
builder
|
||||
.Property(p => p.Id)
|
||||
.ValueGeneratedNever();
|
||||
|
||||
builder
|
||||
.HasIndex(p => p.OrganizationId)
|
||||
.IsClustered(false);
|
||||
|
||||
builder
|
||||
.HasIndex(p => new { p.OrganizationId, p.Type })
|
||||
.IsUnique()
|
||||
.IsClustered(false);
|
||||
|
||||
builder.ToTable(nameof(OrganizationIntegration));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using AutoMapper;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.AdminConsole.Models;
|
||||
|
||||
public class OrganizationIntegration : Core.AdminConsole.Entities.OrganizationIntegration
|
||||
{
|
||||
public virtual Organization Organization { get; set; }
|
||||
}
|
||||
|
||||
public class OrganizationIntegrationMapperProfile : Profile
|
||||
{
|
||||
public OrganizationIntegrationMapperProfile()
|
||||
{
|
||||
CreateMap<Core.AdminConsole.Entities.OrganizationIntegration, OrganizationIntegration>().ReverseMap();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using AutoMapper;
|
||||
|
||||
namespace Bit.Infrastructure.EntityFramework.AdminConsole.Models;
|
||||
|
||||
public class OrganizationIntegrationConfiguration : Core.AdminConsole.Entities.OrganizationIntegrationConfiguration
|
||||
{
|
||||
public virtual OrganizationIntegration OrganizationIntegration { get; set; }
|
||||
}
|
||||
|
||||
public class OrganizationIntegrationConfigurationMapperProfile : Profile
|
||||
{
|
||||
public OrganizationIntegrationConfigurationMapperProfile()
|
||||
{
|
||||
CreateMap<Core.AdminConsole.Entities.OrganizationIntegrationConfiguration, OrganizationIntegrationConfiguration>().ReverseMap();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
CREATE PROCEDURE [dbo].[OrganizationIntegrationConfiguration_ReadManyByEventTypeOrganizationIdIntegrationType]
|
||||
@EventType SMALLINT,
|
||||
@OrganizationId UNIQUEIDENTIFIER,
|
||||
@IntegrationType SMALLINT
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT
|
||||
oic.*
|
||||
FROM
|
||||
[dbo].[OrganizationIntegrationConfigurationView] oic
|
||||
INNER JOIN
|
||||
[dbo].[OrganizationIntegration] oi ON oi.[Id] = oic.[OrganizationIntegrationId]
|
||||
WHERE
|
||||
oic.[EventType] = @EventType
|
||||
AND
|
||||
oi.[OrganizationId] = @OrganizationId
|
||||
AND
|
||||
oi.[Type] = @IntegrationType
|
||||
END
|
||||
GO
|
||||
20
src/Sql/dbo/Tables/OrganizationIntegration.sql
Normal file
20
src/Sql/dbo/Tables/OrganizationIntegration.sql
Normal file
@@ -0,0 +1,20 @@
|
||||
CREATE TABLE [dbo].[OrganizationIntegration]
|
||||
(
|
||||
[Id] UNIQUEIDENTIFIER NOT NULL,
|
||||
[OrganizationId] UNIQUEIDENTIFIER NOT NULL,
|
||||
[Type] SMALLINT NOT NULL,
|
||||
[Configuration] VARCHAR (MAX) NULL,
|
||||
[CreationDate] DATETIME2 (7) NOT NULL,
|
||||
[RevisionDate] DATETIME2 (7) NOT NULL,
|
||||
CONSTRAINT [PK_OrganizationIntegration] PRIMARY KEY CLUSTERED ([Id] ASC),
|
||||
CONSTRAINT [FK_OrganizationIntegration_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id])
|
||||
);
|
||||
GO
|
||||
|
||||
CREATE NONCLUSTERED INDEX [IX_OrganizationIntegration_OrganizationId]
|
||||
ON [dbo].[OrganizationIntegration]([OrganizationId] ASC);
|
||||
GO
|
||||
|
||||
CREATE UNIQUE INDEX [IX_OrganizationIntegration_Organization_Type]
|
||||
ON [dbo].[OrganizationIntegration]([OrganizationId], [Type]);
|
||||
GO
|
||||
13
src/Sql/dbo/Tables/OrganizationIntegrationConfiguration.sql
Normal file
13
src/Sql/dbo/Tables/OrganizationIntegrationConfiguration.sql
Normal file
@@ -0,0 +1,13 @@
|
||||
CREATE TABLE [dbo].[OrganizationIntegrationConfiguration]
|
||||
(
|
||||
[Id] UNIQUEIDENTIFIER NOT NULL,
|
||||
[OrganizationIntegrationId] UNIQUEIDENTIFIER NOT NULL,
|
||||
[EventType] SMALLINT NOT NULL,
|
||||
[Configuration] VARCHAR (MAX) NULL,
|
||||
[Template] VARCHAR (MAX) NULL,
|
||||
[CreationDate] DATETIME2 (7) NOT NULL,
|
||||
[RevisionDate] DATETIME2 (7) NOT NULL,
|
||||
CONSTRAINT [PK_OrganizationIntegrationConfiguration] PRIMARY KEY CLUSTERED ([Id] ASC),
|
||||
CONSTRAINT [FK_OrganizationIntegrationConfiguration_OrganizationIntegration] FOREIGN KEY ([OrganizationIntegrationId]) REFERENCES [dbo].[OrganizationIntegration] ([Id])
|
||||
);
|
||||
GO
|
||||
@@ -0,0 +1,6 @@
|
||||
CREATE VIEW [dbo].[OrganizationIntegrationConfigurationView]
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[OrganizationIntegrationConfiguration]
|
||||
6
src/Sql/dbo/Views/OrganizationIntegrationView.sql
Normal file
6
src/Sql/dbo/Views/OrganizationIntegrationView.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
CREATE VIEW [dbo].[OrganizationIntegrationView]
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[OrganizationIntegration]
|
||||
Reference in New Issue
Block a user