mirror of
https://github.com/bitwarden/server
synced 2025-12-25 04:33:26 +00:00
* Update sql files to add Manage permission * Add migration script * Rename collection manage migration file to remove duplicate migration date * Migrations * Add manage to models * Add manage to repository * Add constraint to Manage columns * Migration lint fixes * Add manage to OrganizationUserUserDetails_ReadWithCollectionsById * Add missing manage fields * Add 'Manage' to UserCollectionDetails * Use CREATE OR ALTER where possible
78 lines
1.9 KiB
Transact-SQL
78 lines
1.9 KiB
Transact-SQL
CREATE PROCEDURE [dbo].[CollectionUser_UpdateUsers]
|
|
@CollectionId UNIQUEIDENTIFIER,
|
|
@Users AS [dbo].[SelectionReadOnlyArray] READONLY
|
|
AS
|
|
BEGIN
|
|
SET NOCOUNT ON
|
|
|
|
DECLARE @OrgId UNIQUEIDENTIFIER = (
|
|
SELECT TOP 1
|
|
[OrganizationId]
|
|
FROM
|
|
[dbo].[Collection]
|
|
WHERE
|
|
[Id] = @CollectionId
|
|
)
|
|
|
|
-- Update
|
|
UPDATE
|
|
[Target]
|
|
SET
|
|
[Target].[ReadOnly] = [Source].[ReadOnly],
|
|
[Target].[HidePasswords] = [Source].[HidePasswords],
|
|
[Target].[Manage] = [Source].[Manage]
|
|
FROM
|
|
[dbo].[CollectionUser] [Target]
|
|
INNER JOIN
|
|
@Users [Source] ON [Source].[Id] = [Target].[OrganizationUserId]
|
|
WHERE
|
|
[Target].[CollectionId] = @CollectionId
|
|
AND (
|
|
[Target].[ReadOnly] != [Source].[ReadOnly]
|
|
OR [Target].[HidePasswords] != [Source].[HidePasswords]
|
|
OR [Target].[Manage] != [Source].[Manage]
|
|
)
|
|
|
|
-- Insert
|
|
INSERT INTO
|
|
[dbo].[CollectionUser]
|
|
SELECT
|
|
@CollectionId,
|
|
[Source].[Id],
|
|
[Source].[ReadOnly],
|
|
[Source].[HidePasswords],
|
|
[Source].[Manage]
|
|
FROM
|
|
@Users [Source]
|
|
INNER JOIN
|
|
[dbo].[OrganizationUser] OU ON [Source].[Id] = OU.[Id] AND OU.[OrganizationId] = @OrgId
|
|
WHERE
|
|
NOT EXISTS (
|
|
SELECT
|
|
1
|
|
FROM
|
|
[dbo].[CollectionUser]
|
|
WHERE
|
|
[CollectionId] = @CollectionId
|
|
AND [OrganizationUserId] = [Source].[Id]
|
|
)
|
|
|
|
-- Delete
|
|
DELETE
|
|
CU
|
|
FROM
|
|
[dbo].[CollectionUser] CU
|
|
WHERE
|
|
CU.[CollectionId] = @CollectionId
|
|
AND NOT EXISTS (
|
|
SELECT
|
|
1
|
|
FROM
|
|
@Users
|
|
WHERE
|
|
[Id] = CU.[OrganizationUserId]
|
|
)
|
|
|
|
EXEC [dbo].[User_BumpAccountRevisionDateByCollectionId] @CollectionId, @OrgId
|
|
END
|