Skip to content

Commit

Permalink
fix: seat count calculation in plan detail resolver (#418)
Browse files Browse the repository at this point in the history
  • Loading branch information
rohan-chaturvedi authored Dec 17, 2024
1 parent 537a577 commit d0d8808
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions backend/backend/graphene/queries/quotas.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
from api.utils.access.permissions import user_is_org_member
from api.models import App, Organisation, OrganisationMember, OrganisationMemberInvite
from api.models import (
App,
Organisation,
OrganisationMember,
OrganisationMemberInvite,
ServiceAccount,
)
from backend.quotas import PLAN_CONFIG
from django.utils import timezone

Expand All @@ -11,13 +17,24 @@ def resolve_organisation_plan(self, info, organisation_id):

plan = PLAN_CONFIG[organisation.plan]

plan["user_count"] = (
OrganisationMember.objects.filter(
plan["seats_used"] = {
"users": (
OrganisationMember.objects.filter(
organisation=organisation, deleted_at=None
).count()
+ OrganisationMemberInvite.objects.filter(
organisation=organisation,
valid=True,
expires_at__gte=timezone.now(),
).count()
),
"service_accounts": ServiceAccount.objects.filter(
organisation=organisation, deleted_at=None
).count()
+ OrganisationMemberInvite.objects.filter(
organisation=organisation, valid=True, expires_at__gte=timezone.now()
).count()
).count(),
}

plan["seats_used"]["total"] = (
plan["seats_used"]["users"] + plan["seats_used"]["service_accounts"]
)

plan["app_count"] = App.objects.filter(
Expand Down

0 comments on commit d0d8808

Please sign in to comment.