From d20c6971576e998625e226fac6acdee283cd3549 Mon Sep 17 00:00:00 2001 From: Magnus Hagander Date: Fri, 14 Aug 2015 12:34:39 +0200 Subject: [PATCH] Ensure duplicate patches aren't created when an invalid msgid is entered --- pgcommitfest/commitfest/forms.py | 10 ++++++++++ pgcommitfest/commitfest/views.py | 3 +++ 2 files changed, 13 insertions(+) diff --git a/pgcommitfest/commitfest/forms.py b/pgcommitfest/commitfest/forms.py index 2a832ae..67205d2 100644 --- a/pgcommitfest/commitfest/forms.py +++ b/pgcommitfest/commitfest/forms.py @@ -3,6 +3,7 @@ from django.forms import ValidationError from django.forms.widgets import HiddenInput from django.db.models import Q from django.contrib.auth.models import User +from django.http import Http404 from selectable.forms.widgets import AutoCompleteSelectMultipleWidget @@ -58,6 +59,15 @@ class NewPatchForm(forms.ModelForm): model = Patch exclude = ('commitfests', 'mailthreads', 'modified', 'authors', 'reviewers', 'committer', 'wikilink', 'gitlink', 'lastmail', ) + def clean_threadmsgid(self): + try: + _archivesAPI('/message-id.json/%s' % self.cleaned_data['threadmsgid']) + except Http404: + raise ValidationError("Message not found in archives") + except: + raise ValidationError("Error in API call to validate thread") + return self.cleaned_data['threadmsgid'] + def _fetch_thread_choices(patch): for mt in patch.mailthread_set.order_by('-latestmessage'): ti = sorted(_archivesAPI('/message-id.json/%s' % mt.messageid), key=lambda x: x['date'], reverse=True) diff --git a/pgcommitfest/commitfest/views.py b/pgcommitfest/commitfest/views.py index ddc579a..6e86743 100644 --- a/pgcommitfest/commitfest/views.py +++ b/pgcommitfest/commitfest/views.py @@ -282,6 +282,9 @@ def newpatch(request, cfid): form._errors['threadmsgid'] = form.error_class(('Selected thread did not exist in the archives',)) except Exception: form._errors['threadmsgid'] = form.error_class(('An error occurred looking up the thread in the archives.',)) + # In this case, we have created a patch - delete it. This causes a agp in id's, but it should + # not happen very often. If we successfully attached to it, we will have already returned. + patch.delete() else: form = NewPatchForm() -- 2.39.5