mirror of
https://github.com/bitwarden/server.git
synced 2025-05-01 17:52:17 -05:00
Updated seat count logic to ensure that only the correct sponsorships are counted towards the seat count (#5711)
This commit is contained in:
parent
9fdf12e955
commit
7ebf312b84
@ -23,7 +23,19 @@ public class OrganizationUserReadOccupiedSeatCountByOrganizationIdQuery : IQuery
|
|||||||
var sponsorshipsQuery = from os in dbContext.OrganizationSponsorships
|
var sponsorshipsQuery = from os in dbContext.OrganizationSponsorships
|
||||||
where os.SponsoringOrganizationId == _organizationId &&
|
where os.SponsoringOrganizationId == _organizationId &&
|
||||||
os.IsAdminInitiated &&
|
os.IsAdminInitiated &&
|
||||||
!os.ToDelete
|
(
|
||||||
|
// Not marked for deletion - always count
|
||||||
|
(!os.ToDelete) ||
|
||||||
|
// Marked for deletion but has a valid until date in the future (RevokeWhenExpired status)
|
||||||
|
(os.ToDelete && os.ValidUntil.HasValue && os.ValidUntil.Value > DateTime.UtcNow)
|
||||||
|
) &&
|
||||||
|
(
|
||||||
|
// SENT status: When SponsoredOrganizationId is null
|
||||||
|
os.SponsoredOrganizationId == null ||
|
||||||
|
// ACCEPTED status: When SponsoredOrganizationId is not null and ValidUntil is null or in the future
|
||||||
|
(os.SponsoredOrganizationId != null &&
|
||||||
|
(!os.ValidUntil.HasValue || os.ValidUntil.Value > DateTime.UtcNow))
|
||||||
|
)
|
||||||
select new OrganizationUser
|
select new OrganizationUser
|
||||||
{
|
{
|
||||||
Id = os.Id,
|
Id = os.Id,
|
||||||
|
@ -19,5 +19,19 @@ BEGIN
|
|||||||
FROM [dbo].[OrganizationSponsorship]
|
FROM [dbo].[OrganizationSponsorship]
|
||||||
WHERE SponsoringOrganizationId = @OrganizationId
|
WHERE SponsoringOrganizationId = @OrganizationId
|
||||||
AND IsAdminInitiated = 1
|
AND IsAdminInitiated = 1
|
||||||
|
AND (
|
||||||
|
-- Not marked for deletion - always count
|
||||||
|
(ToDelete = 0)
|
||||||
|
OR
|
||||||
|
-- Marked for deletion but has a valid until date in the future (RevokeWhenExpired status)
|
||||||
|
(ToDelete = 1 AND ValidUntil IS NOT NULL AND ValidUntil > GETUTCDATE())
|
||||||
|
)
|
||||||
|
AND (
|
||||||
|
-- SENT status: When SponsoredOrganizationId is null
|
||||||
|
SponsoredOrganizationId IS NULL
|
||||||
|
OR
|
||||||
|
-- ACCEPTED status: When SponsoredOrganizationId is not null and ValidUntil is null or in the future
|
||||||
|
(SponsoredOrganizationId IS NOT NULL AND (ValidUntil IS NULL OR ValidUntil > GETUTCDATE()))
|
||||||
|
)
|
||||||
)
|
)
|
||||||
END
|
END
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
IF OBJECT_ID('[dbo].[OrganizationUser_ReadOccupiedSeatCountByOrganizationId]') IS NOT NULL
|
||||||
|
BEGIN
|
||||||
|
DROP PROCEDURE [dbo].[OrganizationUser_ReadOccupiedSeatCountByOrganizationId]
|
||||||
|
END
|
||||||
|
GO
|
||||||
|
|
||||||
|
CREATE PROCEDURE [dbo].[OrganizationUser_ReadOccupiedSeatCountByOrganizationId]
|
||||||
|
@OrganizationId UNIQUEIDENTIFIER
|
||||||
|
AS
|
||||||
|
BEGIN
|
||||||
|
SET NOCOUNT ON
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
(
|
||||||
|
SELECT COUNT(1)
|
||||||
|
FROM [dbo].[OrganizationUserView]
|
||||||
|
WHERE OrganizationId = @OrganizationId
|
||||||
|
AND Status >= 0 --Invited
|
||||||
|
) +
|
||||||
|
(
|
||||||
|
SELECT COUNT(1)
|
||||||
|
FROM [dbo].[OrganizationSponsorship]
|
||||||
|
WHERE SponsoringOrganizationId = @OrganizationId
|
||||||
|
AND IsAdminInitiated = 1
|
||||||
|
AND (
|
||||||
|
-- Not marked for deletion - always count
|
||||||
|
(ToDelete = 0)
|
||||||
|
OR
|
||||||
|
-- Marked for deletion but has a valid until date in the future (RevokeWhenExpired status)
|
||||||
|
(ToDelete = 1 AND ValidUntil IS NOT NULL AND ValidUntil > GETUTCDATE())
|
||||||
|
)
|
||||||
|
AND (
|
||||||
|
-- SENT status: When SponsoredOrganizationId is null
|
||||||
|
SponsoredOrganizationId IS NULL
|
||||||
|
OR
|
||||||
|
-- ACCEPTED status: When SponsoredOrganizationId is not null and ValidUntil is null or in the future
|
||||||
|
(SponsoredOrganizationId IS NOT NULL AND (ValidUntil IS NULL OR ValidUntil > GETUTCDATE()))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
END
|
||||||
|
GO
|
Loading…
x
Reference in New Issue
Block a user