endpoints/api: Allow null fields in user metadata

The user metadata fields are nullable in the database, but were not in
the json sechema.  This prevented users from updating some of their
information on the site if they hadn't set the metadata fields.
This commit is contained in:
Brad Ison 2018-06-26 16:07:59 -04:00
parent f32bbf1fdc
commit 73cb7f3228
No known key found for this signature in database
GPG key ID: 972D14B0BE6DE287
6 changed files with 71 additions and 27 deletions

View file

@ -436,10 +436,18 @@ def update_user_metadata(user, metadata=None):
metadata = metadata if metadata is not None else {}
with db_transaction():
user.given_name = metadata.get('given_name') or user.given_name
user.family_name = metadata.get('family_name') or user.family_name
user.company = metadata.get('company') or user.company
user.location = metadata.get('location') or user.location
if 'given_name' in metadata:
user.given_name = metadata['given_name']
if 'family_name' in metadata:
user.family_name = metadata['family_name']
if 'company' in metadata:
user.company = metadata['company']
if 'location' in metadata:
user.location = metadata['location']
user.save()
# Remove any prompts associated with the user's metadata being needed.