mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 15:42:48 -05:00
apis for bulk sharing
This commit is contained in:
@ -18,8 +18,8 @@ BEGIN
|
||||
OR G.[AccessAll] = 1
|
||||
OR CU.[ReadOnly] = 0
|
||||
OR CG.[ReadOnly] = 0
|
||||
THEN 1
|
||||
ELSE 0
|
||||
THEN 0
|
||||
ELSE 1
|
||||
END [ReadOnly]
|
||||
FROM
|
||||
[dbo].[CollectionView] C
|
||||
@ -62,13 +62,13 @@ BEGIN
|
||||
|
||||
DECLARE @Storage BIGINT
|
||||
|
||||
CREATE TABLE #Temp
|
||||
CREATE TABLE #OrgStorageUpdateTemp
|
||||
(
|
||||
[Id] UNIQUEIDENTIFIER NOT NULL,
|
||||
[Attachments] VARCHAR(MAX) NULL
|
||||
)
|
||||
|
||||
INSERT INTO #Temp
|
||||
INSERT INTO #OrgStorageUpdateTemp
|
||||
SELECT
|
||||
[Id],
|
||||
[Attachments]
|
||||
@ -88,14 +88,14 @@ BEGIN
|
||||
OPENJSON([Attachments])
|
||||
) [Size]
|
||||
FROM
|
||||
#Temp
|
||||
#OrgStorageUpdateTemp
|
||||
)
|
||||
SELECT
|
||||
@Storage = SUM([Size])
|
||||
FROM
|
||||
[CTE]
|
||||
|
||||
DROP TABLE #Temp
|
||||
DROP TABLE #OrgStorageUpdateTemp
|
||||
|
||||
UPDATE
|
||||
[dbo].[Organization]
|
||||
@ -121,13 +121,13 @@ BEGIN
|
||||
|
||||
DECLARE @Storage BIGINT
|
||||
|
||||
CREATE TABLE #Temp
|
||||
CREATE TABLE #UserStorageUpdateTemp
|
||||
(
|
||||
[Id] UNIQUEIDENTIFIER NOT NULL,
|
||||
[Attachments] VARCHAR(MAX) NULL
|
||||
)
|
||||
|
||||
INSERT INTO #Temp
|
||||
INSERT INTO #UserStorageUpdateTemp
|
||||
SELECT
|
||||
[Id],
|
||||
[Attachments]
|
||||
@ -146,14 +146,14 @@ BEGIN
|
||||
OPENJSON([Attachments])
|
||||
) [Size]
|
||||
FROM
|
||||
#Temp
|
||||
#UserStorageUpdateTemp
|
||||
)
|
||||
SELECT
|
||||
@Storage = SUM([CTE].[Size])
|
||||
FROM
|
||||
[CTE]
|
||||
|
||||
DROP TABLE #Temp
|
||||
DROP TABLE #UserStorageUpdateTemp
|
||||
|
||||
UPDATE
|
||||
[dbo].[User]
|
||||
@ -164,3 +164,75 @@ BEGIN
|
||||
[Id] = @Id
|
||||
END
|
||||
GO
|
||||
|
||||
IF OBJECT_ID('[dbo].[CollectionCipher_UpdateCollectionsForCiphers]') IS NOT NULL
|
||||
BEGIN
|
||||
DROP PROCEDURE [dbo].[CollectionCipher_UpdateCollectionsForCiphers]
|
||||
END
|
||||
GO
|
||||
|
||||
CREATE PROCEDURE [dbo].[CollectionCipher_UpdateCollectionsForCiphers]
|
||||
@CipherIds AS [dbo].[GuidIdArray] READONLY,
|
||||
@OrganizationId UNIQUEIDENTIFIER,
|
||||
@UserId UNIQUEIDENTIFIER,
|
||||
@CollectionIds AS [dbo].[GuidIdArray] READONLY
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
CREATE TABLE #AvailableCollections (
|
||||
[Id] UNIQUEIDENTIFIER
|
||||
)
|
||||
|
||||
INSERT INTO #AvailableCollections
|
||||
SELECT
|
||||
C.[Id]
|
||||
FROM
|
||||
[dbo].[Collection] C
|
||||
INNER JOIN
|
||||
[Organization] O ON O.[Id] = C.[OrganizationId]
|
||||
INNER JOIN
|
||||
[dbo].[OrganizationUser] OU ON OU.[OrganizationId] = O.[Id] AND OU.[UserId] = @UserId
|
||||
LEFT JOIN
|
||||
[dbo].[CollectionUser] CU ON OU.[AccessAll] = 0 AND CU.[CollectionId] = C.[Id] AND CU.[OrganizationUserId] = OU.[Id]
|
||||
LEFT JOIN
|
||||
[dbo].[GroupUser] GU ON CU.[CollectionId] IS NULL AND OU.[AccessAll] = 0 AND GU.[OrganizationUserId] = OU.[Id]
|
||||
LEFT JOIN
|
||||
[dbo].[Group] G ON G.[Id] = GU.[GroupId]
|
||||
LEFT JOIN
|
||||
[dbo].[CollectionGroup] CG ON G.[AccessAll] = 0 AND CG.[GroupId] = GU.[GroupId]
|
||||
WHERE
|
||||
O.[Id] = @OrganizationId
|
||||
AND O.[Enabled] = 1
|
||||
AND OU.[Status] = 2 -- Confirmed
|
||||
AND (
|
||||
OU.[AccessAll] = 1
|
||||
OR CU.[ReadOnly] = 0
|
||||
OR G.[AccessAll] = 1
|
||||
OR CG.[ReadOnly] = 0
|
||||
)
|
||||
|
||||
IF (SELECT COUNT(1) FROM #AvailableCollections) < 1
|
||||
BEGIN
|
||||
-- No writable collections available to share with in this organization.
|
||||
RETURN
|
||||
END
|
||||
|
||||
INSERT INTO [dbo].[CollectionCipher]
|
||||
(
|
||||
[CollectionId],
|
||||
[CipherId]
|
||||
)
|
||||
SELECT
|
||||
[Collection].[Id],
|
||||
[Cipher].[Id]
|
||||
FROM
|
||||
@CollectionIds [Collection]
|
||||
INNER JOIN
|
||||
@CipherIds [Cipher] ON 1 = 1
|
||||
WHERE
|
||||
[Collection].[Id] IN (SELECT [Id] FROM #AvailableCollections)
|
||||
|
||||
EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrganizationId
|
||||
END
|
||||
GO
|
||||
|
Reference in New Issue
Block a user