mirror of https://github.com/zulip/zulip.git
billing: Update get_seat_count to incorporate guests.
This commit is contained in:
parent
db6e6472b1
commit
a37558b021
|
@ -2,6 +2,7 @@ from datetime import datetime
|
|||
from decimal import Decimal
|
||||
from functools import wraps
|
||||
import logging
|
||||
import math
|
||||
import os
|
||||
from typing import Any, Callable, Dict, Optional, TypeVar, Tuple, cast
|
||||
import ujson
|
||||
|
@ -39,7 +40,11 @@ MIN_INVOICED_LICENSES = 30
|
|||
DEFAULT_INVOICE_DAYS_UNTIL_DUE = 30
|
||||
|
||||
def get_seat_count(realm: Realm) -> int:
|
||||
return UserProfile.objects.filter(realm=realm, is_active=True, is_bot=False).count()
|
||||
non_guests = UserProfile.objects.filter(
|
||||
realm=realm, is_active=True, is_bot=False, is_guest=False).count()
|
||||
guests = UserProfile.objects.filter(
|
||||
realm=realm, is_active=True, is_bot=False, is_guest=True).count()
|
||||
return max(non_guests, math.ceil(guests / 5))
|
||||
|
||||
def sign_string(string: str) -> Tuple[str, str]:
|
||||
salt = generate_random_token(64)
|
||||
|
|
|
@ -735,6 +735,21 @@ class StripeTest(StripeTestCase):
|
|||
do_deactivate_user(user2)
|
||||
self.assertEqual(get_seat_count(realm), initial_count)
|
||||
|
||||
# Test guests
|
||||
# Adding a guest to a realm with a lot of members shouldn't change anything
|
||||
UserProfile.objects.create(realm=realm, email='user3@zulip.com', pointer=-1, is_guest=True)
|
||||
self.assertEqual(get_seat_count(realm), initial_count)
|
||||
# Test 1 member and 5 guests
|
||||
realm = Realm.objects.create(string_id='second', name='second')
|
||||
UserProfile.objects.create(realm=realm, email='member@second.com', pointer=-1)
|
||||
for i in range(5):
|
||||
UserProfile.objects.create(realm=realm, email='guest{}@second.com'.format(i),
|
||||
pointer=-1, is_guest=True)
|
||||
self.assertEqual(get_seat_count(realm), 1)
|
||||
# Test 1 member and 6 guests
|
||||
UserProfile.objects.create(realm=realm, email='guest5@second.com', pointer=-1, is_guest=True)
|
||||
self.assertEqual(get_seat_count(realm), 2)
|
||||
|
||||
def test_sign_string(self) -> None:
|
||||
string = "abc"
|
||||
signed_string, salt = sign_string(string)
|
||||
|
|
Loading…
Reference in New Issue