mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	invitations: Fix email validation errors for deactivated accounts.
This provides a much clearer error message when trying to invite a user who has a deactivated account. Fixes part of #8144.
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							62007d3e38
						
					
				
				
					commit
					e7fb19c8b0
				
			@@ -4754,9 +4754,10 @@ def validate_email_for_realm(target_realm: Realm, email: str) -> None:
 | 
			
		||||
        if existing_user_profile.is_mirror_dummy:
 | 
			
		||||
            raise AssertionError("Mirror dummy user is already active!")
 | 
			
		||||
        # Other users should not already exist at all.
 | 
			
		||||
        raise ValidationError('%s already has an account' % (email,))
 | 
			
		||||
        raise ValidationError('%s already has an account' % (email,), code = _("Already has an account."))
 | 
			
		||||
    elif not existing_user_profile.is_mirror_dummy:
 | 
			
		||||
        raise ValidationError('The account for %s has been deactivated' % (email,))
 | 
			
		||||
        raise ValidationError('The account for %s has been deactivated' % (email,),
 | 
			
		||||
                              code = _("Account has been deactivated."))
 | 
			
		||||
 | 
			
		||||
def validate_email(user_profile: UserProfile, email: str) -> Tuple[Optional[str], Optional[str]]:
 | 
			
		||||
    try:
 | 
			
		||||
@@ -4775,8 +4776,8 @@ def validate_email(user_profile: UserProfile, email: str) -> Tuple[Optional[str]
 | 
			
		||||
 | 
			
		||||
    try:
 | 
			
		||||
        validate_email_for_realm(user_profile.realm, email)
 | 
			
		||||
    except ValidationError:
 | 
			
		||||
        return None, _("Already has an account.")
 | 
			
		||||
    except ValidationError as error:
 | 
			
		||||
        return None, (error.code)
 | 
			
		||||
 | 
			
		||||
    return None, None
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -3041,7 +3041,7 @@ class EmailValidatorTestCase(ZulipTestCase):
 | 
			
		||||
        cordelia.save()
 | 
			
		||||
 | 
			
		||||
        _, error = validate_email(inviter, cordelia.email)
 | 
			
		||||
        self.assertEqual(error, 'Already has an account.')
 | 
			
		||||
        self.assertEqual(error, 'Account has been deactivated.')
 | 
			
		||||
 | 
			
		||||
        _, error = validate_email(inviter, 'fred-is-fine@zulip.com')
 | 
			
		||||
        self.assertEqual(error, None)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user