From 7cefa15c8d1b12456fad97d85368c5377fe1cd6c Mon Sep 17 00:00:00 2001 From: Shane Melton Date: Mon, 10 Jul 2023 15:48:58 -0700 Subject: [PATCH] [AC-1487] Update queries to use [User] table instead of [OrganizationUser] for email address --- .../AuthRequest_ReadAdminApprovalsByIds.sql | 4 +- ...uthRequest_ReadPendingByOrganizationId.sql | 4 +- ...2023-07-10_00_FixTdeAdminApprovalEmail.sql | 46 +++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 util/Migrator/DbScripts/2023-07-10_00_FixTdeAdminApprovalEmail.sql diff --git a/src/Sql/Auth/dbo/Stored Procedures/AuthRequest_ReadAdminApprovalsByIds.sql b/src/Sql/Auth/dbo/Stored Procedures/AuthRequest_ReadAdminApprovalsByIds.sql index 6aff36431836..74515f9d3807 100644 --- a/src/Sql/Auth/dbo/Stored Procedures/AuthRequest_ReadAdminApprovalsByIds.sql +++ b/src/Sql/Auth/dbo/Stored Procedures/AuthRequest_ReadAdminApprovalsByIds.sql @@ -6,11 +6,13 @@ BEGIN SET NOCOUNT ON SELECT - ar.*, ou.[Email], ou.[Id] AS [OrganizationUserId] + ar.*, u.[Email], ou.[Id] AS [OrganizationUserId] FROM [dbo].[AuthRequestView] ar INNER JOIN [dbo].[OrganizationUser] ou ON ou.[UserId] = ar.[UserId] AND ou.[OrganizationId] = ar.[OrganizationId] + INNER JOIN + [dbo].[User] u ON u.[Id] = ar.[UserId] WHERE ar.[OrganizationId] = @OrganizationId AND diff --git a/src/Sql/Auth/dbo/Stored Procedures/AuthRequest_ReadPendingByOrganizationId.sql b/src/Sql/Auth/dbo/Stored Procedures/AuthRequest_ReadPendingByOrganizationId.sql index d3a2f8c581ff..56c1d1f15c29 100644 --- a/src/Sql/Auth/dbo/Stored Procedures/AuthRequest_ReadPendingByOrganizationId.sql +++ b/src/Sql/Auth/dbo/Stored Procedures/AuthRequest_ReadPendingByOrganizationId.sql @@ -5,11 +5,13 @@ BEGIN SET NOCOUNT ON SELECT - ar.*, ou.[Email], ou.[OrganizationId], ou.[Id] AS [OrganizationUserId] + ar.*, u.[Email], ou.[Id] AS [OrganizationUserId] FROM [dbo].[AuthRequestView] ar INNER JOIN [dbo].[OrganizationUser] ou ON ou.[UserId] = ar.[UserId] AND ou.[OrganizationId] = ar.[OrganizationId] + INNER JOIN + [dbo].[User] u ON u.[Id] = ar.[UserId] WHERE ar.[OrganizationId] = @OrganizationId AND diff --git a/util/Migrator/DbScripts/2023-07-10_00_FixTdeAdminApprovalEmail.sql b/util/Migrator/DbScripts/2023-07-10_00_FixTdeAdminApprovalEmail.sql new file mode 100644 index 000000000000..e2aec0ecaa7e --- /dev/null +++ b/util/Migrator/DbScripts/2023-07-10_00_FixTdeAdminApprovalEmail.sql @@ -0,0 +1,46 @@ +CREATE OR ALTER PROCEDURE [dbo].[AuthRequest_ReadAdminApprovalsByIds] + @OrganizationId UNIQUEIDENTIFIER, + @Ids AS [dbo].[GuidIdArray] READONLY +AS +BEGIN + SET NOCOUNT ON + +SELECT + ar.*, u.[Email], ou.[Id] AS [OrganizationUserId] +FROM + [dbo].[AuthRequestView] ar + INNER JOIN + [dbo].[OrganizationUser] ou ON ou.[UserId] = ar.[UserId] AND ou.[OrganizationId] = ar.[OrganizationId] + INNER JOIN + [dbo].[User] u ON u.[Id] = ar.[UserId] + WHERE + ar.[OrganizationId] = @OrganizationId + AND + ar.[Type] = 2 -- AdminApproval + AND + ar.[Id] IN (SELECT [Id] FROM @Ids) +END +GO + +CREATE OR ALTER PROCEDURE [dbo].[AuthRequest_ReadPendingByOrganizationId] + @OrganizationId UNIQUEIDENTIFIER +AS +BEGIN + SET NOCOUNT ON + +SELECT + ar.*, u.[Email], ou.[Id] AS [OrganizationUserId] +FROM + [dbo].[AuthRequestView] ar + INNER JOIN + [dbo].[OrganizationUser] ou ON ou.[UserId] = ar.[UserId] AND ou.[OrganizationId] = ar.[OrganizationId] + INNER JOIN + [dbo].[User] u ON u.[Id] = ar.[UserId] + WHERE + ar.[OrganizationId] = @OrganizationId + AND + ar.[ResponseDate] IS NULL + AND + ar.[Type] = 2 -- AdminApproval +END +GO \ No newline at end of file