Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
invites: _max_invites is currently never None.
Alex Vandiver36da7783ce5d
diff --git a/analytics/tests/test_counts.py b/analytics/tests/test_counts.pyindex ecea422b1a3..07266644050 100644--- a/analytics/tests/test_counts.py+++ b/analytics/tests/test_counts.py@@ -1382,26 +1382,30 @@ class TestLoggingCountStats(AnalyticsTestCase):stream, _ = self.create_stream_with_recipient()invite_expires_in_minutes = 2 * 24 * 60- do_invite_users(- user,- ["[email protected]", "[email protected]"],- [stream],- invite_expires_in_minutes=invite_expires_in_minutes,- )+ with mock.patch("zerver.actions.invites.apply_invite_realm_heuristics"):+ do_invite_users(+ user,+ ["[email protected]", "[email protected]"],+ [stream],+ invite_expires_in_minutes=invite_expires_in_minutes,+ )assertInviteCountEquals(2)# We currently send emails when re-inviting users that haven't# turned into accounts, so count them towards the total- do_invite_users(- user,- ["[email protected]", "[email protected]"],- [stream],- invite_expires_in_minutes=invite_expires_in_minutes,- )+ with mock.patch("zerver.actions.invites.apply_invite_realm_heuristics"):+ do_invite_users(+ user,+ ["[email protected]", "[email protected]"],+ [stream],+ invite_expires_in_minutes=invite_expires_in_minutes,+ )assertInviteCountEquals(4)# Test mix of good and malformed invite emails- with self.assertRaises(InvitationError):+ with self.assertRaises(InvitationError), mock.patch(+ "zerver.actions.invites.apply_invite_realm_heuristics"+ ):do_invite_users(user,["[email protected]", "malformed"],@@ -1411,7 +1415,9 @@ class TestLoggingCountStats(AnalyticsTestCase):assertInviteCountEquals(4)# Test inviting existing users- with self.assertRaises(InvitationError):+ with self.assertRaises(InvitationError), mock.patch(+ "zerver.actions.invites.apply_invite_realm_heuristics"+ ):do_invite_users(user,["[email protected]", "[email protected]"],@@ -1427,7 +1433,8 @@ class TestLoggingCountStats(AnalyticsTestCase):assertInviteCountEquals(5)# Resending invite should cost you- do_resend_user_invite_email(assert_is_not_none(PreregistrationUser.objects.first()))+ with mock.patch("zerver.actions.invites.apply_invite_realm_heuristics"):+ do_resend_user_invite_email(assert_is_not_none(PreregistrationUser.objects.first()))assertInviteCountEquals(6)def test_messages_read_hour(self) -> None:diff --git a/zerver/actions/invites.py b/zerver/actions/invites.pyindex fb322dde5f2..2c97f3dc786 100644--- a/zerver/actions/invites.py+++ b/zerver/actions/invites.py@@ -82,10 +82,10 @@ def estimate_recent_invites(realms: Collection[Realm], *, days: int) -> int:return recent_invites-def apply_invite_realm_heuristics(realm: Realm) -> None:+def apply_invite_realm_heuristics(realm: Realm, recent_invites: int, num_invitees: int) -> None:if realm.plan_type != Realm.PLAN_TYPE_LIMITED:return- if realm._max_invites is not None:+ if realm.max_invites != settings.INVITES_DEFAULT_REALM_DAILY_MAX:return# If they're a non-paid plan with default invitation limits,@@ -160,7 +160,7 @@ def check_invite_limit(realm: Realm, num_invitees: int) -> None:daily_limit_reached=True,)- apply_invite_realm_heuristics(realm)+ apply_invite_realm_heuristics(realm, recent_invites, num_invitees)default_max = settings.INVITES_DEFAULT_REALM_DAILY_MAXnewrealm_age = datetime.timedelta(days=settings.INVITES_NEW_REALM_DAYS)