mirror of
https://github.com/bitwarden/server.git
synced 2024-11-22 12:15:36 +01:00
0da62f9cee
- Add default constraint - Update sprocs to remove column - Drop column
171 lines
4.0 KiB
Transact-SQL
171 lines
4.0 KiB
Transact-SQL
-- Finalise removal of Group.AccessAll column
|
|
-- Remove the column from sprocs
|
|
|
|
CREATE OR ALTER PROCEDURE [dbo].[Group_Create]
|
|
@Id UNIQUEIDENTIFIER OUTPUT,
|
|
@OrganizationId UNIQUEIDENTIFIER,
|
|
@Name NVARCHAR(100),
|
|
@ExternalId NVARCHAR(300),
|
|
@CreationDate DATETIME2(7),
|
|
@RevisionDate DATETIME2(7)
|
|
AS
|
|
BEGIN
|
|
SET NOCOUNT ON
|
|
|
|
INSERT INTO [dbo].[Group]
|
|
(
|
|
[Id],
|
|
[OrganizationId],
|
|
[Name],
|
|
[ExternalId],
|
|
[CreationDate],
|
|
[RevisionDate]
|
|
)
|
|
VALUES
|
|
(
|
|
@Id,
|
|
@OrganizationId,
|
|
@Name,
|
|
@ExternalId,
|
|
@CreationDate,
|
|
@RevisionDate
|
|
)
|
|
END
|
|
GO
|
|
|
|
|
|
CREATE OR ALTER PROCEDURE [dbo].[Group_CreateWithCollections]
|
|
@Id UNIQUEIDENTIFIER,
|
|
@OrganizationId UNIQUEIDENTIFIER,
|
|
@Name NVARCHAR(100),
|
|
@ExternalId NVARCHAR(300),
|
|
@CreationDate DATETIME2(7),
|
|
@RevisionDate DATETIME2(7),
|
|
@Collections AS [dbo].[CollectionAccessSelectionType] READONLY
|
|
AS
|
|
BEGIN
|
|
SET NOCOUNT ON
|
|
|
|
EXEC [dbo].[Group_Create] @Id, @OrganizationId, @Name, @ExternalId, @CreationDate, @RevisionDate
|
|
|
|
;WITH [AvailableCollectionsCTE] AS(
|
|
SELECT
|
|
[Id]
|
|
FROM
|
|
[dbo].[Collection]
|
|
WHERE
|
|
[OrganizationId] = @OrganizationId
|
|
)
|
|
INSERT INTO [dbo].[CollectionGroup]
|
|
(
|
|
[CollectionId],
|
|
[GroupId],
|
|
[ReadOnly],
|
|
[HidePasswords],
|
|
[Manage]
|
|
)
|
|
SELECT
|
|
[Id],
|
|
@Id,
|
|
[ReadOnly],
|
|
[HidePasswords],
|
|
[Manage]
|
|
FROM
|
|
@Collections
|
|
WHERE
|
|
[Id] IN (SELECT [Id] FROM [AvailableCollectionsCTE])
|
|
|
|
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId
|
|
END
|
|
GO
|
|
|
|
|
|
CREATE OR ALTER PROCEDURE [dbo].[Group_Update]
|
|
@Id UNIQUEIDENTIFIER,
|
|
@OrganizationId UNIQUEIDENTIFIER,
|
|
@Name NVARCHAR(100),
|
|
@ExternalId NVARCHAR(300),
|
|
@CreationDate DATETIME2(7),
|
|
@RevisionDate DATETIME2(7)
|
|
AS
|
|
BEGIN
|
|
SET NOCOUNT ON
|
|
|
|
UPDATE
|
|
[dbo].[Group]
|
|
SET
|
|
[OrganizationId] = @OrganizationId,
|
|
[Name] = @Name,
|
|
[ExternalId] = @ExternalId,
|
|
[CreationDate] = @CreationDate,
|
|
[RevisionDate] = @RevisionDate
|
|
WHERE
|
|
[Id] = @Id
|
|
END
|
|
GO
|
|
|
|
|
|
CREATE OR ALTER PROCEDURE [dbo].[Group_UpdateWithCollections]
|
|
@Id UNIQUEIDENTIFIER,
|
|
@OrganizationId UNIQUEIDENTIFIER,
|
|
@Name NVARCHAR(100),
|
|
@ExternalId NVARCHAR(300),
|
|
@CreationDate DATETIME2(7),
|
|
@RevisionDate DATETIME2(7),
|
|
@Collections AS [dbo].[CollectionAccessSelectionType] READONLY
|
|
AS
|
|
BEGIN
|
|
SET NOCOUNT ON
|
|
|
|
EXEC [dbo].[Group_Update] @Id, @OrganizationId, @Name, @ExternalId, @CreationDate, @RevisionDate
|
|
|
|
;WITH [AvailableCollectionsCTE] AS(
|
|
SELECT
|
|
Id
|
|
FROM
|
|
[dbo].[Collection]
|
|
WHERE
|
|
OrganizationId = @OrganizationId
|
|
)
|
|
MERGE
|
|
[dbo].[CollectionGroup] AS [Target]
|
|
USING
|
|
@Collections AS [Source]
|
|
ON
|
|
[Target].[CollectionId] = [Source].[Id]
|
|
AND [Target].[GroupId] = @Id
|
|
WHEN NOT MATCHED BY TARGET
|
|
AND [Source].[Id] IN (SELECT [Id] FROM [AvailableCollectionsCTE]) THEN
|
|
INSERT
|
|
(
|
|
[CollectionId],
|
|
[GroupId],
|
|
[ReadOnly],
|
|
[HidePasswords],
|
|
[Manage]
|
|
)
|
|
VALUES
|
|
(
|
|
[Source].[Id],
|
|
@Id,
|
|
[Source].[ReadOnly],
|
|
[Source].[HidePasswords],
|
|
[Source].[Manage]
|
|
)
|
|
WHEN MATCHED AND (
|
|
[Target].[ReadOnly] != [Source].[ReadOnly]
|
|
OR [Target].[HidePasswords] != [Source].[HidePasswords]
|
|
OR [Target].[Manage] != [Source].[Manage]
|
|
) THEN
|
|
UPDATE SET [Target].[ReadOnly] = [Source].[ReadOnly],
|
|
[Target].[HidePasswords] = [Source].[HidePasswords],
|
|
[Target].[Manage] = [Source].[Manage]
|
|
WHEN NOT MATCHED BY SOURCE
|
|
AND [Target].[GroupId] = @Id THEN
|
|
DELETE
|
|
;
|
|
|
|
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId
|
|
END
|
|
GO
|