mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	email: Convert accounts code to use delivery_email.
A key part of this is the new helper, get_user_by_delivery_email. Its verbose name is important for clarity; it should help avoid blind copy-pasting of get_user (which we'll also want to rename). Unfortunately, it requires detailed understanding of the context to figure out which one to use; each is used in about half of call sites. Another important note is that this PR doesn't migrate get_user calls in the tests except where not doing so would cause the tests to fail. This probably deserves a follow-up refactor to avoid bugs here.
This commit is contained in:
		@@ -110,7 +110,8 @@ You can use the command list_realms to find ID of the realms in this server."""
 | 
			
		||||
        # throw an error if they don't exist.
 | 
			
		||||
        if realm is not None:
 | 
			
		||||
            try:
 | 
			
		||||
                return UserProfile.objects.select_related().get(email__iexact=email.strip(), realm=realm)
 | 
			
		||||
                return UserProfile.objects.select_related().get(
 | 
			
		||||
                    delivery_email__iexact=email.strip(), realm=realm)
 | 
			
		||||
            except UserProfile.DoesNotExist:
 | 
			
		||||
                raise CommandError("The realm '%s' does not contain a user with email '%s'" % (realm, email))
 | 
			
		||||
 | 
			
		||||
@@ -118,7 +119,7 @@ You can use the command list_realms to find ID of the realms in this server."""
 | 
			
		||||
        # optimistically try to see if there is exactly one user with
 | 
			
		||||
        # that email; if so, we'll return it.
 | 
			
		||||
        try:
 | 
			
		||||
            return UserProfile.objects.select_related().get(email__iexact=email.strip())
 | 
			
		||||
            return UserProfile.objects.select_related().get(delivery_email__iexact=email.strip())
 | 
			
		||||
        except MultipleObjectsReturned:
 | 
			
		||||
            raise CommandError("This Zulip server contains multiple users with that email " +
 | 
			
		||||
                               "(in different realms); please pass `--realm` "
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user