From eccc82afcc590dc600526657bc1c6293dd9bb81d Mon Sep 17 00:00:00 2001 From: Luna Mendes Date: Mon, 19 Nov 2018 15:59:03 -0300 Subject: [PATCH] users: use to_update instead of manual checks to avatar field Closes #20. - schemas: change avatar's type to str instead of b64_icon --- litecord/blueprints/users.py | 12 +++++++++++- litecord/schemas.py | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/litecord/blueprints/users.py b/litecord/blueprints/users.py index 3e14a9b..c968aa6 100644 --- a/litecord/blueprints/users.py +++ b/litecord/blueprints/users.py @@ -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)) diff --git a/litecord/schemas.py b/litecord/schemas.py index e1ddeb2..8d72005 100644 --- a/litecord/schemas.py +++ b/litecord/schemas.py @@ -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 },