Navigation Menu

Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Don't add ownership of namespaces sanitized username collisions

Issue: AAH-513
  • Loading branch information
alikins committed Apr 21, 2021
1 parent 1fe0bd9 commit d4f84d3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
36 changes: 26 additions & 10 deletions galaxy/main/signals/handlers.py
Expand Up @@ -44,6 +44,7 @@ def user_logged_in_handler(request, user, **kwargs):
sanitized_username = username.lower().replace('-', '_')

if models.ProviderNamespace.objects.filter(name=username).exists():
logger.debug('Found ProviderNamespace name=username (%s)', username)
return

# User is not associated with any Provider Namespaces, so we'll attempt
Expand All @@ -63,15 +64,10 @@ def user_logged_in_handler(request, user, **kwargs):

ns_defaults = {'name': sanitized_username, **defaults}

# Create lowercase namespace if case insensitive search does not find match
# Look for case insensitive search namespace match, if not found
# we need to create one
qs = models.Namespace.objects.filter(
name__iexact=sanitized_username).order_by('name')
if qs.exists():
namespace = qs[0]
else:
namespace = models.Namespace.objects.create(**ns_defaults)

namespace.owners.add(user)

provider_ns_defaults = {
'description': social.extra_data.get('bio') or name,
Expand All @@ -81,9 +77,29 @@ def user_logged_in_handler(request, user, **kwargs):
}
provider = models.Provider.objects.get(name__iexact="github")

models.ProviderNamespace.objects.get_or_create(
namespace=namespace, name=username, provider=provider,
defaults=provider_ns_defaults)
if qs.exists():
# Namespace already exists, don't add it to the ProviderNamespace,
# it is someone elses.

msg = 'Creating ProviderNamespace for %s, ' \
'but without references to any Namespaces ' \
'since the Namespace %s already exists'
logger.warning(msg, username, sanitized_username)

models.ProviderNamespace.objects.get_or_create(
name=username, provider=provider,
defaults=provider_ns_defaults)
else:
# Creating a new Namespace

namespace = models.Namespace.objects.create(**ns_defaults)

# Add new user to namespace
namespace.owners.add(user)

models.ProviderNamespace.objects.get_or_create(
namespace=namespace, name=username, provider=provider,
defaults=provider_ns_defaults)


@receiver(post_save, sender=models.ImportTask)
Expand Down
2 changes: 1 addition & 1 deletion galaxy/main/tests/test_login_handler.py
Expand Up @@ -109,4 +109,4 @@ def test_already_duplicate_ns_no_additional_ns(self):

new_provider_ns = models.ProviderNamespace.objects.get(
name=NAME_UPPER)
assert new_provider_ns.namespace.name.islower()
assert new_provider_ns.namespace is None

0 comments on commit d4f84d3

Please sign in to comment.