billing: Set message_visibility_limit to 10000 for Limited.

This commit is contained in:
Vishnu Ks 2018-10-17 14:20:59 +05:30 committed by Tim Abbott
parent f90f701f03
commit cc8dd0e971
3 changed files with 30 additions and 7 deletions

View File

@ -3088,11 +3088,14 @@ def do_change_plan_type(user: UserProfile, plan_type: int) -> None:
if plan_type == Realm.STANDARD:
realm.max_invites = Realm.INVITES_STANDARD_REALM_DAILY_MAX
realm.message_visibility_limit = None
elif plan_type == Realm.STANDARD_FREE:
realm.max_invites = Realm.INVITES_STANDARD_REALM_DAILY_MAX
realm.message_visibility_limit = None
elif plan_type == Realm.LIMITED:
realm.max_invites = settings.INVITES_DEFAULT_REALM_DAILY_MAX
realm.save(update_fields=['_max_invites'])
realm.message_visibility_limit = Realm.MESSAGE_VISIBILITY_LIMITED
realm.save(update_fields=['_max_invites', 'message_visibility_limit'])
def do_change_default_sending_stream(user_profile: UserProfile, stream: Optional[Stream],
log: bool=True) -> None:
@ -3272,6 +3275,7 @@ def do_create_realm(string_id: str, name: str,
kwargs['emails_restricted_to_domains'] = emails_restricted_to_domains
if settings.BILLING_ENABLED:
kwargs['plan_type'] = Realm.LIMITED
kwargs['message_visibility_limit'] = Realm.MESSAGE_VISIBILITY_LIMITED
realm = Realm(string_id=string_id, name=name, **kwargs)
realm.save()

View File

@ -144,6 +144,7 @@ class Realm(models.Model):
MAX_VIDEO_CHAT_PROVIDER_LENGTH = 40
MAX_GOOGLE_HANGOUTS_DOMAIN_LENGTH = 255 # This is just the maximum domain length by RFC
INVITES_STANDARD_REALM_DAILY_MAX = 3000
MESSAGE_VISIBILITY_LIMITED = 10000
VIDEO_CHAT_PROVIDERS = [u"Jitsi", u"Google Hangouts"]
AUTHENTICATION_FLAGS = [u'Google', u'Email', u'GitHub', u'LDAP', u'Dev', u'RemoteUser']
SUBDOMAIN_FOR_ROOT_DOMAIN = ''

View File

@ -6,6 +6,7 @@ import mock
from django.conf import settings
from django.http import HttpResponse
from django.conf import settings
from mock import patch
from typing import Any, Dict, List, Union, Mapping
@ -344,19 +345,36 @@ class RealmTest(ZulipTestCase):
def test_initial_plan_type(self) -> None:
with self.settings(BILLING_ENABLED=True):
self.assertEqual(Realm.LIMITED, do_create_realm('hosted', 'hosted').plan_type)
self.assertEqual(do_create_realm('hosted', 'hosted').plan_type, Realm.LIMITED)
self.assertEqual(get_realm("hosted").max_invites, settings.INVITES_DEFAULT_REALM_DAILY_MAX)
self.assertEqual(get_realm("hosted").message_visibility_limit, Realm.MESSAGE_VISIBILITY_LIMITED)
with self.settings(BILLING_ENABLED=False):
self.assertEqual(Realm.SELF_HOSTED, do_create_realm('onpremise', 'onpremise').plan_type)
self.assertEqual(do_create_realm('onpremise', 'onpremise').plan_type, Realm.SELF_HOSTED)
self.assertEqual(get_realm('onpremise').max_invites, settings.INVITES_DEFAULT_REALM_DAILY_MAX)
self.assertEqual(get_realm('onpremise').message_visibility_limit, None)
def test_change_plan_type(self) -> None:
user = self.example_user('iago')
self.assertEqual(get_realm('zulip').max_invites, settings.INVITES_DEFAULT_REALM_DAILY_MAX)
realm = get_realm('zulip')
self.assertEqual(realm.plan_type, Realm.SELF_HOSTED)
self.assertEqual(realm.max_invites, settings.INVITES_DEFAULT_REALM_DAILY_MAX)
self.assertEqual(realm.message_visibility_limit, None)
do_change_plan_type(user, Realm.STANDARD)
self.assertEqual(get_realm('zulip').max_invites, Realm.INVITES_STANDARD_REALM_DAILY_MAX)
realm = get_realm('zulip')
self.assertEqual(realm.max_invites, Realm.INVITES_STANDARD_REALM_DAILY_MAX)
self.assertEqual(realm.message_visibility_limit, None)
do_change_plan_type(user, Realm.LIMITED)
self.assertEqual(get_realm('zulip').max_invites, settings.INVITES_DEFAULT_REALM_DAILY_MAX)
realm = get_realm('zulip')
self.assertEqual(realm.max_invites, settings.INVITES_DEFAULT_REALM_DAILY_MAX)
self.assertEqual(realm.message_visibility_limit, Realm.MESSAGE_VISIBILITY_LIMITED)
do_change_plan_type(user, Realm.STANDARD_FREE)
self.assertEqual(get_realm('zulip').max_invites, Realm.INVITES_STANDARD_REALM_DAILY_MAX)
realm = get_realm('zulip')
self.assertEqual(realm.max_invites, Realm.INVITES_STANDARD_REALM_DAILY_MAX)
self.assertEqual(realm.message_visibility_limit, None)
class RealmAPITest(ZulipTestCase):