From be146a8f626565c9823a12c9e9bd203f3500dcc5 Mon Sep 17 00:00:00 2001 From: Jake Fink Date: Sun, 17 Jul 2022 20:28:46 -0400 Subject: [PATCH] update OrgUserDetailsView to include PlanType and other sponsorship parameters previously removed (#2122) --- ...izationUserOrganizationDetailsViewQuery.cs | 5 +- ...rganizationUserOrganizationDetailsView.sql | 9 ++- .../2022-07-15_00_FixOrgUserDetails.sql | 62 +++++++++++++++++++ 3 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 util/Migrator/DbScripts/2022-07-15_00_FixOrgUserDetails.sql diff --git a/src/Infrastructure.EntityFramework/Repositories/Queries/OrganizationUserOrganizationDetailsViewQuery.cs b/src/Infrastructure.EntityFramework/Repositories/Queries/OrganizationUserOrganizationDetailsViewQuery.cs index f39bb6218d..cd01229702 100644 --- a/src/Infrastructure.EntityFramework/Repositories/Queries/OrganizationUserOrganizationDetailsViewQuery.cs +++ b/src/Infrastructure.EntityFramework/Repositories/Queries/OrganizationUserOrganizationDetailsViewQuery.cs @@ -54,8 +54,11 @@ namespace Bit.Infrastructure.EntityFramework.Repositories.Queries PrivateKey = x.o.PrivateKey, ProviderId = x.p.Id, ProviderName = x.p.Name, - FamilySponsorshipFriendlyName = x.os.FriendlyName, SsoConfig = x.ss.Data, + FamilySponsorshipFriendlyName = x.os.FriendlyName, + FamilySponsorshipLastSyncDate = x.os.LastSyncDate, + FamilySponsorshipToDelete = x.os.ToDelete, + FamilySponsorshipValidUntil = x.os.ValidUntil }); } } diff --git a/src/Sql/dbo/Views/OrganizationUserOrganizationDetailsView.sql b/src/Sql/dbo/Views/OrganizationUserOrganizationDetailsView.sql index b990a45691..01f327b085 100644 --- a/src/Sql/dbo/Views/OrganizationUserOrganizationDetailsView.sql +++ b/src/Sql/dbo/Views/OrganizationUserOrganizationDetailsView.sql @@ -5,6 +5,7 @@ SELECT OU.[OrganizationId], O.[Name], O.[Enabled], + O.[PlanType], O.[UsePolicies], O.[UseSso], O.[UseKeyConnector], @@ -32,7 +33,11 @@ SELECT OU.[Permissions], PO.[ProviderId], P.[Name] ProviderName, - SS.[Data] SsoConfig + SS.[Data] SsoConfig, + OS.[FriendlyName] FamilySponsorshipFriendlyName, + OS.[LastSyncDate] FamilySponsorshipLastSyncDate, + OS.[ToDelete] FamilySponsorshipToDelete, + OS.[ValidUntil] FamilySponsorshipValidUntil FROM [dbo].[OrganizationUser] OU INNER JOIN @@ -45,3 +50,5 @@ LEFT JOIN [dbo].[Provider] P ON P.[Id] = PO.[ProviderId] LEFT JOIN [dbo].[SsoConfig] SS ON SS.[OrganizationId] = OU.[OrganizationId] +LEFT JOIN + [dbo].[OrganizationSponsorship] OS ON OS.[SponsoringOrganizationUserID] = OU.[Id] diff --git a/util/Migrator/DbScripts/2022-07-15_00_FixOrgUserDetails.sql b/util/Migrator/DbScripts/2022-07-15_00_FixOrgUserDetails.sql new file mode 100644 index 0000000000..a5c3b1aff5 --- /dev/null +++ b/util/Migrator/DbScripts/2022-07-15_00_FixOrgUserDetails.sql @@ -0,0 +1,62 @@ + +IF EXISTS(SELECT * FROM sys.views WHERE [Name] = 'OrganizationUserOrganizationDetailsView') + BEGIN + DROP VIEW [dbo].[OrganizationUserOrganizationDetailsView] + END +GO + +CREATE VIEW [dbo].[OrganizationUserOrganizationDetailsView] +AS +SELECT + OU.[UserId], + OU.[OrganizationId], + O.[Name], + O.[Enabled], + O.[PlanType], + O.[UsePolicies], + O.[UseSso], + O.[UseKeyConnector], + O.[UseScim], + O.[UseGroups], + O.[UseDirectory], + O.[UseEvents], + O.[UseTotp], + O.[Use2fa], + O.[UseApi], + O.[UseResetPassword], + O.[SelfHost], + O.[UsersGetPremium], + O.[Seats], + O.[MaxCollections], + O.[MaxStorageGb], + O.[Identifier], + OU.[Key], + OU.[ResetPasswordKey], + O.[PublicKey], + O.[PrivateKey], + OU.[Status], + OU.[Type], + SU.[ExternalId] SsoExternalId, + OU.[Permissions], + PO.[ProviderId], + P.[Name] ProviderName, + SS.[Data] SsoConfig, + OS.[FriendlyName] FamilySponsorshipFriendlyName, + OS.[LastSyncDate] FamilySponsorshipLastSyncDate, + OS.[ToDelete] FamilySponsorshipToDelete, + OS.[ValidUntil] FamilySponsorshipValidUntil +FROM + [dbo].[OrganizationUser] OU +LEFT JOIN + [dbo].[Organization] O ON O.[Id] = OU.[OrganizationId] +LEFT JOIN + [dbo].[SsoUser] SU ON SU.[UserId] = OU.[UserId] AND SU.[OrganizationId] = OU.[OrganizationId] +LEFT JOIN + [dbo].[ProviderOrganization] PO ON PO.[OrganizationId] = O.[Id] +LEFT JOIN + [dbo].[Provider] P ON P.[Id] = PO.[ProviderId] +LEFT JOIN + [dbo].[SsoConfig] SS ON SS.[OrganizationId] = OU.[OrganizationId] +LEFT JOIN + [dbo].[OrganizationSponsorship] OS ON OS.[SponsoringOrganizationUserID] = OU.[Id] +GO