1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-04 12:40:22 -05:00

Organization integration creation, update, and deletion database logic

This commit is contained in:
Matt Bishop 2025-04-03 15:56:41 -04:00
parent 0f0c3a4e5a
commit 63181da4d7
No known key found for this signature in database
10 changed files with 308 additions and 8 deletions

View File

@ -0,0 +1,33 @@
CREATE PROCEDURE [dbo].[OrganizationIntegrationConfiguration_Create]
@Id UNIQUEIDENTIFIER OUTPUT,
@OrganizationIntegrationId UNIQUEIDENTIFIER,
@EventType SMALLINT,
@Configuration VARCHAR(MAX),
@Template VARCHAR(MAX),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7)
AS
BEGIN
SET NOCOUNT ON
INSERT INTO [dbo].[OrganizationIntegrationConfiguration]
(
[Id],
[OrganizationIntegrationId],
[EventType],
[Configuration],
[Template],
[CreationDate],
[RevisionDate]
)
VALUES
(
@Id,
@OrganizationIntegrationId,
@EventType,
@Configuration,
@Template,
@CreationDate,
@RevisionDate
)
END

View File

@ -0,0 +1,12 @@
CREATE PROCEDURE [dbo].[OrganizationIntegrationConfiguration_DeleteById]
@Id UNIQUEIDENTIFIER
AS
BEGIN
SET NOCOUNT ON
DELETE
FROM
[dbo].[OrganizationIntegrationConfiguration]
WHERE
[Id] = @Id
END

View File

@ -0,0 +1,24 @@
CREATE PROCEDURE [dbo].[OrganizationIntegrationConfiguration_Update]
@Id UNIQUEIDENTIFIER OUTPUT,
@OrganizationIntegrationId UNIQUEIDENTIFIER,
@EventType SMALLINT,
@Configuration VARCHAR(MAX),
@Template VARCHAR(MAX),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7)
AS
BEGIN
SET NOCOUNT ON
UPDATE
[dbo].[OrganizationIntegrationConfiguration]
SET
[OrganizationIntegrationId] = @OrganizationIntegrationId,
[EventType] = @EventType,
[Configuration] = @Configuration,
[Template] = @Template,
[CreationDate] = @CreationDate,
[RevisionDate] = @RevisionDate
WHERE
[Id] = @Id
END

View File

@ -0,0 +1,30 @@
CREATE PROCEDURE [dbo].[OrganizationIntegration_Create]
@Id UNIQUEIDENTIFIER OUTPUT,
@OrganizationId UNIQUEIDENTIFIER,
@Type SMALLINT,
@Configuration VARCHAR(MAX),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7)
AS
BEGIN
SET NOCOUNT ON
INSERT INTO [dbo].[OrganizationIntegration]
(
[Id],
[OrganizationId],
[Type],
[Configuration],
[CreationDate],
[RevisionDate]
)
VALUES
(
@Id,
@OrganizationId,
@Type,
@Configuration,
@CreationDate,
@RevisionDate
)
END

View File

@ -0,0 +1,12 @@
CREATE PROCEDURE [dbo].[OrganizationIntegration_DeleteById]
@Id UNIQUEIDENTIFIER
AS
BEGIN
SET NOCOUNT ON
DELETE
FROM
[dbo].[OrganizationIntegration]
WHERE
[Id] = @Id
END

View File

@ -0,0 +1,12 @@
CREATE PROCEDURE [dbo].[OrganizationIntegration_OrganizationDeleted]
@OrganizationId UNIQUEIDENTIFIER
AS
BEGIN
SET NOCOUNT ON
DELETE
FROM
[dbo].[OrganizationIntegration]
WHERE
[OrganizationId] = @OrganizationId
END

View File

@ -0,0 +1,22 @@
CREATE PROCEDURE [dbo].[OrganizationIntegration_Update]
@Id UNIQUEIDENTIFIER OUTPUT,
@OrganizationId UNIQUEIDENTIFIER,
@Type SMALLINT,
@Configuration VARCHAR(MAX),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7)
AS
BEGIN
SET NOCOUNT ON
UPDATE
[dbo].[OrganizationIntegration]
SET
[OrganizationId] = @OrganizationId,
[Type] = @Type,
[Configuration] = @Configuration,
[CreationDate] = @CreationDate,
[RevisionDate] = @RevisionDate
WHERE
[Id] = @Id
END

View File

@ -45,11 +45,11 @@ BEGIN
[OrganizationId] = @Id
DELETE CU
FROM
FROM
[dbo].[CollectionUser] CU
INNER JOIN
INNER JOIN
[dbo].[OrganizationUser] OU ON [CU].[OrganizationUserId] = [OU].[Id]
WHERE
WHERE
[OU].[OrganizationId] = @Id
DELETE AP
@ -69,9 +69,9 @@ BEGIN
[OU].[OrganizationId] = @Id
DELETE
FROM
FROM
[dbo].[OrganizationUser]
WHERE
WHERE
[OrganizationId] = @Id
DELETE
@ -84,6 +84,7 @@ BEGIN
EXEC [dbo].[OrganizationConnection_OrganizationDeleted] @Id
EXEC [dbo].[OrganizationSponsorship_OrganizationDeleted] @Id
EXEC [dbo].[OrganizationDomain_OrganizationDeleted] @Id
EXEC [dbo].[OrganizationIntegration_OrganizationDeleted] @Id
DELETE
FROM
@ -128,14 +129,14 @@ BEGIN
[dbo].[Notification] N ON N.[Id] = NS.[NotificationId]
WHERE
N.[OrganizationId] = @Id
-- Delete Notification
DELETE
FROM
[dbo].[Notification]
WHERE
[OrganizationId] = @Id
DELETE
FROM
[dbo].[Organization]

View File

@ -8,6 +8,6 @@ CREATE TABLE [dbo].[OrganizationIntegrationConfiguration]
[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])
CONSTRAINT [FK_OrganizationIntegrationConfiguration_OrganizationIntegration] FOREIGN KEY ([OrganizationIntegrationId]) REFERENCES [dbo].[OrganizationIntegration] ([Id]) ON DELETE CASCADE
);
GO

View File

@ -0,0 +1,154 @@
-- Configure FK to cascade on delete
IF EXISTS(SELECT *
FROM information_schema.table_constraints
WHERE table_name='OrganizationIntegrationConfiguration'
AND constraint_name='FK_OrganizationIntegrationConfiguration_OrganizationIntegration')
BEGIN
ALTER TABLE [dbo].[OrganizationIntegrationConfiguration] DROP FK_OrganizationIntegrationConfiguration_OrganizationIntegration;
ALTER TABLE [dbo].[OrganizationIntegrationConfiguration] ADD CONSTRAINT [FK_OrganizationIntegrationConfiguration_OrganizationIntegration] FOREIGN KEY ([OrganizationIntegrationId]) REFERENCES [dbo].[OrganizationIntegration] ([Id]) ON DELETE CASCADE;
END
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationIntegration_Create]
@Id UNIQUEIDENTIFIER OUTPUT,
@OrganizationId UNIQUEIDENTIFIER,
@Type SMALLINT,
@Configuration VARCHAR(MAX),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7)
AS
BEGIN
SET NOCOUNT ON
INSERT INTO [dbo].[OrganizationIntegration]
(
[Id],
[OrganizationId],
[Type],
[Configuration],
[CreationDate],
[RevisionDate]
)
VALUES
(
@Id,
@OrganizationId,
@Type,
@Configuration,
@CreationDate,
@RevisionDate
)
END
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationIntegrationConfiguration_Create]
@Id UNIQUEIDENTIFIER OUTPUT,
@OrganizationIntegrationId UNIQUEIDENTIFIER,
@EventType SMALLINT,
@Configuration VARCHAR(MAX),
@Template VARCHAR(MAX),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7)
AS
BEGIN
SET NOCOUNT ON
INSERT INTO [dbo].[OrganizationIntegrationConfiguration]
(
[Id],
[OrganizationIntegrationId],
[EventType],
[Configuration],
[Template],
[CreationDate],
[RevisionDate]
)
VALUES
(
@Id,
@OrganizationIntegrationId,
@EventType,
@Configuration,
@Template,
@CreationDate,
@RevisionDate
)
END
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationIntegration_Update]
@Id UNIQUEIDENTIFIER OUTPUT,
@OrganizationId UNIQUEIDENTIFIER,
@Type SMALLINT,
@Configuration VARCHAR(MAX),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7)
AS
BEGIN
SET NOCOUNT ON
UPDATE
[dbo].[OrganizationIntegration]
SET
[OrganizationId] = @OrganizationId,
[Type] = @Type,
[Configuration] = @Configuration,
[CreationDate] = @CreationDate,
[RevisionDate] = @RevisionDate
WHERE
[Id] = @Id
END
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationIntegrationConfiguration_Update]
@Id UNIQUEIDENTIFIER OUTPUT,
@OrganizationIntegrationId UNIQUEIDENTIFIER,
@EventType SMALLINT,
@Configuration VARCHAR(MAX),
@Template VARCHAR(MAX),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7)
AS
BEGIN
SET NOCOUNT ON
UPDATE
[dbo].[OrganizationIntegrationConfiguration]
SET
[OrganizationIntegrationId] = @OrganizationIntegrationId,
[EventType] = @EventType,
[Configuration] = @Configuration,
[Template] = @Template,
[CreationDate] = @CreationDate,
[RevisionDate] = @RevisionDate
WHERE
[Id] = @Id
END
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationIntegration_DeleteById]
@Id UNIQUEIDENTIFIER
AS
BEGIN
SET NOCOUNT ON
DELETE
FROM
[dbo].[OrganizationIntegration]
WHERE
[Id] = @Id
END
GO
CREATE OR ALTER PROCEDURE [dbo].[OrganizationIntegrationConfiguration_DeleteById]
@Id UNIQUEIDENTIFIER
AS
BEGIN
SET NOCOUNT ON
DELETE
FROM
[dbo].[OrganizationIntegrationConfiguration]
WHERE
[Id] = @Id
END