1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-05 05:00:19 -05:00

[AC-2805] Add AssignedSeats to ProviderOrganizationOrganizationDetailsView (#4446)

* Add 'AssignedSeats' to ProviderOrganizationOrganizationDetailsView

* Add newline

* Thomas' feedback
This commit is contained in:
Alex Morask 2024-07-03 10:33:37 -04:00 committed by GitHub
parent ef44def88b
commit 07d37b1b41
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 32 additions and 3 deletions

View File

@ -42,6 +42,8 @@ public class ProviderOrganizationResponseModel : ResponseModel
RevisionDate = providerOrganization.RevisionDate; RevisionDate = providerOrganization.RevisionDate;
UserCount = providerOrganization.UserCount; UserCount = providerOrganization.UserCount;
Seats = providerOrganization.Seats; Seats = providerOrganization.Seats;
OccupiedSeats = providerOrganization.OccupiedSeats;
RemainingSeats = providerOrganization.Seats - providerOrganization.OccupiedSeats;
Plan = providerOrganization.Plan; Plan = providerOrganization.Plan;
} }
@ -54,6 +56,8 @@ public class ProviderOrganizationResponseModel : ResponseModel
public DateTime RevisionDate { get; set; } public DateTime RevisionDate { get; set; }
public int UserCount { get; set; } public int UserCount { get; set; }
public int? Seats { get; set; } public int? Seats { get; set; }
public int? OccupiedSeats { get; set; }
public int? RemainingSeats { get; set; }
public string Plan { get; set; } public string Plan { get; set; }
} }

View File

@ -79,7 +79,7 @@ public class ProviderEventService(
ClientName = client.OrganizationName, ClientName = client.OrganizationName,
PlanName = client.Plan, PlanName = client.Plan,
AssignedSeats = client.Seats ?? 0, AssignedSeats = client.Seats ?? 0,
UsedSeats = client.UserCount, UsedSeats = client.OccupiedSeats ?? 0,
Total = client.Plan == enterprisePlan.Name Total = client.Plan == enterprisePlan.Name
? (client.Seats ?? 0) * discountedEnterpriseSeatPrice ? (client.Seats ?? 0) * discountedEnterpriseSeatPrice
: (client.Seats ?? 0) * discountedTeamsSeatPrice : (client.Seats ?? 0) * discountedTeamsSeatPrice

View File

@ -20,6 +20,7 @@ public class ProviderOrganizationOrganizationDetails
public DateTime CreationDate { get; set; } public DateTime CreationDate { get; set; }
public DateTime RevisionDate { get; set; } public DateTime RevisionDate { get; set; }
public int UserCount { get; set; } public int UserCount { get; set; }
public int? OccupiedSeats { get; set; }
public int? Seats { get; set; } public int? Seats { get; set; }
public string Plan { get; set; } public string Plan { get; set; }
public OrganizationStatusType Status { get; set; } public OrganizationStatusType Status { get; set; }

View File

@ -32,6 +32,7 @@ public class ProviderOrganizationOrganizationDetailsReadByProviderIdQuery : IQue
CreationDate = x.po.CreationDate, CreationDate = x.po.CreationDate,
RevisionDate = x.po.RevisionDate, RevisionDate = x.po.RevisionDate,
UserCount = x.o.OrganizationUsers.Count(ou => ou.Status == Core.Enums.OrganizationUserStatusType.Confirmed), UserCount = x.o.OrganizationUsers.Count(ou => ou.Status == Core.Enums.OrganizationUserStatusType.Confirmed),
OccupiedSeats = x.o.OrganizationUsers.Count(ou => ou.Status >= 0),
Seats = x.o.Seats, Seats = x.o.Seats,
Plan = x.o.Plan, Plan = x.o.Plan,
Status = x.o.Status Status = x.o.Status

View File

@ -10,6 +10,7 @@ SELECT
PO.[CreationDate], PO.[CreationDate],
PO.[RevisionDate], PO.[RevisionDate],
(SELECT COUNT(1) FROM [dbo].[OrganizationUser] OU WHERE OU.OrganizationId = PO.OrganizationId AND OU.Status = 2) UserCount, (SELECT COUNT(1) FROM [dbo].[OrganizationUser] OU WHERE OU.OrganizationId = PO.OrganizationId AND OU.Status = 2) UserCount,
(SELECT COUNT(1) FROM [dbo].[OrganizationUser] OU WHERE OU.OrganizationId = PO.OrganizationId AND OU.Status >= 0) OccupiedSeats,
O.[Seats], O.[Seats],
O.[Plan], O.[Plan],
O.[Status] O.[Status]

View File

@ -176,7 +176,7 @@ public class ProviderEventServiceTests
OrganizationName = "Client 1", OrganizationName = "Client 1",
Plan = "Teams (Monthly)", Plan = "Teams (Monthly)",
Seats = 50, Seats = 50,
UserCount = 30, OccupiedSeats = 30,
Status = OrganizationStatusType.Managed Status = OrganizationStatusType.Managed
}, },
new () new ()
@ -184,7 +184,7 @@ public class ProviderEventServiceTests
OrganizationName = "Client 2", OrganizationName = "Client 2",
Plan = "Enterprise (Monthly)", Plan = "Enterprise (Monthly)",
Seats = 50, Seats = 50,
UserCount = 30, OccupiedSeats = 30,
Status = OrganizationStatusType.Managed Status = OrganizationStatusType.Managed
} }
}; };

View File

@ -0,0 +1,22 @@
-- Add column 'AssignedSeats'
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,
(SELECT COUNT(1) FROM [dbo].[OrganizationUser] OU WHERE OU.OrganizationId = PO.OrganizationId AND OU.Status >= 0) OccupiedSeats,
O.[Seats],
O.[Plan],
O.[Status]
FROM
[dbo].[ProviderOrganization] PO
LEFT JOIN
[dbo].[Organization] O ON O.[Id] = PO.[OrganizationId]
GO