Skip to content

Commit

Permalink
Delete all print statements.
Browse files Browse the repository at this point in the history
No-Issue

Signed-off-by: James Tanner <[email protected]>
  • Loading branch information
jctanner committed Sep 20, 2023
1 parent c9fbea9 commit 1618105
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 73 deletions.
23 changes: 2 additions & 21 deletions galaxy_ng/app/utils/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,22 @@


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()<>]+|"
+ r"(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'\".,<>?«»“”‘’]))"
)

for match in re.findall(regex, url):
# print(f'MATCH {match}')
if match and 'http' in match[0]:
return match[0]

return None


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 = \
Expand All @@ -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
Expand All @@ -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

Expand All @@ -112,39 +104,28 @@ 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
owner = User.objects.filter(username=unverified_email).first()
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()

Expand Down
22 changes: 9 additions & 13 deletions galaxy_ng/social/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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}'
)
Expand All @@ -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

Expand Down
42 changes: 3 additions & 39 deletions galaxy_ng/social/pipeline/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ... ?
Expand All @@ -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:
Expand All @@ -67,18 +46,13 @@ 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()

if found_email.email != email:
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
Expand All @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit 1618105

Please sign in to comment.