Generate the client_id on the client, so we don't need a round trip to get it before we can send arbitrary RPCs.

This changes the Profile/Client relationship; we never needed to be transactional with them, so split them up entirely so we can reparent Clients.
This commit is contained in:
Ian Gulliver
2014-05-31 23:25:15 -07:00
parent 0ab2fe620c
commit fd5569c5dc
4 changed files with 49 additions and 47 deletions

View File

@@ -25,7 +25,8 @@ import utils
# Profile
# ↳ Client
#
# Client (⤴︎ Profile)
#
# Instance
#
@@ -73,20 +74,20 @@ class Profile(db.Model):
class Client(db.Model):
# parent=Profile
profile = db.ReferenceProperty(reference_class=Profile)
first_seen = db.DateTimeProperty(required=True, auto_now_add=True)
@classmethod
def FromProfile(cls, profile):
client = cls(parent=profile)
def FromProfile(cls, client_id, profile):
client = cls(key_name=client_id, profile=profile)
client.put()
return client
@classmethod
def FromGoogleUser(cls, google_user):
def FromGoogleUser(cls, client_id, google_user):
profile = Profile.FromGoogleUser(google_user)
return cls.FromProfile(profile)
return cls.FromProfile(client_id, profile)
class Instance(db.Model):
@@ -308,7 +309,7 @@ class Subscription(db.Model):
readable_only_by = (
Subject.readable_only_by.get_value_for_datastore(subject))
if (readable_only_by and
readable_only_by != client.parent_key()):
readable_only_by != Client.profile.get_value_for_datastore(client)):
raise AccessDenied
subscriptions = (