From 4a07ab80ce61ed3d482bbe578b1bd02f904088fa Mon Sep 17 00:00:00 2001 From: "R. Miles McCain" Date: Fri, 28 Aug 2020 17:19:57 +0000 Subject: [PATCH] Prevent multiple emails from pointing to same collaborator (fixes #78) --- shynet/dashboard/forms.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/shynet/dashboard/forms.py b/shynet/dashboard/forms.py index 88eb6f3..29965ab 100644 --- a/shynet/dashboard/forms.py +++ b/shynet/dashboard/forms.py @@ -60,6 +60,7 @@ class ServiceForm(forms.ModelForm): def clean_collaborators(self): 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(","): email = collaborator_email.strip() if email == "": @@ -69,6 +70,10 @@ class ServiceForm(forms.ModelForm): ).first() if collaborator_email_linked is None: 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) return collaborators