Commit e6238699 authored by stef's avatar stef
Browse files

[enh] added confirmation of reports

parent 6ec7b34d
...@@ -63,6 +63,9 @@ class Violation(models.Model): ...@@ -63,6 +63,9 @@ class Violation(models.Model):
loophole = models.BooleanField() loophole = models.BooleanField()
activationid= models.CharField(max_length=128) activationid= models.CharField(max_length=128)
def confirmations(self):
return self.confirmation_set.filter(key='').count()
class Comment(models.Model): class Comment(models.Model):
submitter_email = models.EmailField() submitter_email = models.EmailField()
submitter_name = models.CharField(max_length=20) submitter_name = models.CharField(max_length=20)
...@@ -75,6 +78,11 @@ class Attachment(models.Model): ...@@ -75,6 +78,11 @@ class Attachment(models.Model):
name= models.CharField(max_length=512) name= models.CharField(max_length=512)
comment = models.ForeignKey(Comment) comment = models.ForeignKey(Comment)
class Confirmation(models.Model):
key=models.CharField(max_length=64)
email=models.EmailField()
violation = models.ForeignKey(Violation)
class ViolationModerator(CommentModerator): class ViolationModerator(CommentModerator):
email_notification = True email_notification = True
moderate_after = 0 moderate_after = 0
......
...@@ -7,7 +7,8 @@ from django.conf import settings ...@@ -7,7 +7,8 @@ from django.conf import settings
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.contrib import messages from django.contrib import messages
from models import Violation, Attachment, Comment from django.utils.translation import ugettext_lazy as _
from models import Violation, Attachment, Comment, Confirmation
from tempfile import mkstemp from tempfile import mkstemp
from datetime import datetime from datetime import datetime
import hashlib, os, re, json, smtplib import hashlib, os, re, json, smtplib
...@@ -48,18 +49,35 @@ def activate(request): ...@@ -48,18 +49,35 @@ def activate(request):
messages.add_message(request, messages.INFO, _('Thank you for verifying your submission.')) messages.add_message(request, messages.INFO, _('Thank you for verifying your submission.'))
return HttpResponseRedirect('/') # Redirect after POST return HttpResponseRedirect('/') # Redirect after POST
def confirm(request, id, name=None):
if name:
if Confirmation.objects.filter(email=name, violation=id).count()==0:
actid=sendverifymail('confirm/',name)
c=Confirmation(key=actid, email=name, violation=Violation.objects.get(pk=id))
c.save()
return HttpResponse('<div class="confirm_thanks">Thank you for your confirmation</div>')
c=Confirmation.objects.get(key=id)
if c:
c.key=''
c.save()
return HttpResponse('<div class="confirm_thanks">Thank you for verifying your confirmation</div>')
def sendverifymail(service,to):
actid = hashlib.sha1(''.join([chr(randint(32, 122)) for x in range(12)])).hexdigest()
msg = MIMEText(_("Your verification key is %s/%s%s\n") % (settings.ROOT_URL or 'http://localhost:8001/', service, actid))
msg['Subject'] = _('NNMon submission verification')
msg['From'] = 'nnmon@nnmon.lqdn.fr'
msg['To'] = to
s = smtplib.SMTP('localhost')
s.sendmail('nnmon@nnmon.lqdn.fr', [to], msg.as_string())
s.quit()
return actid
def add(request): def add(request):
if request.method == 'POST': if request.method == 'POST':
form = AddViolation(request.POST) form = AddViolation(request.POST)
if form.is_valid(): if form.is_valid():
actid = hashlib.sha1(''.join([chr(randint(32, 122)) for x in range(12)])).hexdigest() actid=sendverifymail('activate?key=',form.cleaned_data['email'])
msg = MIMEText(_("Your verification key is %s/activate?key=%s\n") % (settings.ROOT_URL or 'http://localhost:8001/',actid))
msg['Subject'] = _('NNMon submission verification')
msg['From'] = 'nnmon@nnmon.lqdn.fr'
msg['To'] = form.cleaned_data['email']
s = smtplib.SMTP('localhost')
s.sendmail('nnmon@nnmon.lqdn.fr', [form.cleaned_data['email']], msg.as_string())
s.quit()
v=Violation( v=Violation(
country = form.cleaned_data['country'], country = form.cleaned_data['country'],
operator = form.cleaned_data['operator'], operator = form.cleaned_data['operator'],
......
...@@ -21,6 +21,11 @@ li { list-style: none; } ...@@ -21,6 +21,11 @@ li { list-style: none; }
#report dd { display: inline; } #report dd { display: inline; }
#auth { float: right; clear: both; } #auth { float: right; clear: both; }
.confirm { display: inline; position: relative; }
.confirm:hover > div { display: block; }
.confirm_popup { display: none; position: absolute; right: 0; border: 2px solid #454545; padding: 10px; background: #F7F7F7; z-index: 20; }
.confirm_thanks { width: 17.2em; height: 6.7em; }
table.listing, .pagination { width: 90%; margin: auto; } table.listing, .pagination { width: 90%; margin: auto; }
table.listing thead td { font-weight: bold; border-bottom: 1px solid black; } table.listing thead td { font-weight: bold; border-bottom: 1px solid black; }
......
...@@ -9,7 +9,12 @@ ...@@ -9,7 +9,12 @@
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
$("#sortedlist").tablesorter(); $("#sortedlist").tablesorter();
}); $('.confirm_form').submit(function() {
var self=this;
$.ajax({url: '/confirm/'+$(this).attr('id')+'/'+$(this).children('input:first').attr('value'), success: function(data) { $(self).html(data); }});
return false;
});
});
</script> </script>
{% endblock %} {% endblock %}
...@@ -35,6 +40,7 @@ ...@@ -35,6 +40,7 @@
<th>{% trans "contractual" %}</th> <th>{% trans "contractual" %}</th>
<th>{% trans "contractual_excerpt" %}</th> <th>{% trans "contractual_excerpt" %}</th>
<th>{% trans "loophole" %}</th> <th>{% trans "loophole" %}</th>
<th>{% trans "confirmations" %}</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
...@@ -51,6 +57,20 @@ ...@@ -51,6 +57,20 @@
<td>{{ violation.contractual }}</td> <td>{{ violation.contractual }}</td>
<td>{{ violation.contractual_excerpt }}</td> <td>{{ violation.contractual_excerpt }}</td>
<td>{{ violation.loophole }}</td> <td>{{ violation.loophole }}</td>
<td>{{ violation.confirmations }} <div class="confirm"><a>Confirm this violation</a>
<div class="hidden confirm_popup">
<h3>Confirmation</h3>
<p>
<form method="get" class="confirm_form" id="{{ violation.pk }}">
E-mail: <input type="text" name="email" /><br />
//required<br />
<input type="hidden" value="{{ violation.pk }}" />
<input type="submit" value="confirm" />
</form>
</p>
</div>
</div>
</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
......
...@@ -11,6 +11,8 @@ urlpatterns = patterns('', ...@@ -11,6 +11,8 @@ urlpatterns = patterns('',
(r'^add/$', bt.add), (r'^add/$', bt.add),
(r'^view/(?P<id>[0-9]*)$', bt.view), (r'^view/(?P<id>[0-9]*)$', bt.view),
(r'^activate/$', bt.activate), (r'^activate/$', bt.activate),
(r'^confirm/(?P<id>[0-9a-z]*)$', bt.confirm),
(r'^confirm/(?P<id>[0-9]*)/(?P<name>.*)$', bt.confirm),
(r'^accounts/logout$', 'django.contrib.auth.views.logout', {'next_page' : '/'}), (r'^accounts/logout$', 'django.contrib.auth.views.logout', {'next_page' : '/'}),
(r'^accounts/', include('registration.urls')), (r'^accounts/', include('registration.urls')),
(r'^comments/', include('django.contrib.comments.urls')), (r'^comments/', include('django.contrib.comments.urls')),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment