From 343ef92a2097a731f0695ceb4863f243e3420ad7 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 21 May 2020 11:35:00 -0400 Subject: [PATCH 1/3] Sproc tweaks (#730) * do not follow local hosts or ip addresses * remove cron from mssql * migration script * Use joins instead of temp tables * update migration script with join changes --- .../CollectionUser_UpdateUsers.sql | 75 ++-- .../GroupUser_UpdateGroups.sql | 61 +-- .../GroupUser_UpdateUsers.sql | 59 +-- ...OrganizationUser_UpdateWithCollections.sql | 73 ++-- ...User_BumpAccountRevisionDateByCipherId.sql | 14 +- ..._BumpAccountRevisionDateByCollectionId.sql | 14 +- .../2020-05-02_00_SprocPerfTweaks.sql | 368 ++++++++++++++++++ 7 files changed, 542 insertions(+), 122 deletions(-) create mode 100644 util/Migrator/DbScripts/2020-05-02_00_SprocPerfTweaks.sql diff --git a/src/Sql/dbo/Stored Procedures/CollectionUser_UpdateUsers.sql b/src/Sql/dbo/Stored Procedures/CollectionUser_UpdateUsers.sql index f27e4110ef..fed619aedf 100644 --- a/src/Sql/dbo/Stored Procedures/CollectionUser_UpdateUsers.sql +++ b/src/Sql/dbo/Stored Procedures/CollectionUser_UpdateUsers.sql @@ -14,35 +14,56 @@ BEGIN [Id] = @CollectionId ) - ;WITH [AvailableUsersCTE] AS( - SELECT - Id - FROM - [dbo].[OrganizationUser] - WHERE - OrganizationId = @OrgId - ) - MERGE - [dbo].[CollectionUser] AS [Target] - USING - @Users AS [Source] - ON + -- Update + UPDATE + [Target] + SET + [Target].[ReadOnly] = [Source].[ReadOnly] + FROM + [dbo].[CollectionUser] [Target] + INNER JOIN + @Users [Source] ON [Source].[Id] = [Target].[OrganizationUserId] + WHERE [Target].[CollectionId] = @CollectionId - AND [Target].[OrganizationUserId] = [Source].[Id] - WHEN NOT MATCHED BY TARGET - AND [Source].[Id] IN (SELECT [Id] FROM [AvailableUsersCTE]) THEN - INSERT VALUES - ( - @CollectionId, - [Source].[Id], - [Source].[ReadOnly] + AND [Target].[ReadOnly] != [Source].[ReadOnly] + + -- Insert + INSERT INTO + [dbo].[CollectionUser] + SELECT + @CollectionId, + [Source].[Id], + [Source].[ReadOnly] + FROM + @Users [Source] + INNER JOIN + [dbo].[OrganizationUser] OU ON [Source].[Id] = OU.[Id] AND OU.[OrganizationId] = @OrgId + WHERE + NOT EXISTS ( + SELECT + 1 + FROM + [dbo].[CollectionUser] + WHERE + [CollectionId] = @CollectionId + AND [OrganizationUserId] = [Source].[Id] + ) + + -- Delete + DELETE + CU + FROM + [dbo].[CollectionUser] CU + WHERE + CU.[CollectionId] = @CollectionId + AND NOT EXISTS ( + SELECT + 1 + FROM + @Users + WHERE + [Id] = CU.[OrganizationUserId] ) - WHEN MATCHED AND [Target].[ReadOnly] != [Source].[ReadOnly] THEN - UPDATE SET [Target].[ReadOnly] = [Source].[ReadOnly] - WHEN NOT MATCHED BY SOURCE - AND [Target].[CollectionId] = @CollectionId THEN - DELETE - ; EXEC [dbo].[User_BumpAccountRevisionDateByCollectionId] @CollectionId, @OrgId END \ No newline at end of file diff --git a/src/Sql/dbo/Stored Procedures/GroupUser_UpdateGroups.sql b/src/Sql/dbo/Stored Procedures/GroupUser_UpdateGroups.sql index c977708469..c417d0c4d8 100644 --- a/src/Sql/dbo/Stored Procedures/GroupUser_UpdateGroups.sql +++ b/src/Sql/dbo/Stored Procedures/GroupUser_UpdateGroups.sql @@ -14,33 +14,42 @@ BEGIN [Id] = @OrganizationUserId ) - ;WITH [AvailableGroupsCTE] AS( - SELECT - [Id] - FROM - [dbo].[Group] - WHERE - [OrganizationId] = @OrgId - ) - MERGE - [dbo].[GroupUser] AS [Target] - USING - @GroupIds AS [Source] - ON - [Target].[GroupId] = [Source].[Id] - AND [Target].[OrganizationUserId] = @OrganizationUserId - WHEN NOT MATCHED BY TARGET - AND [Source].[Id] IN (SELECT [Id] FROM [AvailableGroupsCTE]) THEN - INSERT VALUES - ( - [Source].[Id], - @OrganizationUserId + -- Insert + INSERT INTO + [dbo].[GroupUser] + SELECT + [Source].[Id], + @OrganizationUserId + FROM + @GroupIds [Source] + INNER JOIN + [dbo].[Group] G ON G.[Id] = [Source].[Id] AND G.[OrganizationId] = @OrgId + WHERE + NOT EXISTS ( + SELECT + 1 + FROM + [dbo].[GroupUser] + WHERE + [OrganizationUserId] = @OrganizationUserId + AND [GroupId] = [Source].[Id] + ) + + -- Delete + DELETE + GU + FROM + [dbo].[GroupUser] GU + WHERE + GU.[OrganizationUserId] = @OrganizationUserId + AND NOT EXISTS ( + SELECT + 1 + FROM + @GroupIds + WHERE + [Id] = GU.[GroupId] ) - WHEN NOT MATCHED BY SOURCE - AND [Target].[OrganizationUserId] = @OrganizationUserId - AND [Target].[GroupId] IN (SELECT [Id] FROM [AvailableGroupsCTE]) THEN - DELETE - ; EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationUserId] @OrganizationUserId END \ No newline at end of file diff --git a/src/Sql/dbo/Stored Procedures/GroupUser_UpdateUsers.sql b/src/Sql/dbo/Stored Procedures/GroupUser_UpdateUsers.sql index 1e41def02d..750d3fe9ce 100644 --- a/src/Sql/dbo/Stored Procedures/GroupUser_UpdateUsers.sql +++ b/src/Sql/dbo/Stored Procedures/GroupUser_UpdateUsers.sql @@ -14,33 +14,42 @@ BEGIN [Id] = @GroupId ) - ;WITH [AvailableUsersCTE] AS( - SELECT - [Id] - FROM - [dbo].[OrganizationUser] - WHERE - [OrganizationId] = @OrgId - ) - MERGE - [dbo].[GroupUser] AS [Target] - USING + -- Insert + INSERT INTO + [dbo].[GroupUser] + SELECT + @GroupId, + [Source].[Id] + FROM @OrganizationUserIds AS [Source] - ON - [Target].[GroupId] = @GroupId - AND [Target].[OrganizationUserId] = [Source].[Id] - WHEN NOT MATCHED BY TARGET - AND [Source].[Id] IN (SELECT [Id] FROM [AvailableUsersCTE]) THEN - INSERT VALUES - ( - @GroupId, - [Source].[Id] + INNER JOIN + [dbo].[OrganizationUser] OU ON [Source].[Id] = OU.[Id] AND OU.[OrganizationId] = @OrgId + WHERE + NOT EXISTS ( + SELECT + 1 + FROM + [dbo].[GroupUser] + WHERE + [GroupId] = @GroupId + AND [OrganizationUserId] = [Source].[Id] + ) + + -- Delete + DELETE + GU + FROM + [dbo].[GroupUser] GU + WHERE + GU.[GroupId] = @GroupId + AND NOT EXISTS ( + SELECT + 1 + FROM + @OrganizationUserIds + WHERE + [Id] = GU.[OrganizationUserId] ) - WHEN NOT MATCHED BY SOURCE - AND [Target].[GroupId] = @GroupId - AND [Target].[OrganizationUserId] IN (SELECT [Id] FROM [AvailableUsersCTE]) THEN - DELETE - ; EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrgId END \ No newline at end of file diff --git a/src/Sql/dbo/Stored Procedures/OrganizationUser_UpdateWithCollections.sql b/src/Sql/dbo/Stored Procedures/OrganizationUser_UpdateWithCollections.sql index b35d688775..d351752fb2 100644 --- a/src/Sql/dbo/Stored Procedures/OrganizationUser_UpdateWithCollections.sql +++ b/src/Sql/dbo/Stored Procedures/OrganizationUser_UpdateWithCollections.sql @@ -17,33 +17,54 @@ BEGIN EXEC [dbo].[OrganizationUser_Update] @Id, @OrganizationId, @UserId, @Email, @Key, @Status, @Type, @AccessAll, @ExternalId, @CreationDate, @RevisionDate - ;WITH [AvailableCollectionsCTE] AS( - SELECT - Id - FROM - [dbo].[Collection] - WHERE - OrganizationId = @OrganizationId - ) - MERGE + -- Update + UPDATE + [Target] + SET + [Target].[ReadOnly] = [Source].[ReadOnly] + FROM [dbo].[CollectionUser] AS [Target] - USING + INNER JOIN + @Collections AS [Source] ON [Source].[Id] = [Target].[CollectionId] + WHERE + [Target].[OrganizationUserId] = @Id + AND [Target].[ReadOnly] != [Source].[ReadOnly] + + -- Insert + INSERT INTO + [dbo].[CollectionUser] + SELECT + [Source].[Id], + @Id, + [Source].[ReadOnly] + FROM @Collections AS [Source] - ON - [Target].[CollectionId] = [Source].[Id] - AND [Target].[OrganizationUserId] = @Id - WHEN NOT MATCHED BY TARGET - AND [Source].[Id] IN (SELECT [Id] FROM [AvailableCollectionsCTE]) THEN - INSERT VALUES - ( - [Source].[Id], - @Id, - [Source].[ReadOnly] + INNER JOIN + [dbo].[Collection] C ON C.[Id] = [Source].[Id] AND C.[OrganizationId] = @OrganizationId + WHERE + NOT EXISTS ( + SELECT + 1 + FROM + [dbo].[CollectionUser] + WHERE + [CollectionId] = [Source].[Id] + AND [OrganizationUserId] = @Id + ) + + -- Delete + DELETE + CU + FROM + [dbo].[CollectionUser] CU + WHERE + CU.[OrganizationUserId] = @Id + AND NOT EXISTS ( + SELECT + 1 + FROM + @Collections + WHERE + [Id] = CU.[CollectionId] ) - WHEN MATCHED AND [Target].[ReadOnly] != [Source].[ReadOnly] THEN - UPDATE SET [Target].[ReadOnly] = [Source].[ReadOnly] - WHEN NOT MATCHED BY SOURCE - AND [Target].[OrganizationUserId] = @Id THEN - DELETE - ; END \ No newline at end of file diff --git a/src/Sql/dbo/Stored Procedures/User_BumpAccountRevisionDateByCipherId.sql b/src/Sql/dbo/Stored Procedures/User_BumpAccountRevisionDateByCipherId.sql index 53a12ed6e0..5b96db54a9 100644 --- a/src/Sql/dbo/Stored Procedures/User_BumpAccountRevisionDateByCipherId.sql +++ b/src/Sql/dbo/Stored Procedures/User_BumpAccountRevisionDateByCipherId.sql @@ -11,7 +11,7 @@ BEGIN U.[AccountRevisionDate] = GETUTCDATE() FROM [dbo].[User] U - LEFT JOIN + INNER JOIN [dbo].[OrganizationUser] OU ON OU.[UserId] = U.[Id] LEFT JOIN [dbo].[CollectionCipher] CC ON CC.[CipherId] = @CipherId @@ -24,16 +24,12 @@ BEGIN LEFT JOIN [dbo].[CollectionGroup] CG ON G.[AccessAll] = 0 AND CG.[GroupId] = GU.[GroupId] AND CG.[CollectionId] = CC.[CollectionId] WHERE - OU.[Status] = 2 -- 2 = Confirmed + OU.[OrganizationId] = @OrganizationId + AND OU.[Status] = 2 -- 2 = Confirmed AND ( CU.[CollectionId] IS NOT NULL OR CG.[CollectionId] IS NOT NULL - OR ( - OU.[OrganizationId] = @OrganizationId - AND ( - OU.[AccessAll] = 1 - OR G.[AccessAll] = 1 - ) - ) + OR OU.[AccessAll] = 1 + OR G.[AccessAll] = 1 ) END diff --git a/src/Sql/dbo/Stored Procedures/User_BumpAccountRevisionDateByCollectionId.sql b/src/Sql/dbo/Stored Procedures/User_BumpAccountRevisionDateByCollectionId.sql index 0300fd2c8a..f001a54cdb 100644 --- a/src/Sql/dbo/Stored Procedures/User_BumpAccountRevisionDateByCollectionId.sql +++ b/src/Sql/dbo/Stored Procedures/User_BumpAccountRevisionDateByCollectionId.sql @@ -11,7 +11,7 @@ BEGIN U.[AccountRevisionDate] = GETUTCDATE() FROM [dbo].[User] U - LEFT JOIN + INNER JOIN [dbo].[OrganizationUser] OU ON OU.[UserId] = U.[Id] LEFT JOIN [dbo].[CollectionUser] CU ON OU.[AccessAll] = 0 AND CU.[OrganizationUserId] = OU.[Id] AND CU.[CollectionId] = @CollectionId @@ -22,16 +22,12 @@ BEGIN LEFT JOIN [dbo].[CollectionGroup] CG ON G.[AccessAll] = 0 AND CG.[GroupId] = GU.[GroupId] AND CG.[CollectionId] = @CollectionId WHERE - OU.[Status] = 2 -- 2 = Confirmed + OU.[OrganizationId] = @OrganizationId + AND OU.[Status] = 2 -- 2 = Confirmed AND ( CU.[CollectionId] IS NOT NULL OR CG.[CollectionId] IS NOT NULL - OR ( - OU.[OrganizationId] = @OrganizationId - AND ( - OU.[AccessAll] = 1 - OR G.[AccessAll] = 1 - ) - ) + OR OU.[AccessAll] = 1 + OR G.[AccessAll] = 1 ) END diff --git a/util/Migrator/DbScripts/2020-05-02_00_SprocPerfTweaks.sql b/util/Migrator/DbScripts/2020-05-02_00_SprocPerfTweaks.sql new file mode 100644 index 0000000000..a0f662bbf2 --- /dev/null +++ b/util/Migrator/DbScripts/2020-05-02_00_SprocPerfTweaks.sql @@ -0,0 +1,368 @@ +/** + * Performance updates to various sprocs + */ + +IF OBJECT_ID('[dbo].[CollectionUser_UpdateUsers]') IS NOT NULL +BEGIN + DROP PROCEDURE [dbo].[CollectionUser_UpdateUsers]; +END +GO + +CREATE PROCEDURE [dbo].[CollectionUser_UpdateUsers] + @CollectionId UNIQUEIDENTIFIER, + @Users AS [dbo].[SelectionReadOnlyArray] READONLY +AS +BEGIN + SET NOCOUNT ON + + DECLARE @OrgId UNIQUEIDENTIFIER = ( + SELECT TOP 1 + [OrganizationId] + FROM + [dbo].[Collection] + WHERE + [Id] = @CollectionId + ) + + -- Update + UPDATE + [Target] + SET + [Target].[ReadOnly] = [Source].[ReadOnly] + FROM + [dbo].[CollectionUser] [Target] + INNER JOIN + @Users [Source] ON [Source].[Id] = [Target].[OrganizationUserId] + WHERE + [Target].[CollectionId] = @CollectionId + AND [Target].[ReadOnly] != [Source].[ReadOnly] + + -- Insert + INSERT INTO + [dbo].[CollectionUser] + SELECT + @CollectionId, + [Source].[Id], + [Source].[ReadOnly] + FROM + @Users [Source] + INNER JOIN + [dbo].[OrganizationUser] OU ON [Source].[Id] = OU.[Id] AND OU.[OrganizationId] = @OrgId + WHERE + NOT EXISTS ( + SELECT + 1 + FROM + [dbo].[CollectionUser] + WHERE + [CollectionId] = @CollectionId + AND [OrganizationUserId] = [Source].[Id] + ) + + -- Delete + DELETE + CU + FROM + [dbo].[CollectionUser] CU + WHERE + CU.[CollectionId] = @CollectionId + AND NOT EXISTS ( + SELECT + 1 + FROM + @Users + WHERE + [Id] = CU.[OrganizationUserId] + ) + + EXEC [dbo].[User_BumpAccountRevisionDateByCollectionId] @CollectionId, @OrgId +END +GO + +IF OBJECT_ID('[dbo].[GroupUser_UpdateGroups]') IS NOT NULL +BEGIN + DROP PROCEDURE [dbo].[GroupUser_UpdateGroups]; +END +GO + +CREATE PROCEDURE [dbo].[GroupUser_UpdateGroups] + @OrganizationUserId UNIQUEIDENTIFIER, + @GroupIds AS [dbo].[GuidIdArray] READONLY +AS +BEGIN + SET NOCOUNT ON + + DECLARE @OrgId UNIQUEIDENTIFIER = ( + SELECT TOP 1 + [OrganizationId] + FROM + [dbo].[OrganizationUser] + WHERE + [Id] = @OrganizationUserId + ) + + -- Insert + INSERT INTO + [dbo].[GroupUser] + SELECT + [Source].[Id], + @OrganizationUserId + FROM + @GroupIds [Source] + INNER JOIN + [dbo].[Group] G ON G.[Id] = [Source].[Id] AND G.[OrganizationId] = @OrgId + WHERE + NOT EXISTS ( + SELECT + 1 + FROM + [dbo].[GroupUser] + WHERE + [OrganizationUserId] = @OrganizationUserId + AND [GroupId] = [Source].[Id] + ) + + -- Delete + DELETE + GU + FROM + [dbo].[GroupUser] GU + WHERE + GU.[OrganizationUserId] = @OrganizationUserId + AND NOT EXISTS ( + SELECT + 1 + FROM + @GroupIds + WHERE + [Id] = GU.[GroupId] + ) + + EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationUserId] @OrganizationUserId +END +GO + +IF OBJECT_ID('[dbo].[GroupUser_UpdateUsers]') IS NOT NULL +BEGIN + DROP PROCEDURE [dbo].[GroupUser_UpdateUsers]; +END +GO + +CREATE PROCEDURE [dbo].[GroupUser_UpdateUsers] + @GroupId UNIQUEIDENTIFIER, + @OrganizationUserIds AS [dbo].[GuidIdArray] READONLY +AS +BEGIN + SET NOCOUNT ON + + DECLARE @OrgId UNIQUEIDENTIFIER = ( + SELECT TOP 1 + [OrganizationId] + FROM + [dbo].[Group] + WHERE + [Id] = @GroupId + ) + + -- Insert + INSERT INTO + [dbo].[GroupUser] + SELECT + @GroupId, + [Source].[Id] + FROM + @OrganizationUserIds AS [Source] + INNER JOIN + [dbo].[OrganizationUser] OU ON [Source].[Id] = OU.[Id] AND OU.[OrganizationId] = @OrgId + WHERE + NOT EXISTS ( + SELECT + 1 + FROM + [dbo].[GroupUser] + WHERE + [GroupId] = @GroupId + AND [OrganizationUserId] = [Source].[Id] + ) + + -- Delete + DELETE + GU + FROM + [dbo].[GroupUser] GU + WHERE + GU.[GroupId] = @GroupId + AND NOT EXISTS ( + SELECT + 1 + FROM + @OrganizationUserIds + WHERE + [Id] = GU.[OrganizationUserId] + ) + + EXEC [dbo].[User_BumpAccountRevisionDateByOrganizationId] @OrgId +END +GO + +IF OBJECT_ID('[dbo].[OrganizationUser_UpdateWithCollections]') IS NOT NULL +BEGIN + DROP PROCEDURE [dbo].[OrganizationUser_UpdateWithCollections]; +END +GO + +CREATE PROCEDURE [dbo].[OrganizationUser_UpdateWithCollections] + @Id UNIQUEIDENTIFIER, + @OrganizationId UNIQUEIDENTIFIER, + @UserId UNIQUEIDENTIFIER, + @Email NVARCHAR(50), + @Key VARCHAR(MAX), + @Status TINYINT, + @Type TINYINT, + @AccessAll BIT, + @ExternalId NVARCHAR(300), + @CreationDate DATETIME2(7), + @RevisionDate DATETIME2(7), + @Collections AS [dbo].[SelectionReadOnlyArray] READONLY +AS +BEGIN + SET NOCOUNT ON + + EXEC [dbo].[OrganizationUser_Update] @Id, @OrganizationId, @UserId, @Email, @Key, @Status, @Type, @AccessAll, @ExternalId, @CreationDate, @RevisionDate + + -- Update + UPDATE + [Target] + SET + [Target].[ReadOnly] = [Source].[ReadOnly] + FROM + [dbo].[CollectionUser] AS [Target] + INNER JOIN + @Collections AS [Source] ON [Source].[Id] = [Target].[CollectionId] + WHERE + [Target].[OrganizationUserId] = @Id + AND [Target].[ReadOnly] != [Source].[ReadOnly] + + -- Insert + INSERT INTO + [dbo].[CollectionUser] + SELECT + [Source].[Id], + @Id, + [Source].[ReadOnly] + FROM + @Collections AS [Source] + INNER JOIN + [dbo].[Collection] C ON C.[Id] = [Source].[Id] AND C.[OrganizationId] = @OrganizationId + WHERE + NOT EXISTS ( + SELECT + 1 + FROM + [dbo].[CollectionUser] + WHERE + [CollectionId] = [Source].[Id] + AND [OrganizationUserId] = @Id + ) + + -- Delete + DELETE + CU + FROM + [dbo].[CollectionUser] CU + WHERE + CU.[OrganizationUserId] = @Id + AND NOT EXISTS ( + SELECT + 1 + FROM + @Collections + WHERE + [Id] = CU.[CollectionId] + ) +END +GO + +IF OBJECT_ID('[dbo].[User_BumpAccountRevisionDateByCipherId]') IS NOT NULL +BEGIN + DROP PROCEDURE [dbo].[User_BumpAccountRevisionDateByCipherId]; +END +GO + +CREATE PROCEDURE [dbo].[User_BumpAccountRevisionDateByCipherId] + @CipherId UNIQUEIDENTIFIER, + @OrganizationId UNIQUEIDENTIFIER +AS +BEGIN + SET NOCOUNT ON + + UPDATE + U + SET + U.[AccountRevisionDate] = GETUTCDATE() + FROM + [dbo].[User] U + INNER JOIN + [dbo].[OrganizationUser] OU ON OU.[UserId] = U.[Id] + LEFT JOIN + [dbo].[CollectionCipher] CC ON CC.[CipherId] = @CipherId + LEFT JOIN + [dbo].[CollectionUser] CU ON OU.[AccessAll] = 0 AND CU.[OrganizationUserId] = OU.[Id] AND CU.[CollectionId] = CC.[CollectionId] + 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] AND CG.[CollectionId] = CC.[CollectionId] + WHERE + OU.[OrganizationId] = @OrganizationId + AND OU.[Status] = 2 -- 2 = Confirmed + AND ( + CU.[CollectionId] IS NOT NULL + OR CG.[CollectionId] IS NOT NULL + OR OU.[AccessAll] = 1 + OR G.[AccessAll] = 1 + ) +END +GO + +IF OBJECT_ID('[dbo].[User_BumpAccountRevisionDateByCollectionId]') IS NOT NULL +BEGIN + DROP PROCEDURE [dbo].[User_BumpAccountRevisionDateByCollectionId]; +END +GO + +CREATE PROCEDURE [dbo].[User_BumpAccountRevisionDateByCollectionId] + @CollectionId UNIQUEIDENTIFIER, + @OrganizationId UNIQUEIDENTIFIER +AS +BEGIN + SET NOCOUNT ON + + UPDATE + U + SET + U.[AccountRevisionDate] = GETUTCDATE() + FROM + [dbo].[User] U + INNER JOIN + [dbo].[OrganizationUser] OU ON OU.[UserId] = U.[Id] + LEFT JOIN + [dbo].[CollectionUser] CU ON OU.[AccessAll] = 0 AND CU.[OrganizationUserId] = OU.[Id] AND CU.[CollectionId] = @CollectionId + 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] AND CG.[CollectionId] = @CollectionId + WHERE + OU.[OrganizationId] = @OrganizationId + AND OU.[Status] = 2 -- 2 = Confirmed + AND ( + CU.[CollectionId] IS NOT NULL + OR CG.[CollectionId] IS NOT NULL + OR OU.[AccessAll] = 1 + OR G.[AccessAll] = 1 + ) +END +GO From beb40eb682f601d9cf0898b76f49d2cfbe685bcc Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 21 May 2020 15:00:03 -0400 Subject: [PATCH 2/3] Update swagger config to use proper URL scheme (#744) --- appveyor.yml | 2 +- src/Api/Startup.cs | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 7981595e44..0cad53a1f8 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -86,7 +86,7 @@ build_script: $env:swaggerGen = "true" $env:ASPNETCORE_ENVIRONMENT = "Production" cd .\src\Api - dotnet swagger tofile --output ..\..\swagger.json --host api.bitwarden.com ` + dotnet swagger tofile --output ..\..\swagger.json --host https://api.bitwarden.com ` .\bin\Debug\netcoreapp3.1\Api.dll public cd ..\.. $env:ASPNETCORE_ENVIRONMENT = "" diff --git a/src/Api/Startup.cs b/src/Api/Startup.cs index 15e7879eba..868d0e500a 100644 --- a/src/Api/Startup.cs +++ b/src/Api/Startup.cs @@ -188,12 +188,10 @@ namespace Bit.Api app.UseSwagger(config => { config.RouteTemplate = "specs/{documentName}/swagger.json"; - var host = globalSettings.BaseServiceUri.Api.Replace("https://", string.Empty) - .Replace("http://", string.Empty); config.PreSerializeFilters.Add((swaggerDoc, httpReq) => swaggerDoc.Servers = new List { - new OpenApiServer { Url = $"{httpReq.Scheme}://{host}" } + new OpenApiServer { Url = globalSettings.BaseServiceUri.Api } }); }); app.UseSwaggerUI(config => From 4b776f94134b5b43e03d4e4f72ff96eedd7206b2 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 22 May 2020 10:16:51 -0400 Subject: [PATCH 3/3] bump docker version --- scripts/bitwarden.ps1 | 4 ++-- scripts/bitwarden.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/bitwarden.ps1 b/scripts/bitwarden.ps1 index 605b810a33..9949c57636 100644 --- a/scripts/bitwarden.ps1 +++ b/scripts/bitwarden.ps1 @@ -23,8 +23,8 @@ if ($output -eq "") { $scriptsDir = "${output}\scripts" $githubBaseUrl = "https://raw.githubusercontent.com/bitwarden/server/master" -$coreVersion = "1.33.1" -$webVersion = "2.13.2" +$coreVersion = "1.34.0" +$webVersion = "2.14.0" # Functions diff --git a/scripts/bitwarden.sh b/scripts/bitwarden.sh index 92ee08a067..b2ddfca2a9 100755 --- a/scripts/bitwarden.sh +++ b/scripts/bitwarden.sh @@ -37,8 +37,8 @@ fi SCRIPTS_DIR="$OUTPUT/scripts" GITHUB_BASE_URL="https://raw.githubusercontent.com/bitwarden/server/master" -COREVERSION="1.33.1" -WEBVERSION="2.13.2" +COREVERSION="1.34.0" +WEBVERSION="2.14.0" # Functions