From 4cb189fc63f2df819c436430651453cd1791a5a7 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Mon, 6 Dec 2021 17:23:24 -0800 Subject: [PATCH] settings: Rename TOS_VERSION to TERMS_OF_SERVICE_VERSION. The previous version was appropriate in a setting where it was only used for Zulip Cloud, but it's definitely clearer to spell it out. --- zerver/lib/actions.py | 4 ++-- zerver/management/commands/send_custom_email.py | 2 +- zerver/models.py | 2 +- zerver/tests/test_audit_log.py | 2 +- zerver/tests/test_home.py | 6 ++++-- zerver/views/home.py | 6 +++--- zerver/views/registration.py | 2 +- zilencer/management/commands/populate_db.py | 10 +++++++--- zproject/default_settings.py | 4 ++-- 9 files changed, 22 insertions(+), 16 deletions(-) diff --git a/zerver/lib/actions.py b/zerver/lib/actions.py index fbd0316a68..4574bbe1c2 100644 --- a/zerver/lib/actions.py +++ b/zerver/lib/actions.py @@ -745,7 +745,7 @@ def do_activate_mirror_dummy_user( user_profile.is_mirror_dummy = False user_profile.set_unusable_password() user_profile.date_joined = timezone_now() - user_profile.tos_version = settings.TOS_VERSION + user_profile.tos_version = settings.TERMS_OF_SERVICE_VERSION user_profile.save( update_fields=["date_joined", "password", "is_mirror_dummy", "tos_version"] ) @@ -4438,7 +4438,7 @@ def do_change_tos_version(user_profile: UserProfile, tos_version: str) -> None: realm=user_profile.realm, acting_user=user_profile, modified_user=user_profile, - event_type=RealmAuditLog.USER_TOS_VERSION_CHANGED, + event_type=RealmAuditLog.USER_TERMS_OF_SERVICE_VERSION_CHANGED, event_time=event_time, ) diff --git a/zerver/management/commands/send_custom_email.py b/zerver/management/commands/send_custom_email.py index 91596ca1ca..0b0bdcf08a 100644 --- a/zerver/management/commands/send_custom_email.py +++ b/zerver/management/commands/send_custom_email.py @@ -106,7 +106,7 @@ class Command(ZulipBaseCommand): raise error # Only email users who've agreed to the terms of service. - if settings.TOS_VERSION is not None: + if settings.TERMS_OF_SERVICE_VERSION is not None: # We need to do a new query because the `get_users` path # passes us a list rather than a QuerySet. users = ( diff --git a/zerver/models.py b/zerver/models.py index 6db8776be7..3e7deee120 100644 --- a/zerver/models.py +++ b/zerver/models.py @@ -3846,7 +3846,7 @@ class AbstractRealmAuditLog(models.Model): USER_AVATAR_SOURCE_CHANGED = 123 USER_FULL_NAME_CHANGED = 124 USER_EMAIL_CHANGED = 125 - USER_TOS_VERSION_CHANGED = 126 + USER_TERMS_OF_SERVICE_VERSION_CHANGED = 126 USER_API_KEY_CHANGED = 127 USER_BOT_OWNER_CHANGED = 128 USER_DEFAULT_SENDING_STREAM_CHANGED = 129 diff --git a/zerver/tests/test_audit_log.py b/zerver/tests/test_audit_log.py index afc5f1b2c7..8988d1d3ec 100644 --- a/zerver/tests/test_audit_log.py +++ b/zerver/tests/test_audit_log.py @@ -221,7 +221,7 @@ class TestRealmAuditLog(ZulipTestCase): do_change_tos_version(user, tos_version) self.assertEqual( RealmAuditLog.objects.filter( - event_type=RealmAuditLog.USER_TOS_VERSION_CHANGED, event_time__gte=now + event_type=RealmAuditLog.USER_TERMS_OF_SERVICE_VERSION_CHANGED, event_time__gte=now ).count(), 1, ) diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.py index c6bac88235..aeb16a37e4 100644 --- a/zerver/tests/test_home.py +++ b/zerver/tests/test_home.py @@ -457,7 +457,9 @@ class HomeTest(ZulipTestCase): user.tos_version = user_tos_version user.save() - with self.settings(TERMS_OF_SERVICE="whatever"), self.settings(TOS_VERSION="99.99"): + with self.settings(TERMS_OF_SERVICE="whatever"), self.settings( + TERMS_OF_SERVICE_VERSION="99.99" + ): result = self.client_get("/", dict(stream="Denmark")) @@ -495,7 +497,7 @@ class HomeTest(ZulipTestCase): user.save() with self.settings(FIRST_TIME_TOS_TEMPLATE="hello.html"), self.settings( - TOS_VERSION="99.99" + TERMS_OF_SERVICE_VERSION="99.99" ): result = self.client_post("/accounts/accept_terms/") self.assertEqual(result.status_code, 200) diff --git a/zerver/views/home.py b/zerver/views/home.py index f9be139430..ed187d451c 100644 --- a/zerver/views/home.py +++ b/zerver/views/home.py @@ -29,10 +29,10 @@ def need_accept_tos(user_profile: Optional[UserProfile]) -> bool: if settings.TERMS_OF_SERVICE is None: # nocoverage return False - if settings.TOS_VERSION is None: + if settings.TERMS_OF_SERVICE_VERSION is None: return False - return int(settings.TOS_VERSION.split(".")[0]) > user_profile.major_tos_version() + return int(settings.TERMS_OF_SERVICE_VERSION.split(".")[0]) > user_profile.major_tos_version() @zulip_login_required @@ -42,7 +42,7 @@ def accounts_accept_terms(request: HttpRequest) -> HttpResponse: if request.method == "POST": form = ToSForm(request.POST) if form.is_valid(): - do_change_tos_version(request.user, settings.TOS_VERSION) + do_change_tos_version(request.user, settings.TERMS_OF_SERVICE_VERSION) return redirect(home) else: form = ToSForm() diff --git a/zerver/views/registration.py b/zerver/views/registration.py index 3634a78b0c..902a8ee324 100644 --- a/zerver/views/registration.py +++ b/zerver/views/registration.py @@ -446,7 +446,7 @@ def accounts_register( full_name, prereg_user=prereg_user, role=role, - tos_version=settings.TOS_VERSION, + tos_version=settings.TERMS_OF_SERVICE_VERSION, timezone=timezone, default_stream_groups=default_stream_groups, source_profile=source_profile, diff --git a/zilencer/management/commands/populate_db.py b/zilencer/management/commands/populate_db.py index 1ad08b59ec..37d21decec 100644 --- a/zilencer/management/commands/populate_db.py +++ b/zilencer/management/commands/populate_db.py @@ -465,7 +465,7 @@ class Command(BaseCommand): email = fname.lower() + "@zulip.com" names.append((full_name, email)) - create_users(zulip_realm, names, tos_version=settings.TOS_VERSION) + create_users(zulip_realm, names, tos_version=settings.TERMS_OF_SERVICE_VERSION) iago = get_user_by_delivery_email("iago@zulip.com", zulip_realm) do_change_user_role(iago, UserProfile.ROLE_REALM_ADMINISTRATOR, acting_user=None) @@ -787,13 +787,17 @@ class Command(BaseCommand): ("Athena Consulting Exchange User (MIT)", "starnine@mit.edu"), ("Esp Classroom (MIT)", "espuser@mit.edu"), ] - create_users(mit_realm, testsuite_mit_users, tos_version=settings.TOS_VERSION) + create_users( + mit_realm, testsuite_mit_users, tos_version=settings.TERMS_OF_SERVICE_VERSION + ) testsuite_lear_users = [ ("King Lear", "king@lear.org"), ("Cordelia, Lear's daughter", "cordelia@zulip.com"), ] - create_users(lear_realm, testsuite_lear_users, tos_version=settings.TOS_VERSION) + create_users( + lear_realm, testsuite_lear_users, tos_version=settings.TERMS_OF_SERVICE_VERSION + ) if not options["test_suite"]: # To keep the messages.json fixtures file for the test diff --git a/zproject/default_settings.py b/zproject/default_settings.py index 756d8d1581..1ce2d37987 100644 --- a/zproject/default_settings.py +++ b/zproject/default_settings.py @@ -358,8 +358,8 @@ REALM_CREATION_LINK_VALIDITY_DAYS = 7 # Version number for ToS. Change this if you want to force every # user to click through to re-accept terms of service before using # Zulip again on the web. -TOS_VERSION: Optional[str] = None -# Template to use when bumping TOS_VERSION to explain situation. +TERMS_OF_SERVICE_VERSION: Optional[str] = None +# Template to use when bumping TERMS_OF_SERVICE_VERSION to explain situation. FIRST_TIME_TOS_TEMPLATE: Optional[str] = None # Hostname used for Zulip's statsd logging integration.