From 169a4381dd00a063b84d31cd3f764a0b12ccfa50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rui=20Tom=C3=A9?= <108268980+r-tome@users.noreply.github.com> Date: Thu, 28 Jul 2022 09:31:03 +0100 Subject: [PATCH] [EC-247] Add columns to provider portal clients table (#2136) * Added migration script to alter ProviderOrganizationOrganizationDetailsView to add new columns UserCount, Seats and Plan * Modified EF query ProviderOrganizationOrganizationDetailsReadByProviderIdQuery * Modified model to output new view columns * Updated view to count only active users * Filtering the organization user count by only confirmed users --- .../ProviderOrganizationResponseModel.cs | 6 ++++++ ...ProviderOrganizationOrganizationDetails.cs | 3 +++ ...rganizationDetailsReadByProviderIdQuery.cs | 5 +++++ ...-20_00_ProviderOrganizationListDetails.sql | 20 +++++++++++++++++++ 4 files changed, 34 insertions(+) create mode 100644 util/Migrator/DbScripts/2022-07-20_00_ProviderOrganizationListDetails.sql diff --git a/src/Api/Models/Response/Providers/ProviderOrganizationResponseModel.cs b/src/Api/Models/Response/Providers/ProviderOrganizationResponseModel.cs index fa03562a7e..e508787a08 100644 --- a/src/Api/Models/Response/Providers/ProviderOrganizationResponseModel.cs +++ b/src/Api/Models/Response/Providers/ProviderOrganizationResponseModel.cs @@ -38,6 +38,9 @@ namespace Bit.Api.Models.Response.Providers Settings = providerOrganization.Settings; CreationDate = providerOrganization.CreationDate; RevisionDate = providerOrganization.RevisionDate; + UserCount = providerOrganization.UserCount; + Seats = providerOrganization.Seats; + Plan = providerOrganization.Plan; } public Guid Id { get; set; } @@ -47,6 +50,9 @@ namespace Bit.Api.Models.Response.Providers public string Settings { get; set; } public DateTime CreationDate { get; set; } public DateTime RevisionDate { get; set; } + public int UserCount { get; set; } + public int? Seats { get; set; } + public string Plan { get; set; } } public class ProviderOrganizationOrganizationDetailsResponseModel : ProviderOrganizationResponseModel diff --git a/src/Core/Models/Data/Provider/ProviderOrganizationOrganizationDetails.cs b/src/Core/Models/Data/Provider/ProviderOrganizationOrganizationDetails.cs index ed05846716..279994df4b 100644 --- a/src/Core/Models/Data/Provider/ProviderOrganizationOrganizationDetails.cs +++ b/src/Core/Models/Data/Provider/ProviderOrganizationOrganizationDetails.cs @@ -10,5 +10,8 @@ public string Settings { get; set; } public DateTime CreationDate { get; set; } public DateTime RevisionDate { get; set; } + public int UserCount { get; set; } + public int? Seats { get; set; } + public string Plan { get; set; } } } diff --git a/src/Infrastructure.EntityFramework/Repositories/Queries/ProviderOrganizationOrganizationDetailsReadByProviderIdQuery.cs b/src/Infrastructure.EntityFramework/Repositories/Queries/ProviderOrganizationOrganizationDetailsReadByProviderIdQuery.cs index e73215ffd2..03ada03c34 100644 --- a/src/Infrastructure.EntityFramework/Repositories/Queries/ProviderOrganizationOrganizationDetailsReadByProviderIdQuery.cs +++ b/src/Infrastructure.EntityFramework/Repositories/Queries/ProviderOrganizationOrganizationDetailsReadByProviderIdQuery.cs @@ -15,6 +15,8 @@ namespace Bit.Infrastructure.EntityFramework.Repositories.Queries var query = from po in dbContext.ProviderOrganizations join o in dbContext.Organizations on po.OrganizationId equals o.Id + join ou in dbContext.OrganizationUsers + on po.OrganizationId equals ou.OrganizationId where po.ProviderId == _providerId select new { po, o }; return query.Select(x => new ProviderOrganizationOrganizationDetails() @@ -27,6 +29,9 @@ namespace Bit.Infrastructure.EntityFramework.Repositories.Queries Settings = x.po.Settings, CreationDate = x.po.CreationDate, RevisionDate = x.po.RevisionDate, + UserCount = x.o.OrganizationUsers.Count(ou => ou.Status == Core.Enums.OrganizationUserStatusType.Confirmed), + Seats = x.o.Seats, + Plan = x.o.Plan }); } } diff --git a/util/Migrator/DbScripts/2022-07-20_00_ProviderOrganizationListDetails.sql b/util/Migrator/DbScripts/2022-07-20_00_ProviderOrganizationListDetails.sql new file mode 100644 index 0000000000..5ea9da1cab --- /dev/null +++ b/util/Migrator/DbScripts/2022-07-20_00_ProviderOrganizationListDetails.sql @@ -0,0 +1,20 @@ +-- Add columns 'UserCount', 'Seats' and 'Plan' +CREATE OR ALTER VIEW [dbo].[ProviderOrganizationOrganizationDetailsView] +AS +SELECT + PO.[Id], + PO.[ProviderId], + PO.[OrganizationId], + O.[Name] OrganizationName, + PO.[Key], + PO.[Settings], + PO.[CreationDate], + PO.[RevisionDate], + (SELECT COUNT(1) FROM [dbo].[OrganizationUser] OU WHERE OU.OrganizationId = PO.OrganizationId AND OU.Status = 2) UserCount, + O.[Seats], + O.[Plan] +FROM + [dbo].[ProviderOrganization] PO +LEFT JOIN + [dbo].[Organization] O ON O.[Id] = PO.[OrganizationId] +GO