mirror of
https://github.com/bitwarden/server.git
synced 2025-07-02 08:32:50 -05:00

* [AC-1174] Update SelectionReadOnlyRequestModel to use Guid for Id property * [AC-1174] Introduce initial bulk-access collection endpoint * [AC-1174] Introduce BulkAddCollectionAccessCommand and validation logic/tests * [AC-1174] Add CreateOrUpdateAccessMany method to CollectionRepository * [AC-1174] Add event logs for bulk add collection access command * [AC-1174] Add User_BumpAccountRevisionDateByCollectionIds and database migration script * [AC-1174] Implement EF repository method * [AC-1174] Improve null checks * [AC-1174] Remove unnecessary BulkCollectionAccessRequestModel helpers * [AC-1174] Add unit tests for new controller endpoint * [AC-1174] Fix formatting * [AC-1174] Remove comment * [AC-1174] Remove redundant organizationId parameter * [AC-1174] Ensure user and group Ids are distinct * [AC-1174] Cleanup tests based on PR feedback * [AC-1174] Formatting * [AC-1174] Update CollectionGroup alias in the sproc * [AC-1174] Add some additional comments to SQL sproc * [AC-1174] Add comment explaining additional SaveChangesAsync call --------- Co-authored-by: Thomas Rittson <trittson@bitwarden.com>
98 lines
2.7 KiB
Transact-SQL
98 lines
2.7 KiB
Transact-SQL
CREATE PROCEDURE [dbo].[Collection_CreateOrUpdateAccessForMany]
|
|
@OrganizationId UNIQUEIDENTIFIER,
|
|
@CollectionIds AS [dbo].[GuidIdArray] READONLY,
|
|
@Groups AS [dbo].[SelectionReadOnlyArray] READONLY,
|
|
@Users AS [dbo].[SelectionReadOnlyArray] READONLY
|
|
AS
|
|
BEGIN
|
|
SET NOCOUNT ON
|
|
|
|
-- Groups
|
|
;WITH [NewCollectionGroups] AS (
|
|
SELECT
|
|
cId.[Id] AS [CollectionId],
|
|
cg.[Id] AS [GroupId],
|
|
cg.[ReadOnly],
|
|
cg.[HidePasswords],
|
|
cg.[Manage]
|
|
FROM
|
|
@Groups AS cg
|
|
CROSS JOIN -- Create a CollectionGroup record for every CollectionId
|
|
@CollectionIds cId
|
|
INNER JOIN
|
|
[dbo].[Group] g ON cg.[Id] = g.[Id]
|
|
WHERE
|
|
g.[OrganizationId] = @OrganizationId
|
|
)
|
|
MERGE
|
|
[dbo].[CollectionGroup] as [Target]
|
|
USING
|
|
[NewCollectionGroups] AS [Source]
|
|
ON
|
|
[Target].[CollectionId] = [Source].[CollectionId]
|
|
AND [Target].[GroupId] = [Source].[GroupId]
|
|
-- Update the target if any values are different from the source
|
|
WHEN MATCHED AND EXISTS(
|
|
SELECT [Source].[ReadOnly], [Source].[HidePasswords], [Source].[Manage]
|
|
EXCEPT
|
|
SELECT [Target].[ReadOnly], [Target].[HidePasswords], [Target].[Manage]
|
|
) THEN UPDATE SET
|
|
[Target].[ReadOnly] = [Source].[ReadOnly],
|
|
[Target].[HidePasswords] = [Source].[HidePasswords],
|
|
[Target].[Manage] = [Source].[Manage]
|
|
WHEN NOT MATCHED BY TARGET
|
|
THEN INSERT VALUES
|
|
(
|
|
[Source].[CollectionId],
|
|
[Source].[GroupId],
|
|
[Source].[ReadOnly],
|
|
[Source].[HidePasswords],
|
|
[Source].[Manage]
|
|
);
|
|
|
|
-- Users
|
|
;WITH [NewCollectionUsers] AS (
|
|
SELECT
|
|
cId.[Id] AS [CollectionId],
|
|
cu.[Id] AS [OrganizationUserId],
|
|
cu.[ReadOnly],
|
|
cu.[HidePasswords],
|
|
cu.[Manage]
|
|
FROM
|
|
@Users AS cu
|
|
CROSS JOIN -- Create a CollectionUser record for every CollectionId
|
|
@CollectionIds cId
|
|
INNER JOIN
|
|
[dbo].[OrganizationUser] u ON cu.[Id] = u.[Id]
|
|
WHERE
|
|
u.[OrganizationId] = @OrganizationId
|
|
)
|
|
MERGE
|
|
[dbo].[CollectionUser] as [Target]
|
|
USING
|
|
[NewCollectionUsers] AS [Source]
|
|
ON
|
|
[Target].[CollectionId] = [Source].[CollectionId]
|
|
AND [Target].[OrganizationUserId] = [Source].[OrganizationUserId]
|
|
-- Update the target if any values are different from the source
|
|
WHEN MATCHED AND EXISTS(
|
|
SELECT [Source].[ReadOnly], [Source].[HidePasswords], [Source].[Manage]
|
|
EXCEPT
|
|
SELECT [Target].[ReadOnly], [Target].[HidePasswords], [Target].[Manage]
|
|
) THEN UPDATE SET
|
|
[Target].[ReadOnly] = [Source].[ReadOnly],
|
|
[Target].[HidePasswords] = [Source].[HidePasswords],
|
|
[Target].[Manage] = [Source].[Manage]
|
|
WHEN NOT MATCHED BY TARGET
|
|
THEN INSERT VALUES
|
|
(
|
|
[Source].[CollectionId],
|
|
[Source].[OrganizationUserId],
|
|
[Source].[ReadOnly],
|
|
[Source].[HidePasswords],
|
|
[Source].[Manage]
|
|
);
|
|
|
|
EXEC [dbo].[User_BumpAccountRevisionDateByCollectionIds] @CollectionIds, @OrganizationId
|
|
END
|