From bca90990b715b375f143c38d529591f589a728fc Mon Sep 17 00:00:00 2001 From: James Tanner Date: Thu, 5 Oct 2023 14:52:53 -0400 Subject: [PATCH] checkin --- .../check_validated_user_namespace_map.py | 70 ++++++++++++++++--- 1 file changed, 62 insertions(+), 8 deletions(-) diff --git a/dev/scripts.community/check_validated_user_namespace_map.py b/dev/scripts.community/check_validated_user_namespace_map.py index 0fd3d52972..9c3ece660a 100644 --- a/dev/scripts.community/check_validated_user_namespace_map.py +++ b/dev/scripts.community/check_validated_user_namespace_map.py @@ -6,6 +6,8 @@ from galaxy_ng.app.models import Namespace from galaxy_ng.app.api.v1.models import LegacyNamespace +from galaxy_ng.app.utils.namespaces import generate_v3_namespace_from_attributes +from galaxy_ng.app.utils import rbac User = get_user_model() @@ -25,29 +27,81 @@ def do_check(): uids = list(umap.keys()) uids = sorted(uids, key=lambda x: int(x)) for uid in uids: - print(uid) - old_data = umap[uid] + print(f"{uid} {old_data['galaxy_username']}") + + # worry about these later ... if not old_data.get('github_login_verified'): continue + # worry about these later ... + if old_data['galaxy_username'] != old_data['github_login'] or \ + (old_data.get('gitub_login_new') and old_data.get('gitub_login_new') != old_data['galaxy_username']): + continue + galaxy_username = old_data['galaxy_username'] github_login = old_data['github_login'] + github_id = old_data['github_id'] if old_data['github_login_new']: github_login = old_data['github_login_new'] - # worry about this later ... - if galaxy_username != github_login: - continue - + # find or make the user ... found_user = User.objects.filter(username=galaxy_username).first() if not found_user: print(f'\tFIX - create user {galaxy_username}') if not checkmode: print(f'\t\tcheckmode:{checkmode} do user create ...') found_user, _ = User.objects.get_or_create(username=galaxy_username) - - #import epdb; epdb.st() + else: + continue + + # check each owned namespace (v1+v3) ... + for ns_name in old_data.get('owned_namespaces', []): + found_v1_namespace = LegacyNamespace.objects.filter(name=ns_name).first() + if not found_v1_namespace: + print(f'\tFIX - create legacy namespace {ns_name}') + if not checkmode: + print(f'\t\tcheckmode:{checkmode} do legacy ns create ...') + found_v1_namespace,_ = LegacyNamespace.objects.get_or_create(name=ns_name) + else: + continue + + # the v3 namespace has to be valid ... + v3_ns_name = generate_v3_namespace_from_attributes(username=ns_name) + # print(f'\tv3:{v3_ns_name}') + + found_v3_namespace = Namespace.objects.filter(name=v3_ns_name).first() + if not found_v3_namespace: + print(f'\tFIX - create v3 namespace {v3_ns_name}') + if not checkmode: + print(f'\t\tcheckmode:{checkmode} do v3 ns create ...') + found_v3_namespace,_ = Namespace.objects.get_or_create(name=v3_ns_name) + else: + continue + + # bind v3 to v1 ... + if found_v1_namespace.namespace != found_v3_namespace: + print(f'\tFIX - bind v3:{found_v3_namespace} to v1:{found_v1_namespace}') + if not checkmode: + print(f'\t\tcheckmode:{checkmode} do v3->v1 bind ...') + try: + found_v1_namespace.namespace = found_v3_namespace + found_v1_namespace.save() + except ValueError: + import epdb; epdb.st() + else: + continue + + current_owners = rbac.get_v3_namespace_owners(found_v3_namespace) + if found_user not in current_owners: + print(f'\tFIX - add {found_user} as owner of v3:{found_v3_namespace}') + if not checkmode: + print(f'\t\tcheckmode:{checkmode} do owner add...') + rbac.add_user_to_v3_namespace(found_user, found_v3_namespace) + else: + continue + + #import epdb; epdb.st()