From abfa2b3a3dc9725e448108295581e05a19285da9 Mon Sep 17 00:00:00 2001 From: Chris Van Date: Sat, 28 Apr 2012 00:41:12 -0700 Subject: [PATCH] invalidate any users who match the walled-garden whitelist regex patterns (bug 747282) --- apps/access/models.py | 11 +++++++---- apps/access/tests.py | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/apps/access/models.py b/apps/access/models.py index 128650ba13..a67e4f3e4f 100644 --- a/apps/access/models.py +++ b/apps/access/models.py @@ -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): diff --git a/apps/access/tests.py b/apps/access/tests.py index e0bb85e42f..b9d05fd7a2 100644 --- a/apps/access/tests.py +++ b/apps/access/tests.py @@ -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)