mirror of
https://github.com/bitwarden/server.git
synced 2025-02-22 02:51:33 +01:00
cleanup sql aliases from collection rename
This commit is contained in:
parent
77aec3977c
commit
44883091f6
@ -5,7 +5,7 @@ BEGIN
|
||||
|
||||
;WITH [CTE] AS(
|
||||
SELECT
|
||||
CASE WHEN OU.[AccessAllCollections] = 1 OR SU.[ReadOnly] = 0 THEN 1 ELSE 0 END [CanEdit]
|
||||
CASE WHEN OU.[AccessAllCollections] = 1 OR CU.[ReadOnly] = 0 THEN 1 ELSE 0 END [CanEdit]
|
||||
FROM
|
||||
[dbo].[Cipher] C
|
||||
INNER JOIN
|
||||
@ -13,14 +13,14 @@ BEGIN
|
||||
INNER JOIN
|
||||
[dbo].[OrganizationUser] OU ON OU.[OrganizationId] = O.[Id] AND OU.[UserId] = @UserId
|
||||
LEFT JOIN
|
||||
[dbo].[CollectionCipher] SC ON C.[UserId] IS NULL AND OU.[AccessAllCollections] = 0 AND SC.[CipherId] = C.[Id]
|
||||
[dbo].[CollectionCipher] CC ON C.[UserId] IS NULL AND OU.[AccessAllCollections] = 0 AND CC.[CipherId] = C.[Id]
|
||||
LEFT JOIN
|
||||
[dbo].[CollectionUser] SU ON SU.[CollectionId] = SC.[CollectionId] AND SU.[OrganizationUserId] = OU.[Id]
|
||||
[dbo].[CollectionUser] CU ON CU.[CollectionId] = CC.[CollectionId] AND CU.[OrganizationUserId] = OU.[Id]
|
||||
WHERE
|
||||
C.[Id] = @CipherId
|
||||
AND OU.[Status] = 2 -- 2 = Confirmed
|
||||
AND O.[Enabled] = 1
|
||||
AND (OU.[AccessAllCollections] = 1 OR SU.[CollectionId] IS NOT NULL)
|
||||
AND (OU.[AccessAllCollections] = 1 OR CU.[CollectionId] IS NOT NULL)
|
||||
)
|
||||
SELECT
|
||||
@CanEdit = CASE WHEN COUNT(1) > 0 THEN 1 ELSE 0 END
|
||||
|
@ -14,9 +14,9 @@ BEGIN
|
||||
LEFT JOIN
|
||||
[dbo].[OrganizationUser] OU ON OU.[OrganizationId] = O.[Id] AND OU.[UserId] = @UserId
|
||||
LEFT JOIN
|
||||
[dbo].[CollectionCipher] SC ON C.[UserId] IS NULL AND OU.[AccessAllCollections] = 0 AND SC.[CipherId] = C.[Id]
|
||||
[dbo].[CollectionCipher] CC ON C.[UserId] IS NULL AND OU.[AccessAllCollections] = 0 AND CC.[CipherId] = C.[Id]
|
||||
LEFT JOIN
|
||||
[dbo].[CollectionUser] SU ON SU.[CollectionId] = SC.[CollectionId] AND SU.[OrganizationUserId] = OU.[Id]
|
||||
[dbo].[CollectionUser] CU ON CU.[CollectionId] = CC.[CollectionId] AND CU.[OrganizationUserId] = OU.[Id]
|
||||
WHERE
|
||||
C.Id = @Id
|
||||
AND (
|
||||
@ -25,7 +25,7 @@ BEGIN
|
||||
C.[UserId] IS NULL
|
||||
AND OU.[Status] = 2 -- 2 = Confirmed
|
||||
AND O.[Enabled] = 1
|
||||
AND (OU.[AccessAllCollections] = 1 OR SU.[CollectionId] IS NOT NULL)
|
||||
AND (OU.[AccessAllCollections] = 1 OR CU.[CollectionId] IS NOT NULL)
|
||||
)
|
||||
)
|
||||
END
|
@ -14,9 +14,9 @@ BEGIN
|
||||
LEFT JOIN
|
||||
[dbo].[OrganizationUser] OU ON OU.[OrganizationId] = O.[Id] AND OU.[UserId] = @UserId
|
||||
LEFT JOIN
|
||||
[dbo].[CollectionCipher] SC ON C.[UserId] IS NULL AND OU.[AccessAllCollections] = 0 AND SC.[CipherId] = C.[Id]
|
||||
[dbo].[CollectionCipher] CC ON C.[UserId] IS NULL AND OU.[AccessAllCollections] = 0 AND CC.[CipherId] = C.[Id]
|
||||
LEFT JOIN
|
||||
[dbo].[CollectionUser] SU ON SU.[CollectionId] = SC.[CollectionId] AND SU.[OrganizationUserId] = OU.[Id]
|
||||
[dbo].[CollectionUser] CU ON CU.[CollectionId] = CC.[CollectionId] AND CU.[OrganizationUserId] = OU.[Id]
|
||||
WHERE
|
||||
C.[Type] = @Type
|
||||
AND (
|
||||
@ -25,7 +25,7 @@ BEGIN
|
||||
C.[UserId] IS NULL
|
||||
AND OU.[Status] = 2 -- 2 = Confirmed
|
||||
AND O.[Enabled] = 1
|
||||
AND (OU.[AccessAllCollections] = 1 OR SU.[CollectionId] IS NOT NULL)
|
||||
AND (OU.[AccessAllCollections] = 1 OR CU.[CollectionId] IS NOT NULL)
|
||||
)
|
||||
)
|
||||
END
|
@ -13,15 +13,15 @@ BEGIN
|
||||
LEFT JOIN
|
||||
[dbo].[OrganizationUser] OU ON OU.[OrganizationId] = O.[Id] AND OU.[UserId] = @UserId
|
||||
LEFT JOIN
|
||||
[dbo].[CollectionCipher] SC ON C.[UserId] IS NULL AND OU.[AccessAllCollections] = 0 AND SC.[CipherId] = C.[Id]
|
||||
[dbo].[CollectionCipher] CC ON C.[UserId] IS NULL AND OU.[AccessAllCollections] = 0 AND CC.[CipherId] = C.[Id]
|
||||
LEFT JOIN
|
||||
[dbo].[CollectionUser] SU ON SU.[CollectionId] = SC.[CollectionId] AND SU.[OrganizationUserId] = OU.[Id]
|
||||
[dbo].[CollectionUser] CU ON CU.[CollectionId] = CC.[CollectionId] AND CU.[OrganizationUserId] = OU.[Id]
|
||||
WHERE
|
||||
C.[UserId] = @UserId
|
||||
OR (
|
||||
C.[UserId] IS NULL
|
||||
AND OU.[Status] = 2 -- 2 = Confirmed
|
||||
AND O.[Enabled] = 1
|
||||
AND (OU.[AccessAllCollections] = 1 OR SU.[CollectionId] IS NOT NULL)
|
||||
AND (OU.[AccessAllCollections] = 1 OR CU.[CollectionId] IS NOT NULL)
|
||||
)
|
||||
END
|
@ -13,11 +13,11 @@ BEGIN
|
||||
INNER JOIN
|
||||
[dbo].[OrganizationUser] OU ON OU.[OrganizationId] = O.[Id] AND OU.[UserId] = @UserId
|
||||
LEFT JOIN
|
||||
[dbo].[CollectionCipher] SC ON C.[UserId] IS NULL AND OU.[AccessAllCollections] = 0 AND SC.[CipherId] = C.[Id]
|
||||
[dbo].[CollectionCipher] CC ON C.[UserId] IS NULL AND OU.[AccessAllCollections] = 0 AND CC.[CipherId] = C.[Id]
|
||||
LEFT JOIN
|
||||
[dbo].[CollectionUser] SU ON SU.[CollectionId] = SC.[CollectionId] AND SU.[OrganizationUserId] = OU.[Id]
|
||||
[dbo].[CollectionUser] CU ON CU.[CollectionId] = CC.[CollectionId] AND CU.[OrganizationUserId] = OU.[Id]
|
||||
WHERE
|
||||
OU.[Status] = 2 -- 2 = Confirmed
|
||||
AND O.[Enabled] = 1
|
||||
AND (OU.[AccessAllCollections] = 1 OR SU.[CollectionId] IS NOT NULL)
|
||||
AND (OU.[AccessAllCollections] = 1 OR CU.[CollectionId] IS NOT NULL)
|
||||
END
|
@ -18,9 +18,9 @@ BEGIN
|
||||
LEFT JOIN
|
||||
[dbo].[OrganizationUser] OU ON OU.[OrganizationId] = O.[Id] AND OU.[UserId] = @UserId
|
||||
LEFT JOIN
|
||||
[dbo].[CollectionCipher] SC ON C.[UserId] IS NULL AND OU.[AccessAllCollections] = 0 AND SC.[CipherId] = C.[Id]
|
||||
[dbo].[CollectionCipher] CC ON C.[UserId] IS NULL AND OU.[AccessAllCollections] = 0 AND CC.[CipherId] = C.[Id]
|
||||
LEFT JOIN
|
||||
[dbo].[CollectionUser] SU ON SU.[CollectionId] = SC.[CollectionId] AND SU.[OrganizationUserId] = OU.[Id]
|
||||
[dbo].[CollectionUser] CU ON CU.[CollectionId] = CC.[CollectionId] AND CU.[OrganizationUserId] = OU.[Id]
|
||||
WHERE
|
||||
C.Id = @Id
|
||||
AND (
|
||||
@ -29,7 +29,7 @@ BEGIN
|
||||
C.[UserId] IS NULL
|
||||
AND OU.[Status] = 2 -- 2 = Confirmed
|
||||
AND O.[Enabled] = 1
|
||||
AND (OU.[AccessAllCollections] = 1 OR SU.[CollectionId] IS NOT NULL)
|
||||
AND (OU.[AccessAllCollections] = 1 OR CU.[CollectionId] IS NOT NULL)
|
||||
)
|
||||
)
|
||||
END
|
@ -34,12 +34,12 @@ BEGIN
|
||||
INNER JOIN
|
||||
[dbo].[OrganizationUser] OU ON OU.[OrganizationId] = O.[Id] AND OU.[UserId] = @UserId
|
||||
LEFT JOIN
|
||||
[dbo].[CollectionUser] SU ON OU.[AccessAllCollections] = 0 AND SU.[CollectionId] = S.[Id] AND SU.[OrganizationUserId] = OU.[Id]
|
||||
[dbo].[CollectionUser] CU ON OU.[AccessAllCollections] = 0 AND CU.[CollectionId] = S.[Id] AND CU.[OrganizationUserId] = OU.[Id]
|
||||
WHERE
|
||||
O.[Id] = @OrganizationId
|
||||
AND O.[Enabled] = 1
|
||||
AND OU.[Status] = 2 -- Confirmed
|
||||
AND (OU.[AccessAllCollections] = 1 OR SU.[ReadOnly] = 0)
|
||||
AND (OU.[AccessAllCollections] = 1 OR CU.[ReadOnly] = 0)
|
||||
)
|
||||
INSERT INTO [dbo].[CollectionCipher]
|
||||
(
|
||||
|
@ -13,8 +13,8 @@ BEGIN
|
||||
INNER JOIN
|
||||
[dbo].[OrganizationUser] OU ON OU.[OrganizationId] = S.[OrganizationId] AND OU.[UserId] = @UserId
|
||||
LEFT JOIN
|
||||
[dbo].[CollectionUser] SU ON OU.[AccessAllCollections] = 0 AND SU.[CollectionId] = S.[Id] AND SU.[OrganizationUserId] = OU.[Id]
|
||||
[dbo].[CollectionUser] CU ON OU.[AccessAllCollections] = 0 AND CU.[CollectionId] = S.[Id] AND CU.[OrganizationUserId] = OU.[Id]
|
||||
WHERE
|
||||
OU.[Status] = 2 -- Confirmed
|
||||
AND (OU.[AccessAllCollections] = 1 OR SU.[CollectionId] IS NOT NULL)
|
||||
AND (OU.[AccessAllCollections] = 1 OR CU.[CollectionId] IS NOT NULL)
|
||||
END
|
@ -14,9 +14,9 @@ BEGIN
|
||||
INNER JOIN
|
||||
[dbo].[OrganizationUser] OU ON OU.[OrganizationId] = S.[OrganizationId] AND OU.[UserId] = @UserId
|
||||
LEFT JOIN
|
||||
[dbo].[CollectionUser] SU ON OU.[AccessAllCollections] = 0 AND SU.[CollectionId] = S.[Id] AND SU.[OrganizationUserId] = OU.[Id]
|
||||
[dbo].[CollectionUser] CU ON OU.[AccessAllCollections] = 0 AND CU.[CollectionId] = S.[Id] AND CU.[OrganizationUserId] = OU.[Id]
|
||||
WHERE
|
||||
SC.[CipherId] = @CipherId
|
||||
AND OU.[Status] = 2 -- Confirmed
|
||||
AND (OU.[AccessAllCollections] = 1 OR SU.[CollectionId] IS NOT NULL)
|
||||
AND (OU.[AccessAllCollections] = 1 OR CU.[CollectionId] IS NOT NULL)
|
||||
END
|
@ -25,12 +25,12 @@ BEGIN
|
||||
INNER JOIN
|
||||
[dbo].[OrganizationUser] OU ON OU.[OrganizationId] = O.[Id] AND OU.[UserId] = @UserId
|
||||
LEFT JOIN
|
||||
[dbo].[CollectionUser] SU ON OU.[AccessAllCollections] = 0 AND SU.[CollectionId] = S.[Id] AND SU.[OrganizationUserId] = OU.[Id]
|
||||
[dbo].[CollectionUser] CU ON OU.[AccessAllCollections] = 0 AND CU.[CollectionId] = S.[Id] AND CU.[OrganizationUserId] = OU.[Id]
|
||||
WHERE
|
||||
O.[Id] = @OrgId
|
||||
AND O.[Enabled] = 1
|
||||
AND OU.[Status] = 2 -- Confirmed
|
||||
AND (OU.[AccessAllCollections] = 1 OR SU.[ReadOnly] = 0)
|
||||
AND (OU.[AccessAllCollections] = 1 OR CU.[ReadOnly] = 0)
|
||||
)
|
||||
MERGE
|
||||
[dbo].[CollectionCipher] AS [Target]
|
||||
|
@ -5,11 +5,11 @@ BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT
|
||||
SU.*
|
||||
CU.*
|
||||
FROM
|
||||
[dbo].[CollectionUserCollectionDetailsView] SU
|
||||
[dbo].[CollectionUserCollectionDetailsView] CU
|
||||
INNER JOIN
|
||||
[OrganizationUser] OU ON SU.[OrganizationUserId] = OU.[Id]
|
||||
[OrganizationUser] OU ON CU.[OrganizationUserId] = OU.[Id]
|
||||
WHERE
|
||||
OU.[UserId] = @UserId
|
||||
END
|
@ -13,9 +13,9 @@ BEGIN
|
||||
INNER JOIN
|
||||
[dbo].[OrganizationUser] OU ON OU.[OrganizationId] = O.[Id] AND OU.[UserId] = @UserId
|
||||
LEFT JOIN
|
||||
[dbo].[CollectionUser] SU ON OU.[AccessAllCollections] = 0 AND SU.[CollectionId] = S.[Id] AND SU.[OrganizationUserId] = OU.[Id]
|
||||
[dbo].[CollectionUser] CU ON OU.[AccessAllCollections] = 0 AND CU.[CollectionId] = S.[Id] AND CU.[OrganizationUserId] = OU.[Id]
|
||||
WHERE
|
||||
OU.[Status] = 2 -- Confirmed
|
||||
AND O.[Enabled] = 1
|
||||
AND (OU.[AccessAllCollections] = 1 OR SU.[CollectionId] IS NOT NULL)
|
||||
AND (OU.[AccessAllCollections] = 1 OR CU.[CollectionId] IS NOT NULL)
|
||||
END
|
@ -18,14 +18,14 @@ BEGIN
|
||||
LEFT JOIN
|
||||
[dbo].[OrganizationUser] OU ON OU.[OrganizationId] = O.[Id] AND OU.[UserId] = @UserId
|
||||
LEFT JOIN
|
||||
[dbo].[CollectionCipher] SC ON C.[UserId] IS NULL AND OU.[AccessAllCollections] = 0 AND SC.[CipherId] = C.[Id]
|
||||
[dbo].[CollectionCipher] CC ON C.[UserId] IS NULL AND OU.[AccessAllCollections] = 0 AND CC.[CipherId] = C.[Id]
|
||||
LEFT JOIN
|
||||
[dbo].[CollectionUser] SU ON SU.[CollectionId] = SC.[CollectionId] AND SU.[OrganizationUserId] = OU.[Id]
|
||||
[dbo].[CollectionUser] CU ON CU.[CollectionId] = CC.[CollectionId] AND CU.[OrganizationUserId] = OU.[Id]
|
||||
WHERE
|
||||
C.[UserId] = @UserId
|
||||
OR (
|
||||
C.[UserId] IS NULL
|
||||
AND (OU.[AccessAllCollections] = 1 OR SU.[CollectionId] IS NOT NULL)
|
||||
AND (OU.[AccessAllCollections] = 1 OR CU.[CollectionId] IS NOT NULL)
|
||||
)
|
||||
AND C.[Folders] IS NOT NULL
|
||||
AND JSON_VALUE(C.[Folders], @UserIdPath) = @Id
|
||||
|
@ -1,12 +1,12 @@
|
||||
CREATE VIEW [dbo].[CollectionUserCollectionDetailsView]
|
||||
AS
|
||||
SELECT
|
||||
SU.[Id],
|
||||
SU.[OrganizationUserId],
|
||||
CU.[Id],
|
||||
CU.[OrganizationUserId],
|
||||
S.[Name],
|
||||
S.[Id] CollectionId,
|
||||
SU.[ReadOnly]
|
||||
CU.[ReadOnly]
|
||||
FROM
|
||||
[dbo].[CollectionUser] SU
|
||||
[dbo].[CollectionUser] CU
|
||||
INNER JOIN
|
||||
[dbo].[Collection] S ON S.[Id] = SU.[CollectionId]
|
||||
[dbo].[Collection] S ON S.[Id] = CU.[CollectionId]
|
@ -3,16 +3,16 @@ AS
|
||||
SELECT
|
||||
OU.[Id] AS [OrganizationUserId],
|
||||
OU.[AccessAllCollections],
|
||||
SU.[Id],
|
||||
SU.[CollectionId],
|
||||
CU.[Id],
|
||||
CU.[CollectionId],
|
||||
U.[Name],
|
||||
ISNULL(U.[Email], OU.[Email]) Email,
|
||||
OU.[Status],
|
||||
OU.[Type],
|
||||
CASE WHEN OU.[AccessAllCollections] = 0 AND SU.[ReadOnly] = 1 THEN 1 ELSE 0 END [ReadOnly]
|
||||
CASE WHEN OU.[AccessAllCollections] = 0 AND CU.[ReadOnly] = 1 THEN 1 ELSE 0 END [ReadOnly]
|
||||
FROM
|
||||
[dbo].[OrganizationUser] OU
|
||||
LEFT JOIN
|
||||
[dbo].[CollectionUser] SU ON OU.[AccessAllCollections] = 0 AND SU.[OrganizationUserId] = OU.[Id]
|
||||
[dbo].[CollectionUser] CU ON OU.[AccessAllCollections] = 0 AND CU.[OrganizationUserId] = OU.[Id]
|
||||
LEFT JOIN
|
||||
[dbo].[User] U ON U.[Id] = OU.[UserId]
|
Loading…
Reference in New Issue
Block a user