Prevent multiple emails from pointing to same collaborator (fixes #78)
This commit is contained in:
parent
c8dead4457
commit
4a07ab80ce
@ -60,6 +60,7 @@ class ServiceForm(forms.ModelForm):
|
|||||||
|
|
||||||
def clean_collaborators(self):
|
def clean_collaborators(self):
|
||||||
collaborators = []
|
collaborators = []
|
||||||
|
users_to_emails = {} # maps users to the email they are listed under as a collaborator
|
||||||
for collaborator_email in self.cleaned_data["collaborators"].split(","):
|
for collaborator_email in self.cleaned_data["collaborators"].split(","):
|
||||||
email = collaborator_email.strip()
|
email = collaborator_email.strip()
|
||||||
if email == "":
|
if email == "":
|
||||||
@ -69,6 +70,10 @@ class ServiceForm(forms.ModelForm):
|
|||||||
).first()
|
).first()
|
||||||
if collaborator_email_linked is None:
|
if collaborator_email_linked is None:
|
||||||
raise forms.ValidationError(f"Email '{email}' is not registered")
|
raise forms.ValidationError(f"Email '{email}' is not registered")
|
||||||
|
user = collaborator_email_linked.user
|
||||||
|
if user in collaborators:
|
||||||
|
raise forms.ValidationError(f"The emails '{email}' and '{users_to_emails[user]}' both correspond to the same user")
|
||||||
|
users_to_emails[user] = email
|
||||||
collaborators.append(collaborator_email_linked.user)
|
collaborators.append(collaborator_email_linked.user)
|
||||||
return collaborators
|
return collaborators
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user