Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: seat count calculation in plan detail resolver #418

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading