From 1d3092b6b27abdcdc59e364dfc9ec8b420ed57e4 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 16 Mar 2017 23:14:02 -0400 Subject: [PATCH] subvault information sprocs --- src/Sql/Sql.sqlproj | 2 ++ .../Cipher_ReadByUserIdHasSubvault.sql | 19 +++++++++++++++++++ .../SubvaultCipher_ReadByUserId.sql | 17 +++++++++++++++++ .../Subvault_ReadByIdAdminUserId.sql | 11 +++++------ 4 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 src/Sql/dbo/Stored Procedures/Cipher_ReadByUserIdHasSubvault.sql create mode 100644 src/Sql/dbo/Stored Procedures/SubvaultCipher_ReadByUserId.sql diff --git a/src/Sql/Sql.sqlproj b/src/Sql/Sql.sqlproj index f2d93b662..84592c2a5 100644 --- a/src/Sql/Sql.sqlproj +++ b/src/Sql/Sql.sqlproj @@ -159,5 +159,7 @@ + + \ No newline at end of file diff --git a/src/Sql/dbo/Stored Procedures/Cipher_ReadByUserIdHasSubvault.sql b/src/Sql/dbo/Stored Procedures/Cipher_ReadByUserIdHasSubvault.sql new file mode 100644 index 000000000..592bd7184 --- /dev/null +++ b/src/Sql/dbo/Stored Procedures/Cipher_ReadByUserIdHasSubvault.sql @@ -0,0 +1,19 @@ +CREATE PROCEDURE [dbo].[Cipher_ReadByUserIdHasSubvault] + @UserId UNIQUEIDENTIFIER +AS +BEGIN + SET NOCOUNT ON + + SELECT DISTINCT + C.* + FROM + [dbo].[CipherView] C + INNER JOIN + [dbo].[SubvaultCipher] SC ON SC.[CipherId] = C.[Id] + INNER JOIN + [dbo].[SubvaultUser] SU ON SU.[SubvaultId] = SC.[SubvaultId] + INNER JOIN + [dbo].[OrganizationUser] OU ON OU.[Id] = SU.[OrganizationUserId] + WHERE + [OU].[UserId] = @UserId +END \ No newline at end of file diff --git a/src/Sql/dbo/Stored Procedures/SubvaultCipher_ReadByUserId.sql b/src/Sql/dbo/Stored Procedures/SubvaultCipher_ReadByUserId.sql new file mode 100644 index 000000000..0efcb1c39 --- /dev/null +++ b/src/Sql/dbo/Stored Procedures/SubvaultCipher_ReadByUserId.sql @@ -0,0 +1,17 @@ +CREATE PROCEDURE [dbo].[SubvaultCipher_ReadByUserId] + @UserId UNIQUEIDENTIFIER +AS +BEGIN + SET NOCOUNT ON + + SELECT + SC.* + FROM + [dbo].[SubvaultCipher] SC + INNER JOIN + [dbo].[SubvaultUser] SU ON SU.[SubvaultId] = SC.[SubvaultId] + INNER JOIN + [dbo].[OrganizationUser] OU ON OU.[Id] = SU.[OrganizationUserId] + WHERE + [OU].[UserId] = @UserId +END \ No newline at end of file diff --git a/src/Sql/dbo/Stored Procedures/Subvault_ReadByIdAdminUserId.sql b/src/Sql/dbo/Stored Procedures/Subvault_ReadByIdAdminUserId.sql index 23658d760..6111d2ad8 100644 --- a/src/Sql/dbo/Stored Procedures/Subvault_ReadByIdAdminUserId.sql +++ b/src/Sql/dbo/Stored Procedures/Subvault_ReadByIdAdminUserId.sql @@ -1,5 +1,4 @@ -CREATE PROCEDURE [dbo].[Subvault_ReadByIdAdminUserId] - @Id UNIQUEIDENTIFIER, +CREATE PROCEDURE [dbo].[Subvault_ReadByUserId] @UserId UNIQUEIDENTIFIER AS BEGIN @@ -10,9 +9,9 @@ BEGIN FROM [dbo].[SubvaultView] S INNER JOIN - [OrganizationUser] OU ON OU.[OrganizationId] = S.[OrganizationId] + [SubvaultUser] SU ON SU.[SubvaultId] = S.[Id] + INNER JOIN + [OrganizationUser] OU ON OU.[Id] = SU.[OrganizationUserId] WHERE - S.[Id] = @Id - AND OU.[UserId] = @UserId - AND OU.[Type] <= 1 -- Owner and admin + OU.[UserId] = @UserId END \ No newline at end of file