signup: Copy hotspots when importing settings.

This commit is contained in:
Vishnu Ks
2018-06-13 12:10:53 +00:00
committed by Tim Abbott
parent ac76935f25
commit b639778d0f
4 changed files with 26 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ from django.contrib.auth.models import UserManager
from django.utils.timezone import now as timezone_now
from zerver.models import UserProfile, Recipient, Subscription, Realm, Stream
from zerver.lib.upload import copy_avatar
from zerver.lib.hotspots import copy_hotpots
import base64
import ujson
@@ -34,6 +35,8 @@ def copy_user_settings(source_profile: UserProfile, target_profile: UserProfile)
do_change_avatar_fields(target_profile, UserProfile.AVATAR_FROM_USER)
copy_avatar(source_profile, target_profile)
copy_hotpots(source_profile, target_profile)
# create_user_profile is based on Django's User.objects.create_user,
# except that we don't save to the database so it can used in
# bulk_creates

View File

@@ -56,3 +56,12 @@ def get_next_hotspots(user: UserProfile) -> List[Dict[str, object]]:
user.tutorial_status = UserProfile.TUTORIAL_FINISHED
user.save(update_fields=['tutorial_status'])
return []
def copy_hotpots(source_profile: UserProfile, target_profile: UserProfile) -> None:
for userhotspot in frozenset(UserHotspot.objects.filter(user=source_profile)):
UserHotspot.objects.create(user=target_profile, hotspot=userhotspot.hotspot,
timestamp=userhotspot.timestamp)
target_profile.tutorial_status = source_profile.tutorial_status
target_profile.onboarding_steps = source_profile.onboarding_steps
target_profile.save(update_fields=['tutorial_status', 'onboarding_steps'])

View File

@@ -2030,6 +2030,7 @@ class UserSignUpTest(ZulipTestCase):
hamlet_in_zulip.default_language = "de"
hamlet_in_zulip.emojiset = "twitter"
hamlet_in_zulip.high_contrast_mode = True
hamlet_in_zulip.tutorial_status = UserProfile.TUTORIAL_FINISHED
hamlet_in_zulip.save()
result = self.client_post('/accounts/home/', {'email': email}, subdomain=subdomain)
@@ -2048,6 +2049,7 @@ class UserSignUpTest(ZulipTestCase):
self.assertEqual(hamlet.emojiset, "google")
self.assertEqual(hamlet.high_contrast_mode, False)
self.assertEqual(hamlet.enable_stream_sounds, False)
self.assertEqual(hamlet.tutorial_status, UserProfile.TUTORIAL_WAITING)
def test_signup_with_user_settings_from_another_realm(self) -> None:
email = self.example_email('hamlet')
@@ -2064,6 +2066,7 @@ class UserSignUpTest(ZulipTestCase):
hamlet_in_zulip.default_language = "de"
hamlet_in_zulip.emojiset = "twitter"
hamlet_in_zulip.high_contrast_mode = True
hamlet_in_zulip.tutorial_status = UserProfile.TUTORIAL_FINISHED
hamlet_in_zulip.save()
result = self.client_post('/accounts/home/', {'email': email}, subdomain=subdomain)
@@ -2082,6 +2085,7 @@ class UserSignUpTest(ZulipTestCase):
self.assertEqual(hamlet_in_lear.emojiset, "twitter")
self.assertEqual(hamlet_in_lear.high_contrast_mode, True)
self.assertEqual(hamlet_in_lear.enable_stream_sounds, False)
self.assertEqual(hamlet_in_lear.tutorial_status, UserProfile.TUTORIAL_FINISHED)
zulip_path_id = avatar_disk_path(hamlet_in_zulip)
hamlet_path_id = avatar_disk_path(hamlet_in_zulip)
self.assertEqual(open(zulip_path_id, "rb").read(), open(hamlet_path_id, "rb").read())

View File

@@ -18,7 +18,7 @@ from zerver.lib.test_classes import (
from zerver.lib.test_runner import slow
from zerver.models import UserProfile, Recipient, \
Realm, RealmDomain, UserActivity, \
Realm, RealmDomain, UserActivity, UserHotspot, \
get_user, get_realm, get_client, get_stream, get_stream_recipient, \
get_membership_realms, get_source_profile, \
Message, get_context_for_message, ScheduledEmail, check_valid_user_id
@@ -443,6 +443,12 @@ class UserProfileTest(ZulipTestCase):
cordelia.enable_stream_push_notifications = True
cordelia.save()
UserHotspot.objects.filter(user=cordelia).delete()
UserHotspot.objects.filter(user=iago).delete()
hotspots_completed = ['intro_reply', 'intro_streams', 'intro_topics']
for hotspot in hotspots_completed:
UserHotspot.objects.create(user=cordelia, hotspot=hotspot)
copy_user_settings(cordelia, iago)
# We verify that cordelia and iago match, but hamlet has the defaults.
@@ -474,6 +480,9 @@ class UserProfileTest(ZulipTestCase):
self.assertEqual(cordelia.enable_stream_push_notifications, True)
self.assertEqual(hamlet.enable_stream_push_notifications, False)
hotspots = list(UserHotspot.objects.filter(user=iago).values_list('hotspot', flat=True))
self.assertEqual(hotspots, hotspots_completed)
class ActivateTest(ZulipTestCase):
def test_basics(self) -> None:
user = self.example_user('hamlet')