Skip to content

Commit

Permalink
SRAM: only sync users with a valid email
Browse files Browse the repository at this point in the history
  • Loading branch information
lwesterhof committed Nov 16, 2023
1 parent c5bedd5 commit 6cda601
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
__copyright__ = 'Copyright (c) 2018-2023, Utrecht University'
__license__ = 'GPLv3, see LICENSE'

import re
import time
from collections import OrderedDict
from datetime import datetime
Expand Down Expand Up @@ -1181,12 +1180,9 @@ def api_group_user_add(ctx, username, group_name):
if config.enable_sram:
sram_group, co_identifier = sram_enabled(ctx, group_name)
if sram_group:
# Email regex.
regex = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,7}\b'

# Validate email
if not re.match(regex, username):
return api.Error('invalid_email', 'The user {} cannot be added to the group {} because user email is invalid'.format(username, group_name))
if not yoda_names.is_email_username(username):
return api.Error('invalid_email', 'User {} cannot be added to group {} because user email is invalid'.format(username, group_name))

response = ctx.uuGroupUserAdd(group_name, username, '', '')['arguments']
status = response[2]
Expand Down Expand Up @@ -1354,6 +1350,10 @@ def rule_group_sram_sync(ctx):

log.write(ctx, "Sync members of group {} with SRAM".format(group_name))
for member in members:
# Validate email
if not yoda_names.is_email_username(member):
log.write(ctx, "User {} cannot be added to group {} because user email is invalid".format(member, group_name))

if config.sram_flow == 'join_request':
sram.invitation_mail_group_add_user(ctx, group_name, member.split('#')[0], co_identifier)
elif config.sram_flow == 'invitation':
Expand Down

0 comments on commit 6cda601

Please sign in to comment.