Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed bad filter that caused dupe user imports.

Also:
- added user indexing for autocomplete
- cron decorator works in dev now
  • Loading branch information...
commit 7c6ad7a94d9640d07eab57c452af629c3df1eb09 1 parent 455ddbf
@kumar303 kumar303 authored
View
8 auth/tasks.py
@@ -5,6 +5,7 @@
from auth import roles
from auth.models import User
+from auth.views import _reindex
log = logging.getLogger()
@@ -24,8 +25,10 @@ def sync_user(request):
# No previously sync'd user exists.
# Let's check by email to see if an old
# user exists with the same email.
- qs = (User.all().filter('email =', user['email'])
- .filter('external_id =', None))
+ qs = User.all().filter('email =', user['email'])
+ if qs.count(2) == 2:
+ raise LookupError('More than one user for %s; '
+ 'aborting sync' % user['email'])
users = qs.fetch(1)
if len(users):
log.info('Linking user %s to ID %s' %
@@ -48,6 +51,7 @@ def sync_user(request):
setattr(dj_user, k, v)
if roles.DJ not in dj_user.roles:
dj_user.roles.append(roles.DJ)
+ _reindex(dj_user)
dj_user.put()
return http.HttpResponse('OK')
View
15 auth/tests/test_tasks.py
@@ -2,7 +2,7 @@
from django.test import TestCase
from django.utils import simplejson as json
-from nose.tools import eq_
+from nose.tools import eq_, raises
from auth import roles
from auth.models import User
@@ -38,6 +38,7 @@ def test_sync_new(self):
eq_(us.is_superuser, False)
eq_(us.is_active, True)
eq_(us.roles, [roles.DJ])
+ assert us.index, 'User was not indexed'
def test_sync_existing_with_id(self):
us = User(email=self.user['email'],
@@ -53,6 +54,7 @@ def test_sync_existing_with_id(self):
eq_(us.is_superuser, False)
eq_(us.is_active, True)
eq_(us.roles, [roles.DJ])
+ assert us.index, 'User was not indexed'
def test_sync_existing_without_id(self):
us = User(email=self.user['email'])
@@ -67,6 +69,17 @@ def test_sync_existing_without_id(self):
eq_(us.is_superuser, False)
eq_(us.is_active, True)
eq_(us.roles, [roles.DJ])
+ eq_(User.all().filter('email =', self.user['email']).count(2), 1)
+
+ @raises(LookupError)
+ def test_collisions(self):
+ us = User(email=self.user['email'])
+ us.put()
+ # This might actually happen because some filtering caused
+ # bad data in production.
+ another = User(email=self.user['email']) # same email
+ another.put()
+ self.sync()
def test_sync_existing_with_roles(self):
us = User(email=self.user['email'],
View
6 common/utilities.py
@@ -18,9 +18,10 @@
import traceback
import logging
-from django.utils import simplejson
from django import http
+from django.conf import settings
from django.http import HttpResponse
+from django.utils import simplejson
from jobs import job_worker, job_product
@@ -114,7 +115,8 @@ def cronjob(handler):
"""
@functools.wraps(handler)
def handle(request, *args, **kwargs):
- if not request.META.get('HTTP_X_APPENGINE_CRON') == 'true':
+ if (not settings.IN_DEV and
+ not request.META.get('HTTP_X_APPENGINE_CRON') == 'true'):
log.error('Not a request from cron')
return http.HttpResponseBadRequest()
res = handler(request, *args, **kwargs)
View
6 cron.yaml
@@ -9,6 +9,6 @@ cron:
- description: play count snapshot
url: /playlists/task/play_count_snapshot
schedule: every day 07:30
-#- description: sync users from live site XML
-# url: /auth/cron/sync_users
-# schedule: every 2 hours
+- description: sync users from live site XML
+ url: /auth/cron/sync_users
+ schedule: every 2 hours
Please sign in to comment.
Something went wrong with that request. Please try again.