billing: Remove references to Realm.has_seat_based_plan.

This commit is contained in:
Rishi Gupta 2018-12-24 00:59:52 -08:00
parent 7c38300949
commit 955dfc6397
3 changed files with 6 additions and 47 deletions

View File

@ -19,8 +19,7 @@ from django.utils.timezone import utc as timezone_utc
import stripe
from zerver.lib.actions import do_deactivate_user, do_create_user, \
do_activate_user, do_reactivate_user, activity_change_requires_seat_update, \
do_create_realm
do_activate_user, do_reactivate_user, do_create_realm
from zerver.lib.test_classes import ZulipTestCase
from zerver.lib.timestamp import timestamp_to_datetime, datetime_to_timestamp
from zerver.models import Realm, UserProfile, get_realm, RealmAuditLog
@ -784,40 +783,6 @@ class StripeTest(ZulipTestCase):
self.assertEqual(number_of_sources, 1)
self.assertFalse(RealmAuditLog.objects.filter(event_type=RealmAuditLog.STRIPE_CARD_CHANGED).exists())
class RequiresBillingUpdateTest(ZulipTestCase):
def test_activity_change_requires_seat_update(self) -> None:
# Realm doesn't have a seat based plan
self.assertFalse(activity_change_requires_seat_update(self.example_user("hamlet")))
realm = get_realm("zulip")
realm.has_seat_based_plan = True
realm.save(update_fields=['has_seat_based_plan'])
# seat based plan + user not a bot
user = self.example_user("hamlet")
self.assertTrue(activity_change_requires_seat_update(user))
user.is_bot = True
user.save(update_fields=['is_bot'])
# seat based plan but user is a bot
self.assertFalse(activity_change_requires_seat_update(user))
def test_requires_billing_update_for_is_active_changes(self) -> None:
count = RealmAuditLog.objects.count()
realm = get_realm("zulip")
user1 = do_create_user('user1@zulip.com', 'password', realm, 'full name', 'short name')
do_deactivate_user(user1)
do_reactivate_user(user1)
# Not a proper use of do_activate_user, but it's fine to call it like this for this test
do_activate_user(user1)
self.assertEqual(count + 4,
RealmAuditLog.objects.filter(requires_billing_update=False).count())
realm.has_seat_based_plan = True
realm.save(update_fields=['has_seat_based_plan'])
user2 = do_create_user('user2@zulip.com', 'password', realm, 'full name', 'short name')
do_deactivate_user(user2)
do_reactivate_user(user2)
do_activate_user(user2)
self.assertEqual(4, RealmAuditLog.objects.filter(requires_billing_update=True).count())
class RequiresBillingAccessTest(ZulipTestCase):
def setUp(self) -> None:
hamlet = self.example_user("hamlet")

View File

@ -224,9 +224,6 @@ def bot_owner_user_ids(user_profile: UserProfile) -> Set[int]:
def realm_user_count(realm: Realm) -> int:
return UserProfile.objects.filter(realm=realm, is_active=True, is_bot=False).count()
def activity_change_requires_seat_update(user: UserProfile) -> bool:
return user.realm.has_seat_based_plan and not user.is_bot
def send_signup_message(sender: UserProfile, admin_realm_signup_notifications_stream: str,
user_profile: UserProfile, internal: bool=False,
realm: Optional[Realm]=None) -> None:
@ -482,8 +479,7 @@ def do_create_user(email: str, password: Optional[str], realm: Realm, full_name:
event_time = user_profile.date_joined
RealmAuditLog.objects.create(realm=user_profile.realm, modified_user=user_profile,
event_type=RealmAuditLog.USER_CREATED, event_time=event_time,
requires_billing_update=activity_change_requires_seat_update(user_profile))
event_type=RealmAuditLog.USER_CREATED, event_time=event_time)
do_increment_logging_stat(user_profile.realm, COUNT_STATS['active_users_log:is_bot:day'],
user_profile.is_bot, event_time)
@ -508,8 +504,7 @@ def do_activate_user(user_profile: UserProfile) -> None:
event_time = user_profile.date_joined
RealmAuditLog.objects.create(realm=user_profile.realm, modified_user=user_profile,
event_type=RealmAuditLog.USER_ACTIVATED, event_time=event_time,
requires_billing_update=activity_change_requires_seat_update(user_profile))
event_type=RealmAuditLog.USER_ACTIVATED, event_time=event_time)
do_increment_logging_stat(user_profile.realm, COUNT_STATS['active_users_log:is_bot:day'],
user_profile.is_bot, event_time)
@ -524,8 +519,7 @@ def do_reactivate_user(user_profile: UserProfile, acting_user: Optional[UserProf
event_time = timezone_now()
RealmAuditLog.objects.create(realm=user_profile.realm, modified_user=user_profile,
event_type=RealmAuditLog.USER_REACTIVATED, event_time=event_time,
acting_user=acting_user,
requires_billing_update=activity_change_requires_seat_update(user_profile))
acting_user=acting_user)
do_increment_logging_stat(user_profile.realm, COUNT_STATS['active_users_log:is_bot:day'],
user_profile.is_bot, event_time)
@ -701,8 +695,7 @@ def do_deactivate_user(user_profile: UserProfile,
event_time = timezone_now()
RealmAuditLog.objects.create(realm=user_profile.realm, modified_user=user_profile,
acting_user=acting_user,
event_type=RealmAuditLog.USER_DEACTIVATED, event_time=event_time,
requires_billing_update=activity_change_requires_seat_update(user_profile))
event_type=RealmAuditLog.USER_DEACTIVATED, event_time=event_time)
do_increment_logging_stat(user_profile.realm, COUNT_STATS['active_users_log:is_bot:day'],
user_profile.is_bot, event_time, increment=-1)

View File

@ -319,6 +319,7 @@ class Realm(models.Model):
BOT_CREATION_ADMINS_ONLY,
]
# Both of these fields are legacy, and will be removed after a manual migration.
has_seat_based_plan = models.BooleanField(default=False) # type: bool
seat_limit = models.PositiveIntegerField(null=True) # type: Optional[int]