Create and track a mapping between bug ids and messageids
authorMagnus Hagander <magnus@hagander.net>
Thu, 17 Jan 2019 09:24:55 +0000 (10:24 +0100)
committerMagnus Hagander <magnus@hagander.net>
Thu, 17 Jan 2019 09:29:06 +0000 (10:29 +0100)
Not used yet (though a prototype redirect view is present) since we need
to populate it with data from the past, but with this we start
collecting the mapping for future bugs.

pgweb/misc/migrations/0001_bugidmap.py [new file with mode: 0644]
pgweb/misc/migrations/__init__.py [new file with mode: 0644]
pgweb/misc/models.py
pgweb/misc/views.py
pgweb/urls.py

diff --git a/pgweb/misc/migrations/0001_bugidmap.py b/pgweb/misc/migrations/0001_bugidmap.py
new file mode 100644 (file)
index 0000000..5bcb8e2
--- /dev/null
@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.10 on 2019-01-17 08:41
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    initial = True
+
+    dependencies = [
+    ]
+
+    operations = [
+        migrations.CreateModel(
+            name='BugIdMap',
+            fields=[
+                ('id', models.IntegerField(primary_key=True, serialize=False)),
+                ('messageid', models.CharField(max_length=500)),
+            ],
+        ),
+    ]
diff --git a/pgweb/misc/migrations/__init__.py b/pgweb/misc/migrations/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
index 54f60fe2160bf2f1632a45929af6f2c53fb94c38..90c7e240fa82040c8eaa6442d82ffc3c50aa3373 100644 (file)
@@ -1,3 +1,7 @@
-#from django.db import models
+from django.db import models
 
-# Create your models here.
+class BugIdMap(models.Model):
+       # Explicit id field because we don't want a SERIAL here, since we generate
+       # the actual bug IDs externally.
+       id = models.IntegerField(null=False, blank=False, primary_key=True)
+       messageid = models.CharField(max_length=500, null=False, blank=False)
index 0cd7c861273510dc1a4c2183bc6e4ef5695c41aa..3cf8e3bb107947c8fa40d78ba2311c5e4a46871b 100644 (file)
@@ -1,6 +1,7 @@
 from pgweb.util.decorators import login_required
-from django.http import HttpResponse
-from django.db import connection
+from django.http import HttpResponse, HttpResponseRedirect
+from django.db import connection, transaction
+from django.shortcuts import get_object_or_404
 from django.conf import settings
 
 import os
@@ -12,6 +13,7 @@ from pgweb.util.helpers import template_to_string
 from pgweb.util.misc import send_template_mail
 
 from pgweb.core.models import Version
+from pgweb.misc.models import BugIdMap
 
 from forms import SubmitBugForm
 
@@ -26,29 +28,34 @@ def submitbug(request):
        if request.method == 'POST':
                form = SubmitBugForm(request.POST)
                if form.is_valid():
-                       c = connection.cursor()
-                       c.execute("SELECT nextval('bug_id_seq')")
-                       bugid = c.fetchall()[0][0]
-
-                       send_template_mail(
-                               settings.BUGREPORT_NOREPLY_EMAIL,
-                               settings.BUGREPORT_EMAIL,
-                               'BUG #%s: %s' % (bugid, form.cleaned_data['shortdesc']),
-                               'misc/bugmail.txt',
-                               {
+                       with transaction.atomic():
+                               c = connection.cursor()
+                               c.execute("SELECT nextval('bug_id_seq')")
+                               bugid = c.fetchall()[0][0]
+
+                               messageid = _make_bugs_messageid(bugid)
+
+                               BugIdMap(id=bugid, messageid=messageid.strip('<>')).save()
+
+                               send_template_mail(
+                                       settings.BUGREPORT_NOREPLY_EMAIL,
+                                       settings.BUGREPORT_EMAIL,
+                                       'BUG #%s: %s' % (bugid, form.cleaned_data['shortdesc']),
+                                       'misc/bugmail.txt',
+                                       {
+                                               'bugid': bugid,
+                                               'bug': form.cleaned_data,
+                                       },
+                                       usergenerated=True,
+                                       cc=form.cleaned_data['email'],
+                                       replyto='%s, %s' % (form.cleaned_data['email'], settings.BUGREPORT_EMAIL),
+                                       sendername="PG Bug reporting form",
+                                       messageid=messageid,
+                               )
+
+                               return render_pgweb(request, 'support', 'misc/bug_completed.html', {
                                        'bugid': bugid,
-                                       'bug': form.cleaned_data,
-                               },
-                               usergenerated=True,
-                               cc=form.cleaned_data['email'],
-                               replyto='%s, %s' % (form.cleaned_data['email'], settings.BUGREPORT_EMAIL),
-                               sendername="PG Bug reporting form",
-                               messageid=_make_bugs_messageid(bugid),
-                       )
-
-                       return render_pgweb(request, 'support', 'misc/bug_completed.html', {
-                               'bugid': bugid,
-                       })
+                               })
        else:
                form = SubmitBugForm(initial={
                        'name': '%s %s' % (request.user.first_name, request.user.last_name),
@@ -69,6 +76,11 @@ def submitbug(request):
        })
 
 
+def bugs_redir(request, bugid):
+       r = get_object_or_404(BugIdMap, id=bugid)
+
+       return HttpResponseRedirect("{0}/message-id/{1}".format(settings.SITE_ROOT, r.messageid))
+
 # A crash testing URL. If the file /tmp/crashtest exists, raise a http 500
 # error. Otherwise, just return a fixed text response
 def crashtest(request):
index 56f6a3fe174e4927b5eec72e2a5a966be3aba5e8..615a6a85a427850427a14e6c752bd1ccb172a82c 100644 (file)
@@ -83,6 +83,7 @@ urlpatterns = [
        url(r'^account/submitbug/$', pgweb.misc.views.submitbug),
        url(r'^support/submitbug/$', RedirectView.as_view(url='/account/submitbug/', permanent=True)),
        url(r'^support/versioning/$', pgweb.core.views.versions),
+       url(r'^bugs_redir/(\d+)/$', pgweb.misc.views.bugs_redir),
 
        url(r'^about/sponsors/$', pgweb.sponsors.views.sponsors),
        url(r'^about/servers/$', pgweb.sponsors.views.servers),