Skip to content
Snippets Groups Projects
Commit 1eaa9f09 authored by Guillaume Chanel's avatar Guillaume Chanel
Browse files

Improve student search heuristic

Stop the search if . is reached
Stop the search if more than one user is returned
In both cases interrupt script and exit
parent ca6bddf4
No related branches found
No related tags found
No related merge requests found
Pipeline #20032 failed
......@@ -62,10 +62,9 @@ def emails_to_ids(emails: List[str], headers: Dict[str, str]) -> List[int]:
for email in emails:
# Dirty and hackish way that attempts to extract the username from the email.
# It's inefficient, but currently there is now way to reliably obtain
# It's inefficient, but currently there is no way to reliably obtain
# the username from the email.
# TODO: new strategy:
# - stop when we reach the "." or when we get more than 1 result
# new strategy: - stop when we reach the "." or when we get more than 1 result
# Example of tricky users:
# pierre-louis.roden@etu.hesge.ch -> login AAI: pierrelo.roden
# joel.ferreirapinto@etu.hesge.ch -> login AAI: joelfili.ferreira
......@@ -76,11 +75,17 @@ def emails_to_ids(emails: List[str], headers: Dict[str, str]) -> List[int]:
#print("Guessed username: ",username)
user_requested = requests.get(BASE_API_URL + '/users', params={'search': username}, headers=headers).json()
if len(user_requested) == 0:
nb_users = len(user_requested)
if nb_users == 0:
#print('No user %s found, another try...' % email)
lastchar = username[-1]
username = username.rstrip(lastchar)
if username[-1] == '.': # stop if we reach the . -> probably at least one wrong person match the first name
break
continue
elif nb_users > 1:
print('Too many users found for email %s, aborting.' % email)
exit(1)
#print(json.dumps(user_requested, indent=4))
user_ids.append(user_requested[0]['id'])
......@@ -118,7 +123,7 @@ def create_repository(token: str, group_id: str, emails: List[str], name: str, i
# Get students ids from their emails
user_ids = emails_to_ids(emails, headers)
# Add each student as project's developer (level 30)
# Add each student as maintainer (level 40)
for user_id in user_ids:
params = {'user_id': user_id, 'access_level': access_level}
if expires_at:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment