Support lastChange field in JSON GroupList data
This commit is contained in:
parent
c5dae5ef45
commit
61f1a78943
2 changed files with 14 additions and 5 deletions
|
@ -73,9 +73,11 @@ def sync(req):
|
||||||
|
|
||||||
login_data=req.ctx.db.login(data['email'],data['password'])
|
login_data=req.ctx.db.login(data['email'],data['password'])
|
||||||
if 'email' in login_data:
|
if 'email' in login_data:
|
||||||
|
log.debug(u'Login successful : sync groups')
|
||||||
ret=req.ctx.db.sync_group(data['email'],data['groups'])
|
ret=req.ctx.db.sync_group(data['email'],data['groups'])
|
||||||
return wsgi_helpers.respond_json(req.ctx,ret,headers=[('Access-Control-Allow-Origin','*')])
|
return wsgi_helpers.respond_json(req.ctx,ret,headers=[('Access-Control-Allow-Origin','*')])
|
||||||
else:
|
else:
|
||||||
|
log.debug(u'Login error : return login error')
|
||||||
return wsgi_helpers.respond_json(
|
return wsgi_helpers.respond_json(
|
||||||
req.ctx,
|
req.ctx,
|
||||||
login_data,
|
login_data,
|
||||||
|
|
|
@ -74,15 +74,22 @@ class DB(object):
|
||||||
db_groups=self.get_group(email)
|
db_groups=self.get_group(email)
|
||||||
json_group=json.dumps(groups)
|
json_group=json.dumps(groups)
|
||||||
if db_groups!=False:
|
if db_groups!=False:
|
||||||
if db_groups=={}:
|
log.debug('Database groups : %s' % db_groups)
|
||||||
if groups=={}:
|
log.debug('Provided groups : %s' % groups)
|
||||||
return {'groups': {}}
|
if 'groups' not in db_groups or db_groups['groups']=={}:
|
||||||
|
log.debug('Database group is empty')
|
||||||
|
if 'groups' not in groups or groups['groups']=={}:
|
||||||
|
log.debug('Database and provided group are empty. Return empty')
|
||||||
|
return {'groups': {'groups': {}}}
|
||||||
else:
|
else:
|
||||||
|
log.debug('Insert provided groups in database and return it')
|
||||||
if self.do_sql("INSERT INTO groups (email,groups) VALUES ('%s','%s')" % (email,json_group)):
|
if self.do_sql("INSERT INTO groups (email,groups) VALUES ('%s','%s')" % (email,json_group)):
|
||||||
return {'groups': groups}
|
return {'groups': groups}
|
||||||
elif groups=={}:
|
elif 'groups' not in groups or groups['groups']=={}:
|
||||||
|
log.debug('Provide group is empty. Return database groups')
|
||||||
return {'groups': db_groups}
|
return {'groups': db_groups}
|
||||||
else:
|
else:
|
||||||
|
log.debug('Update database with provided group and return it')
|
||||||
if self.do_sql("UPDATE groups SET groups='%s' WHERE email='%s'" % (json_group,email)):
|
if self.do_sql("UPDATE groups SET groups='%s' WHERE email='%s'" % (json_group,email)):
|
||||||
return {'groups': groups}
|
return {'groups': groups}
|
||||||
return {'syncerror': 'Erreur inconnu'}
|
return {'syncerror': 'Erreur inconnu'}
|
||||||
|
@ -93,6 +100,6 @@ class DB(object):
|
||||||
if len(ret)==1:
|
if len(ret)==1:
|
||||||
return json.loads(ret[0][0])
|
return json.loads(ret[0][0])
|
||||||
else:
|
else:
|
||||||
return {}
|
return {'groups': {}}
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
Loading…
Reference in a new issue