users: Set tos_version to -1 for users who have not logged-in yet.

We now set tos_version to "-1" for imported users and the ones
created using API or using other methods like LDAP, SCIM and
management commands. This value will help us to allow users to
change email address visibility setting during first login.
This commit is contained in:
Sahil Batra
2023-05-08 12:47:57 +05:30
committed by Tim Abbott
parent f58e3d2cf6
commit 7f01b3fb63
11 changed files with 45 additions and 19 deletions

View File

@@ -53,12 +53,14 @@ workflow as `./manage.py create_user`.
create_user_params.password,
realm,
create_user_params.full_name,
# Explicitly set tos_version=None. For servers that
# have configured Terms of Service, this means that
# users created via this mechanism will be prompted to
# accept the Terms of Service on first login.
# Explicitly set tos_version=-1. This means that users
# created via this mechanism would be prompted to set
# the email_address_visibility setting on first login.
# For servers that have configured Terms of Service,
# users will also be prompted to accept the Terms of
# Service on first login.
role=UserProfile.ROLE_REALM_OWNER,
realm_creation=True,
tos_version=None,
tos_version=UserProfile.TOS_VERSION_BEFORE_FIRST_LOGIN,
acting_user=None,
)

View File

@@ -6,6 +6,7 @@ from django.db.utils import IntegrityError
from zerver.actions.create_user import do_create_user
from zerver.lib.management import ZulipBaseCommand
from zerver.models import UserProfile
class Command(ZulipBaseCommand):
@@ -38,11 +39,13 @@ prompted to accept the Terms of Service the first time they login.
create_user_params.password,
realm,
create_user_params.full_name,
# Explicitly set tos_version=None. For servers that
# have configured Terms of Service, this means that
# users created via this mechanism will be prompted to
# accept the Terms of Service on first login.
tos_version=None,
# Explicitly set tos_version=-1. This means that users
# created via this mechanism would be prompted to set
# the email_address_visibility setting on first login.
# For servers that have configured Terms of Service,
# users will also be prompted to accept the Terms of
# Service on first login.
tos_version=UserProfile.TOS_VERSION_BEFORE_FIRST_LOGIN,
acting_user=None,
)
except IntegrityError:

View File

@@ -3,6 +3,7 @@ from typing import Any, Collection, List
from django.conf import settings
from django.core.management.base import CommandError
from django.db.models import Q
from zerver.lib.management import ZulipBaseCommand
from zerver.lib.send_email import send_custom_email
@@ -130,7 +131,9 @@ class Command(ZulipBaseCommand):
users = (
UserProfile.objects.select_related()
.filter(id__in=[u.id for u in users])
.exclude(tos_version=None)
.exclude(
Q(tos_version=None) | Q(tos_version=UserProfile.TOS_VERSION_BEFORE_FIRST_LOGIN)
)
)
send_custom_email(users, target_emails=target_emails, options=options)