Unverified Commit a8225f42 authored by Tamika Tannis's avatar Tamika Tannis Committed by GitHub

Update profile url workaround (#459)

* Try something for test

* Update fix

* Update fix

* Lint fix
parent c85fb5ea
from typing import Dict from typing import Dict, Optional
from amundsen_common.models.user import UserSchema, User from amundsen_common.models.user import UserSchema, User
from flask import current_app as app from flask import current_app as app
from marshmallow import ValidationError from marshmallow import ValidationError
def _str_no_value(s: Optional[str]) -> bool:
# Returns True if the given string is None or empty
if not s:
return True
if len(s.strip()) == 0:
return True
return False
def load_user(user_data: Dict) -> User: def load_user(user_data: Dict) -> User:
try: try:
schema = UserSchema() schema = UserSchema()
# To make sure we pass frontend configuration to amundsen common models # In order to call 'GET_PROFILE_URL' we make sure the user id exists
user_data['GET_PROFILE_URL'] = app.config['GET_PROFILE_URL'] if _str_no_value(user_data.get('user_id')):
user_data['user_id'] = user_data.get('email')
# Add profile_url from optional 'GET_PROFILE_URL' configuration method.
# This methods currently exists for the case where the 'profile_url' is not included
# in the user metadata.
if _str_no_value(user_data.get('profile_url')) and app.config['GET_PROFILE_URL']:
user_data['profile_url'] = app.config['GET_PROFILE_URL'](user_data['user_id'])
data, errors = schema.load(user_data) data, errors = schema.load(user_data)
return data return data
except ValidationError as err: except ValidationError as err:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment