Skip to content

Commit

Permalink
Fixed Anon user singleton.
Browse files Browse the repository at this point in the history
  • Loading branch information
moowiz committed Sep 16, 2014
1 parent eb6367c commit 12b8d52
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
6 changes: 4 additions & 2 deletions server/app/auth.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Convert access tokens to user records."""

# Because pylint doesn't understand memcache for some reason
# pylint: disable=no-member

from app import models
from app import app
from app.utils import create_api_response
from app.authenticator import AuthenticationException

from google.appengine.api import memcache as mc
Expand All @@ -21,7 +23,7 @@ def authenticate():
return models.User.get_or_insert(user.email())

if 'access_token' not in request.args:
return models.AnonymousUser
return models.AnonymousUser()
else:
access_token = request.args['access_token']
user = mc.get("%s-%s" % (MC_NAMESPACE, access_token))
Expand Down
10 changes: 8 additions & 2 deletions server/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,16 @@ def put(self, *args, **kwds):

@classmethod
def get_or_insert(cls, *args, **kwds):
return super(AnonymousUser, cls).get_or_insert(*args, **kwds)
return super(_AnonUserClass, cls).get_or_insert(*args, **kwds)

_AnonUserClass = AnonymousUser
_AnonUser = None

AnonymousUser = AnonymousUser.get_or_insert("anon_user")
def AnonymousUser():
global _AnonUser
if not _AnonUser:
_AnonUser = _AnonUserClass.get_or_insert("anon_user")
return _AnonUser


class Assignment(Base):
Expand Down
2 changes: 1 addition & 1 deletion server/tests/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def get_accounts(self):
login="albert",
role=ADMIN_ROLE
),
"anon": models.AnonymousUser,
"anon": models.AnonymousUser(),
}

def enroll(self, student, course):
Expand Down

0 comments on commit 12b8d52

Please sign in to comment.