34 entity = session.entity_cache(eid) |
34 entity = session.entity_cache(eid) |
35 except KeyError: |
35 except KeyError: |
36 pass |
36 pass |
37 else: |
37 else: |
38 entity.clear_related_cache(rtype, role) |
38 entity.clear_related_cache(rtype, role) |
39 if gaesubject.kind() == 'EUser': |
39 if gaesubject.kind() == 'CWUser': |
40 for asession in session.repo._sessions.itervalues(): |
40 for asession in session.repo._sessions.itervalues(): |
41 if asession.user.eid == subject: |
41 if asession.user.eid == subject: |
42 asession.user.clear_related_cache(rtype, 'subject') |
42 asession.user.clear_related_cache(rtype, 'subject') |
43 if gaeobject.kind() == 'EUser': |
43 if gaeobject.kind() == 'CWUser': |
44 for asession in session.repo._sessions.itervalues(): |
44 for asession in session.repo._sessions.itervalues(): |
45 if asession.user.eid == object: |
45 if asession.user.eid == object: |
46 asession.user.clear_related_cache(rtype, 'object') |
46 asession.user.clear_related_cache(rtype, 'object') |
47 |
47 |
48 def _mark_modified(session, gaeentity): |
48 def _mark_modified(session, gaeentity): |
112 |
112 |
113 |
113 |
114 class GAESource(AbstractSource): |
114 class GAESource(AbstractSource): |
115 """adapter for a system source on top of google appengine datastore""" |
115 """adapter for a system source on top of google appengine datastore""" |
116 |
116 |
117 passwd_rql = "Any P WHERE X is EUser, X login %(login)s, X upassword P" |
117 passwd_rql = "Any P WHERE X is CWUser, X login %(login)s, X upassword P" |
118 auth_rql = "Any X WHERE X is EUser, X login %(login)s, X upassword %(pwd)s" |
118 auth_rql = "Any X WHERE X is CWUser, X login %(login)s, X upassword %(pwd)s" |
119 _sols = ({'X': 'EUser', 'P': 'Password'},) |
119 _sols = ({'X': 'CWUser', 'P': 'Password'},) |
120 |
120 |
121 options = () |
121 options = () |
122 |
122 |
123 def __init__(self, repo, appschema, source_config, *args, **kwargs): |
123 def __init__(self, repo, appschema, source_config, *args, **kwargs): |
124 AbstractSource.__init__(self, repo, appschema, source_config, |
124 AbstractSource.__init__(self, repo, appschema, source_config, |
155 |
155 |
156 def set_schema(self, schema): |
156 def set_schema(self, schema): |
157 """set the application'schema""" |
157 """set the application'schema""" |
158 self.interpreter = RQLInterpreter(schema) |
158 self.interpreter = RQLInterpreter(schema) |
159 self.schema = schema |
159 self.schema = schema |
160 if 'EUser' in schema and not self.repo.config['use-google-auth']: |
160 if 'CWUser' in schema and not self.repo.config['use-google-auth']: |
161 # rql syntax trees used to authenticate users |
161 # rql syntax trees used to authenticate users |
162 self._passwd_rqlst = self.compile_rql(self.passwd_rql) |
162 self._passwd_rqlst = self.compile_rql(self.passwd_rql) |
163 self._auth_rqlst = self.compile_rql(self.auth_rql) |
163 self._auth_rqlst = self.compile_rql(self.auth_rql) |
164 |
164 |
165 def support_entity(self, etype, write=False): |
165 def support_entity(self, etype, write=False): |
183 else: |
183 else: |
184 login = unicode(guser.nickname()) |
184 login = unicode(guser.nickname()) |
185 # XXX http://code.google.com/appengine/docs/users/userobjects.html |
185 # XXX http://code.google.com/appengine/docs/users/userobjects.html |
186 # use a reference property to automatically work with email address |
186 # use a reference property to automatically work with email address |
187 # changes after the propagation feature is implemented |
187 # changes after the propagation feature is implemented |
188 key = Key.from_path('EUser', 'key_' + login, parent=None) |
188 key = Key.from_path('CWUser', 'key_' + login, parent=None) |
189 try: |
189 try: |
190 euser = session.datastore_get(key) |
190 euser = session.datastore_get(key) |
191 # XXX fix user. Required until we find a better way to fix broken records |
191 # XXX fix user. Required until we find a better way to fix broken records |
192 if not euser.get('s_in_group'): |
192 if not euser.get('s_in_group'): |
193 _init_groups(guser, euser) |
193 _init_groups(guser, euser) |
194 Put(euser) |
194 Put(euser) |
195 return str(key) |
195 return str(key) |
196 except datastore_errors.EntityNotFoundError: |
196 except datastore_errors.EntityNotFoundError: |
197 # create a record for this user |
197 # create a record for this user |
198 euser = Entity('EUser', name='key_' + login) |
198 euser = Entity('CWUser', name='key_' + login) |
199 euser['s_login'] = login |
199 euser['s_login'] = login |
200 _init_groups(guser, euser) |
200 _init_groups(guser, euser) |
201 Put(euser) |
201 Put(euser) |
202 return str(euser.key()) |
202 return str(euser.key()) |
203 |
203 |
204 def authenticate_local(self, session, login, password): |
204 def authenticate_local(self, session, login, password): |
205 """return EUser eid for the given login/password if this account is |
205 """return CWUser eid for the given login/password if this account is |
206 defined in this source, else raise `AuthenticationError` |
206 defined in this source, else raise `AuthenticationError` |
207 |
207 |
208 two queries are needed since passwords are stored crypted, so we have |
208 two queries are needed since passwords are stored crypted, so we have |
209 to fetch the salt first |
209 to fetch the salt first |
210 """ |
210 """ |
247 |
247 |
248 def update_entity(self, session, entity): |
248 def update_entity(self, session, entity): |
249 """replace an entity in the source""" |
249 """replace an entity in the source""" |
250 gaeentity = entity.to_gae_model() |
250 gaeentity = entity.to_gae_model() |
251 _mark_modified(session, entity.to_gae_model()) |
251 _mark_modified(session, entity.to_gae_model()) |
252 if gaeentity.kind() == 'EUser': |
252 if gaeentity.kind() == 'CWUser': |
253 for asession in self.repo._sessions.itervalues(): |
253 for asession in self.repo._sessions.itervalues(): |
254 if asession.user.eid == entity.eid: |
254 if asession.user.eid == entity.eid: |
255 asession.user.update(dict(gaeentity)) |
255 asession.user.update(dict(gaeentity)) |
256 |
256 |
257 def delete_entity(self, session, etype, eid): |
257 def delete_entity(self, session, etype, eid): |