diff --git a/src/Sql/dbo/Functions/UserCanEditCipher.sql b/src/Sql/dbo/Functions/UserCanEditCipher.sql index 313833410d..8b1309146f 100644 --- a/src/Sql/dbo/Functions/UserCanEditCipher.sql +++ b/src/Sql/dbo/Functions/UserCanEditCipher.sql @@ -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 diff --git a/src/Sql/dbo/Stored Procedures/CipherDetails_ReadByIdUserId.sql b/src/Sql/dbo/Stored Procedures/CipherDetails_ReadByIdUserId.sql index 450b9c2312..61a4b6ec9e 100644 --- a/src/Sql/dbo/Stored Procedures/CipherDetails_ReadByIdUserId.sql +++ b/src/Sql/dbo/Stored Procedures/CipherDetails_ReadByIdUserId.sql @@ -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 \ No newline at end of file diff --git a/src/Sql/dbo/Stored Procedures/CipherDetails_ReadByTypeUserId.sql b/src/Sql/dbo/Stored Procedures/CipherDetails_ReadByTypeUserId.sql index 2193f8b9cb..0c481d0923 100644 --- a/src/Sql/dbo/Stored Procedures/CipherDetails_ReadByTypeUserId.sql +++ b/src/Sql/dbo/Stored Procedures/CipherDetails_ReadByTypeUserId.sql @@ -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 \ No newline at end of file diff --git a/src/Sql/dbo/Stored Procedures/CipherDetails_ReadByUserId.sql b/src/Sql/dbo/Stored Procedures/CipherDetails_ReadByUserId.sql index e6e9ebc9c2..784d715db7 100644 --- a/src/Sql/dbo/Stored Procedures/CipherDetails_ReadByUserId.sql +++ b/src/Sql/dbo/Stored Procedures/CipherDetails_ReadByUserId.sql @@ -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 \ No newline at end of file diff --git a/src/Sql/dbo/Stored Procedures/CipherDetails_ReadByUserIdHasCollection.sql b/src/Sql/dbo/Stored Procedures/CipherDetails_ReadByUserIdHasCollection.sql index 09186eeae1..d959743324 100644 --- a/src/Sql/dbo/Stored Procedures/CipherDetails_ReadByUserIdHasCollection.sql +++ b/src/Sql/dbo/Stored Procedures/CipherDetails_ReadByUserIdHasCollection.sql @@ -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 \ No newline at end of file diff --git a/src/Sql/dbo/Stored Procedures/CipherFullDetails_ReadByIdUserId.sql b/src/Sql/dbo/Stored Procedures/CipherFullDetails_ReadByIdUserId.sql index 11cdcfdea9..3ac0eaefab 100644 --- a/src/Sql/dbo/Stored Procedures/CipherFullDetails_ReadByIdUserId.sql +++ b/src/Sql/dbo/Stored Procedures/CipherFullDetails_ReadByIdUserId.sql @@ -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 \ No newline at end of file diff --git a/src/Sql/dbo/Stored Procedures/Cipher_UpdateWithCollections.sql b/src/Sql/dbo/Stored Procedures/Cipher_UpdateWithCollections.sql index 282a48ee59..6f4d09a7c5 100644 --- a/src/Sql/dbo/Stored Procedures/Cipher_UpdateWithCollections.sql +++ b/src/Sql/dbo/Stored Procedures/Cipher_UpdateWithCollections.sql @@ -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] ( diff --git a/src/Sql/dbo/Stored Procedures/CollectionCipher_ReadByUserId.sql b/src/Sql/dbo/Stored Procedures/CollectionCipher_ReadByUserId.sql index d147a8d2cf..aea1a5541f 100644 --- a/src/Sql/dbo/Stored Procedures/CollectionCipher_ReadByUserId.sql +++ b/src/Sql/dbo/Stored Procedures/CollectionCipher_ReadByUserId.sql @@ -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 \ No newline at end of file diff --git a/src/Sql/dbo/Stored Procedures/CollectionCipher_ReadByUserIdCipherId.sql b/src/Sql/dbo/Stored Procedures/CollectionCipher_ReadByUserIdCipherId.sql index 80466d83cc..c97cf5d9c3 100644 --- a/src/Sql/dbo/Stored Procedures/CollectionCipher_ReadByUserIdCipherId.sql +++ b/src/Sql/dbo/Stored Procedures/CollectionCipher_ReadByUserIdCipherId.sql @@ -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 \ No newline at end of file diff --git a/src/Sql/dbo/Stored Procedures/CollectionCipher_UpdateCollections.sql b/src/Sql/dbo/Stored Procedures/CollectionCipher_UpdateCollections.sql index 3c3bbb1091..3457a2e897 100644 --- a/src/Sql/dbo/Stored Procedures/CollectionCipher_UpdateCollections.sql +++ b/src/Sql/dbo/Stored Procedures/CollectionCipher_UpdateCollections.sql @@ -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] diff --git a/src/Sql/dbo/Stored Procedures/CollectionUserCollectionDetails_ReadByUserId.sql b/src/Sql/dbo/Stored Procedures/CollectionUserCollectionDetails_ReadByUserId.sql index bfcecefb11..31a4630c46 100644 --- a/src/Sql/dbo/Stored Procedures/CollectionUserCollectionDetails_ReadByUserId.sql +++ b/src/Sql/dbo/Stored Procedures/CollectionUserCollectionDetails_ReadByUserId.sql @@ -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 \ No newline at end of file diff --git a/src/Sql/dbo/Stored Procedures/Collection_ReadByUserId.sql b/src/Sql/dbo/Stored Procedures/Collection_ReadByUserId.sql index b95c8de873..bfcae2f71d 100644 --- a/src/Sql/dbo/Stored Procedures/Collection_ReadByUserId.sql +++ b/src/Sql/dbo/Stored Procedures/Collection_ReadByUserId.sql @@ -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 \ No newline at end of file diff --git a/src/Sql/dbo/Stored Procedures/Folder_DeleteById.sql b/src/Sql/dbo/Stored Procedures/Folder_DeleteById.sql index 6a1729aed2..2bdb550220 100644 --- a/src/Sql/dbo/Stored Procedures/Folder_DeleteById.sql +++ b/src/Sql/dbo/Stored Procedures/Folder_DeleteById.sql @@ -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 diff --git a/src/Sql/dbo/Views/CollectionUserCollectionDetailsView.sql b/src/Sql/dbo/Views/CollectionUserCollectionDetailsView.sql index 95fcc1b4ea..df996ac144 100644 --- a/src/Sql/dbo/Views/CollectionUserCollectionDetailsView.sql +++ b/src/Sql/dbo/Views/CollectionUserCollectionDetailsView.sql @@ -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] \ No newline at end of file + [dbo].[Collection] S ON S.[Id] = CU.[CollectionId] \ No newline at end of file diff --git a/src/Sql/dbo/Views/CollectionUserUserDetailsView.sql b/src/Sql/dbo/Views/CollectionUserUserDetailsView.sql index 52f327bb9d..59264112fc 100644 --- a/src/Sql/dbo/Views/CollectionUserUserDetailsView.sql +++ b/src/Sql/dbo/Views/CollectionUserUserDetailsView.sql @@ -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] \ No newline at end of file