invalidate any users who match the walled-garden whitelist regex patterns (bug 747282)
This commit is contained in:
Родитель
42316161e3
Коммит
abfa2b3a3d
|
@ -32,11 +32,14 @@ class AccessWhitelist(amo.models.ModelBase):
|
|||
dispatch_uid='accesswhitelist.post_save')
|
||||
def accesswhitelist_post_save(sender, instance, **kw):
|
||||
if not kw.get('raw') and instance.email:
|
||||
from amo.utils import chunked
|
||||
from users.models import UserProfile
|
||||
emails = instance.email.replace('\r', '').split('\n')
|
||||
# Invalidate users.
|
||||
for user in UserProfile.objects.filter(email__in=emails):
|
||||
user.save()
|
||||
# Invalidate all users whose emails match the whitelisted patterns.
|
||||
users = UserProfile.objects.filter(notes='__market__')
|
||||
for chunk in chunked(users, 150):
|
||||
for user in chunk:
|
||||
if AccessWhitelist.matches(user.email):
|
||||
user.save()
|
||||
|
||||
|
||||
class Group(amo.models.ModelBase):
|
||||
|
|
|
@ -239,6 +239,7 @@ class TestAccessWhitelist(amo.tests.TestCase):
|
|||
def test_post_save_invalidate_users(self):
|
||||
u = UserProfile.objects.get(email='regular@mozilla.com')
|
||||
eq_(amo.tests.close_to_now(u.modified), False)
|
||||
u.update(notes='__market__')
|
||||
|
||||
AccessWhitelist.objects.create(
|
||||
email='regular@mozilla.com\r\nfligczar@gmail.com')
|
||||
|
@ -249,8 +250,20 @@ class TestAccessWhitelist(amo.tests.TestCase):
|
|||
def test_post_save_invalidate_correct_users(self):
|
||||
u = UserProfile.objects.get(email='regular@mozilla.com')
|
||||
eq_(amo.tests.close_to_now(u.modified), False)
|
||||
u.update(notes='__market__')
|
||||
|
||||
AccessWhitelist.objects.create(email='fligczar@gmail.com')
|
||||
AccessWhitelist.objects.create(
|
||||
email='regular@*.com\r\nfligczar@gmail.com')
|
||||
|
||||
u = UserProfile.objects.get(email='regular@mozilla.com')
|
||||
eq_(amo.tests.close_to_now(u.modified), True)
|
||||
|
||||
def test_post_save_skip_amo_users(self):
|
||||
a = AccessWhitelist.objects.create(email='regular@mozilla.*')
|
||||
u = UserProfile.objects.get(email='regular@mozilla.com')
|
||||
eq_(amo.tests.close_to_now(u.modified), False)
|
||||
|
||||
u.update(notes='__market__')
|
||||
a.save()
|
||||
u = UserProfile.objects.get(email='regular@mozilla.com')
|
||||
eq_(amo.tests.close_to_now(u.modified), True)
|
||||
|
|
Загрузка…
Ссылка в новой задаче