mirror of
https://github.com/haiwen/seahub.git
synced 2025-09-26 07:22:34 +00:00
[profile] Handle duplicated contact emails
This commit is contained in:
@@ -5,6 +5,7 @@ from django.conf import settings
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
|
from django.core.exceptions import MultipleObjectsReturned
|
||||||
|
|
||||||
from seahub.base.fields import LowerCaseCharField
|
from seahub.base.fields import LowerCaseCharField
|
||||||
from seahub.profile.settings import EMAIL_ID_CACHE_PREFIX, EMAIL_ID_CACHE_TIMEOUT
|
from seahub.profile.settings import EMAIL_ID_CACHE_PREFIX, EMAIL_ID_CACHE_TIMEOUT
|
||||||
@@ -104,6 +105,10 @@ class ProfileManager(models.Manager):
|
|||||||
return super(ProfileManager, self).get(contact_email=contact_email).user
|
return super(ProfileManager, self).get(contact_email=contact_email).user
|
||||||
except Profile.DoesNotExist:
|
except Profile.DoesNotExist:
|
||||||
return None
|
return None
|
||||||
|
except MultipleObjectsReturned as e:
|
||||||
|
logger.warn('Failed to get username by contact email: %s' % contact_email)
|
||||||
|
logger.warn(e)
|
||||||
|
return None
|
||||||
|
|
||||||
def convert_login_str_to_username(self, login_str):
|
def convert_login_str_to_username(self, login_str):
|
||||||
"""
|
"""
|
||||||
|
@@ -6,6 +6,17 @@ class ProfileManagerTest(BaseTestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def test_get_username_by_contact_email(self):
|
||||||
|
assert Profile.objects.get_username_by_contact_email('a@a.com') is None
|
||||||
|
|
||||||
|
user1 = self.user.username
|
||||||
|
Profile.objects.add_or_update(user1, contact_email='a@a.com')
|
||||||
|
assert Profile.objects.get_username_by_contact_email('a@a.com') == user1
|
||||||
|
|
||||||
|
user2 = self.admin.username
|
||||||
|
Profile.objects.add_or_update(user2, contact_email='a@a.com')
|
||||||
|
assert Profile.objects.get_username_by_contact_email('a@a.com') is None
|
||||||
|
|
||||||
def test_convert_login_str_to_username(self):
|
def test_convert_login_str_to_username(self):
|
||||||
s = Profile.objects
|
s = Profile.objects
|
||||||
assert s.convert_login_str_to_username('a@a.com') == 'a@a.com'
|
assert s.convert_login_str_to_username('a@a.com') == 'a@a.com'
|
||||||
|
Reference in New Issue
Block a user