users: use to_update instead of manual checks to avatar field

Closes #20.

 - schemas: change avatar's type to str instead of b64_icon
This commit is contained in:
Luna Mendes 2018-11-19 15:59:03 -03:00
parent 54120bce0c
commit eccc82afcc
2 changed files with 13 additions and 2 deletions

View File

@ -173,7 +173,17 @@ async def patch_me():
""", j['email'], user_id)
user['email'] = j['email']
if 'avatar' in j and j['avatar']:
# only update if values are different
# from what the user gave.
# this will return false if the client
# sends j['avatar'] as the user's
# original avatar hash, as they're the
# same.
# IconManager.update will take care of validating
# the value once put()-ing
if to_update(j, user, 'avatar'):
new_icon = await app.icons.update(
'user', user_id, j['avatar'], size=(128, 128))

View File

@ -191,7 +191,8 @@ USER_UPDATE = {
},
'avatar': {
'type': 'b64_icon', 'required': False,
# can be both b64_icon or string (just the hash)
'type': 'string', 'required': False,
'nullable': True
},