From 1618105c255161d32ceeeb5a2a153247582caac1 Mon Sep 17 00:00:00 2001 From: James Tanner Date: Wed, 20 Sep 2023 12:16:53 -0400 Subject: [PATCH] Delete all print statements. No-Issue Signed-off-by: James Tanner --- galaxy_ng/app/utils/legacy.py | 23 ++--------------- galaxy_ng/social/__init__.py | 22 +++++++--------- galaxy_ng/social/pipeline/user.py | 42 +++---------------------------- 3 files changed, 14 insertions(+), 73 deletions(-) diff --git a/galaxy_ng/app/utils/legacy.py b/galaxy_ng/app/utils/legacy.py index 2cd76fa715..082a2c2fcb 100644 --- a/galaxy_ng/app/utils/legacy.py +++ b/galaxy_ng/app/utils/legacy.py @@ -34,7 +34,7 @@ def sanitize_avatar_url(url): - + '''Remove all the non-url characters people have put in their avatar urls''' regex = ( r"(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)" + r"(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|" @@ -42,7 +42,6 @@ def sanitize_avatar_url(url): ) for match in re.findall(regex, url): - # print(f'MATCH {match}') if match and 'http' in match[0]: return match[0] @@ -50,8 +49,7 @@ def sanitize_avatar_url(url): def process_namespace(namespace_name, namespace_info): - - # validate or transform name ... + '''Do all the work to sync a legacy namespace and build it's v3 counterpart''' # get or create a legacy namespace with an identical name first ... legacy_namespace, legacy_namespace_created = \ @@ -68,13 +66,11 @@ def process_namespace(namespace_name, namespace_info): if _matched_owners: _owner_id = _matched_owners[0][0] - print(f'\tusing {_matched_owners[0]} to create v3 name') v3_namespace_name = \ generate_v3_namespace_from_attributes(username=namespace_name, github_id=_owner_id) else: v3_namespace_name = generate_v3_namespace_from_attributes(username=namespace_name) - print(f'\tusing {v3_namespace_name} for v3 namespace name') namespace, namespace_created = Namespace.objects.get_or_create(name=v3_namespace_name) # bind legacy and v3 @@ -86,21 +82,17 @@ def process_namespace(namespace_name, namespace_info): if namespace_info['avatar_url'] and not namespace.avatar_url: avatar_url = sanitize_avatar_url(namespace_info['avatar_url']) if avatar_url: - print(f'\tsetting avatar_url to {avatar_url}') namespace.avatar_url = avatar_url changed = True if namespace_info['company'] and not namespace.company: if len(namespace_info['company']) >= 60: - print(f"\tsetting company to {namespace_info['company'][:60]}") namespace.company = namespace_info['company'][:60] else: - print(f"\tsetting company to {namespace_info['company']}") namespace.company = namespace_info['company'] changed = True if namespace_info['email'] and not namespace.email: - print(f"\tsetting email to {namespace_info['email']}") namespace.email = namespace_info['email'] changed = True @@ -112,12 +104,10 @@ def process_namespace(namespace_name, namespace_info): changed = True if changed: - print('\tsaving namespace with changes') namespace.save() for owner_info in namespace_info['summary_fields']['owners']: - print(f"\tchecking owner {owner_info['github_id']}:{owner_info['username']}") unverified_email = generate_unverified_email(owner_info['github_id']) owner_created = False @@ -125,26 +115,17 @@ def process_namespace(namespace_name, namespace_info): if not owner: owner = User.objects.filter(email=unverified_email).first() - if owner: - print(f'\t\t found owner {owner}:{owner.email}') - # should always have an email set with default of the unverified email if owner and not owner.email: - print(f'\t\tset owner {owner} email to {unverified_email}') owner.email = unverified_email owner.save() if not owner: - print("\t\tget or create ...") owner, owner_created = User.objects.get_or_create(username=owner_info['username']) - print(f"\t\tusername: {owner.username}") - print(f"\t\temail: {owner.email}") - print(f"\t\tcreated: {owner_created}") if owner_created or not owner.email: # the new user should have the unverified email until they actually login - print(f"\t\tset email to {unverified_email}") owner.email = unverified_email owner.save() diff --git a/galaxy_ng/social/__init__.py b/galaxy_ng/social/__init__.py index 0328c0b23a..a2056cdbc0 100644 --- a/galaxy_ng/social/__init__.py +++ b/galaxy_ng/social/__init__.py @@ -44,10 +44,6 @@ def do_auth(self, access_token, *args, **kwargs): # userdata = id, login, access_token data = self.get_github_user(access_token) - # print('-' * 100) - # from pprint import pprint - # pprint(data) - # print('-' * 100) # extract the login now to prevent mutation gid = data['id'] @@ -75,7 +71,7 @@ def do_auth(self, access_token, *args, **kwargs): def handle_v3_namespace(self, session_user, session_email, session_login, github_id): - print( + logger.debug( f'HANDLING V3 NAMESPACE session_user:{session_user}' + f' session_email:{session_email} session_login:{session_login}' ) @@ -85,37 +81,37 @@ def handle_v3_namespace(self, session_user, session_email, session_login, github # first make the namespace name ... namespace_name = self.transform_namespace_name(session_login) - print(f'TRANSFORMED NAME: {namespace_name}') + logger.debug(f'TRANSFORMED NAME: {namespace_name}') if not self.validate_namespace_name(namespace_name): - print(f'DID NOT VALIDATE NAMESPACE NAME: {namespace_name}') + logger.debug(f'DID NOT VALIDATE NAMESPACE NAME: {namespace_name}') return False, False # does the namespace already exist? found_namespace = Namespace.objects.filter(name=namespace_name).first() - print(f'FOUND NAMESPACE: {found_namespace}') + logger.debug(f'FOUND NAMESPACE: {found_namespace}') # is it owned by this userid? if found_namespace: - print(f'FOUND EXISTING NAMESPACE: {found_namespace}') + logger.debug(f'FOUND EXISTING NAMESPACE: {found_namespace}') owners = rbac.get_v3_namespace_owners(found_namespace) - print(f'FOUND EXISTING OWNERS: {owners}') + logger.debug(f'FOUND EXISTING OWNERS: {owners}') if session_user in owners: return found_namespace, False # should always have a namespace ... if found_namespace: - print(f'GENERATING A NEW NAMESPACE NAME SINCE USER DOES NOT OWN {found_namespace}') + logger.debug(f'GENERATING A NEW NAMESPACE NAME SINCE USER DOES NOT OWN {found_namespace}') namespace_name = self.generate_available_namespace_name(session_login, github_id) - print(f'FINAL NAMESPACE NAME {namespace_name}') + logger.debug(f'FINAL NAMESPACE NAME {namespace_name}') # create a v3 namespace? namespace, namespace_created = self._ensure_namespace(namespace_name, session_user) owned = rbac.get_owned_v3_namespaces(session_user) - print(f'NS OWNED BY {session_user}: {owned}') + logger.debug(f'NS OWNED BY {session_user}: {owned}') return namespace, namespace_created diff --git a/galaxy_ng/social/pipeline/user.py b/galaxy_ng/social/pipeline/user.py index 3d197de93a..59edefb3b2 100644 --- a/galaxy_ng/social/pipeline/user.py +++ b/galaxy_ng/social/pipeline/user.py @@ -2,45 +2,30 @@ from galaxy_ng.app.models.auth import User +from galaxy_ng.app.utils.galaxy import generate_unverified_email USER_FIELDS = ['username', 'email'] def get_username(strategy, details, backend, user=None, *args, **kwargs): - print('GET USERNAME: details:{details}') return {'username': details['username']} def create_user(strategy, details, backend, user=None, *args, **kwargs): - print('-' * 100) - print('CREATE USER') - print(f'\t strat:{strategy}') - print(f'\t backend:{backend}') - print(f'\t user:{user}') - print(f'\t user-type:{type(user)}') - print(f'\t details:{details}') - print(f'\t args:{args}') - print(f'\t kwargs:{kwargs}') - print('-' * 100) - if user: if user.username != details.get('username'): - print('FIXING EXISTING USERs USERNAME') user.username = details.get('username') user.save() - print('SKIPPING USER CREATE: ALREADY EXISTS') return {'is_new': False} fields = dict( (name, kwargs.get(name, details.get(name))) for name in backend.setting('USER_FIELDS', USER_FIELDS) ) - print(f'FIELDS:{fields}') if not fields: - print('SKIPPING USER CREATE: NO FIELDS') return # bypass the strange logic that can't find the user ... ? @@ -50,14 +35,8 @@ def create_user(strategy, details, backend, user=None, *args, **kwargs): if not github_id: github_id = kwargs['response']['id'] - print('-----------------------------------------') - print(f'USERNAME:{username} GITHUB_ID:{github_id}') - print('-----------------------------------------') - - # found_user = User.objects.filter(username=username).first() - # found_user = User.objects.filter(username=username, email=email).first() - - possible_emails = [str(github_id) + '@GALAXY.GITHUB.UNVERIFIED.COM', email] + # check for all possible emails ... + possible_emails = [generate_unverified_email(github_id), email] for possible_email in possible_emails: found_email = User.objects.filter(email=possible_email).first() if found_email is not None: @@ -67,7 +46,6 @@ def create_user(strategy, details, backend, user=None, *args, **kwargs): # fix the username if they've changed their login since last time if found_email.username != username: - print('FIXING FOUND USERs USERNAME') found_email.username = username found_email.save() @@ -75,10 +53,6 @@ def create_user(strategy, details, backend, user=None, *args, **kwargs): found_email.email = email found_email.save() - print( - f'SKIPPING USER CREATE: FOUND USER {found_email} username:{found_email.username}' - + f' email:{found_email.email}' - ) return { 'is_new': False, 'user': found_email @@ -98,9 +72,6 @@ def create_user(strategy, details, backend, user=None, *args, **kwargs): 'user': found_username } - print(f'\tCALLING {strategy}.create_user({fields})') - # return self.storage.user.create_user(*args, **kwargs) - print(f'\t\tSTORAGE:{strategy.storage} TYPE:{type(strategy.storage)}') new_user = strategy.create_user(**fields) return { 'is_new': True, @@ -111,14 +82,7 @@ def create_user(strategy, details, backend, user=None, *args, **kwargs): def user_details(strategy, details, backend, user=None, *args, **kwargs): """Update user details using data from provider.""" - print('USER_DETAILS') - print( - f'\tstrat:{strategy} details:{details} backend:{backend}' - + f' user:{user} args:{args} kwargs:{kwargs}' - ) - if not user: - print('\tNO USER RETURNING') return changed = False # flag to track changes