diff --git a/pwm b/pwm index c9a87c7560c82602b77816c102570210f0f8420e..2d30be1df337bfeff167c000589cfb10f9b2ec66 100755 --- a/pwm +++ b/pwm @@ -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: