Skip to content

Commit

Permalink
Prevents user from adding themselves as a references
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas-Mc committed Feb 4, 2021
1 parent dabf985 commit c0cd3e1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 11 additions & 1 deletion physionet-django/user/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,12 @@ class Meta:
'reference_title': 'Reference job title or position'
}

def __init__(self, user, *args, **kwargs):
"""
This form is only for processing post requests.
"""
super().__init__(*args, **kwargs)
self.user = user

def clean_reference_name(self):
reference_name = self.cleaned_data.get('reference_name')
Expand All @@ -454,7 +460,11 @@ def clean_reference_name(self):
def clean_reference_email(self):
reference_email = self.cleaned_data.get('reference_email')
if reference_email:
return reference_email.strip()
if reference_email in self.user.get_emails():
raise forms.ValidationError("""You can not put yourself
as a reference.""")
else:
return reference_email.strip()

def clean_reference_title(self):
reference_title = self.cleaned_data.get('reference_title')
Expand Down
4 changes: 2 additions & 2 deletions physionet-django/user/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def credential_application(request):
training_form = forms.TrainingCAF(data=request.POST,
files=request.FILES, prefix="application")
research_form = forms.ResearchCAF(data=request.POST, prefix="application")
reference_form = forms.ReferenceCAF(data=request.POST, prefix="application")
reference_form = forms.ReferenceCAF(data=request.POST, prefix="application", user=user)

form = forms.CredentialApplicationForm(user=user, data=request.POST,
files=request.FILES, prefix="application")
Expand All @@ -539,7 +539,7 @@ def credential_application(request):
else:
personal_form = forms.PersonalCAF(user=user, prefix="application")
training_form = forms.TrainingCAF(prefix="application")
reference_form = forms.ReferenceCAF(prefix="application")
reference_form = forms.ReferenceCAF(prefix="application", user=user)
research_form = forms.ResearchCAF(prefix="application")
form = None

Expand Down

0 comments on commit c0cd3e1

Please sign in to comment.