[extensions-web] Require an authenticated user when submitting an error report
- From: Jasper St. Pierre <jstpierre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [extensions-web] Require an authenticated user when submitting an error report
- Date: Tue, 1 Nov 2011 14:47:43 +0000 (UTC)
commit 9cc0c5d5b6ceaa67c4cba0e0ec2f30b5ae9cd9be
Author: Jasper St. Pierre <jstpierre mecheye net>
Date: Mon Oct 31 17:23:58 2011 -0400
Require an authenticated user when submitting an error report
sweettooth/errorreports/admin.py | 2 +-
.../0003_auto__del_field_errorreport_email.py | 97 ++++++++++++++++++++
sweettooth/errorreports/models.py | 19 +----
.../templates/errorreports/report.html | 9 --
.../errorreports/templates/errorreports/view.html | 2 +-
sweettooth/errorreports/views.py | 10 +-
6 files changed, 104 insertions(+), 35 deletions(-)
---
diff --git a/sweettooth/errorreports/admin.py b/sweettooth/errorreports/admin.py
index 6a96a6a..66035b6 100644
--- a/sweettooth/errorreports/admin.py
+++ b/sweettooth/errorreports/admin.py
@@ -4,7 +4,7 @@ from django.contrib import admin
from errorreports.models import ErrorReport
class ErrorReportAdmin(admin.ModelAdmin):
- list_display = 'user_display', 'extension', 'version_num'
+ list_display = 'extension', 'version_num'
list_display_links = list_display
def version_num(self, report):
diff --git a/sweettooth/errorreports/migrations/0003_auto__del_field_errorreport_email.py b/sweettooth/errorreports/migrations/0003_auto__del_field_errorreport_email.py
new file mode 100644
index 0000000..e627dc3
--- /dev/null
+++ b/sweettooth/errorreports/migrations/0003_auto__del_field_errorreport_email.py
@@ -0,0 +1,97 @@
+# encoding: utf-8
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+class Migration(SchemaMigration):
+
+ def forwards(self, orm):
+
+ # Deleting field 'ErrorReport.email'
+ db.delete_column('errorreports_errorreport', 'email')
+
+
+ def backwards(self, orm):
+
+ # Adding field 'ErrorReport.email'
+ db.add_column('errorreports_errorreport', 'email', self.gf('django.db.models.fields.EmailField')(default='', max_length=75, blank=True), keep_default=False)
+
+
+ models = {
+ 'auth.group': {
+ 'Meta': {'object_name': 'Group'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+ 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+ },
+ 'auth.permission': {
+ 'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+ 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+ },
+ 'auth.user': {
+ 'Meta': {'object_name': 'User'},
+ 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+ 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+ 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+ 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+ 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+ 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+ 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+ 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+ },
+ 'contenttypes.contenttype': {
+ 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+ 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+ },
+ 'errorreports.errorreport': {
+ 'Meta': {'object_name': 'ErrorReport'},
+ 'comment': ('django.db.models.fields.TextField', [], {'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'+'", 'to': "orm['auth.User']"}),
+ 'version': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['extensions.ExtensionVersion']"})
+ },
+ 'extensions.extension': {
+ 'Meta': {'object_name': 'Extension'},
+ 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+ 'creator': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']"}),
+ 'description': ('django.db.models.fields.TextField', [], {}),
+ 'icon': ('django.db.models.fields.files.ImageField', [], {'default': "'/static/images/plugin.png'", 'max_length': '100', 'blank': 'True'}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '200'}),
+ 'screenshot': ('sorl.thumbnail.fields.ImageField', [], {'max_length': '100', 'blank': 'True'}),
+ 'slug': ('autoslug.fields.AutoSlugField', [], {'unique_with': '()', 'max_length': '50', 'populate_from': 'None', 'db_index': 'True'}),
+ 'url': ('django.db.models.fields.URLField', [], {'max_length': '200'}),
+ 'uuid': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '200', 'db_index': 'True'})
+ },
+ 'extensions.extensionversion': {
+ 'Meta': {'unique_together': "(('extension', 'version'),)", 'object_name': 'ExtensionVersion'},
+ 'extension': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'versions'", 'to': "orm['extensions.Extension']"}),
+ 'extra_json_fields': ('django.db.models.fields.TextField', [], {}),
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'shell_versions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['extensions.ShellVersion']", 'symmetrical': 'False'}),
+ 'source': ('django.db.models.fields.files.FileField', [], {'max_length': '223'}),
+ 'status': ('django.db.models.fields.PositiveIntegerField', [], {}),
+ 'version': ('django.db.models.fields.IntegerField', [], {'default': '0'})
+ },
+ 'extensions.shellversion': {
+ 'Meta': {'object_name': 'ShellVersion'},
+ 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+ 'major': ('django.db.models.fields.PositiveIntegerField', [], {}),
+ 'minor': ('django.db.models.fields.PositiveIntegerField', [], {}),
+ 'point': ('django.db.models.fields.IntegerField', [], {})
+ }
+ }
+
+ complete_apps = ['errorreports']
diff --git a/sweettooth/errorreports/models.py b/sweettooth/errorreports/models.py
index 0e7c5fa..9935df5 100644
--- a/sweettooth/errorreports/models.py
+++ b/sweettooth/errorreports/models.py
@@ -7,25 +7,8 @@ from extensions.models import ExtensionVersion
class ErrorReport(models.Model):
comment = models.TextField(blank=True)
- # In the case that a user isn't logged in, they can supply an optional
- # email address for the extension author to reply to.
- email = models.EmailField(blank=True)
-
- user = models.ForeignKey(auth.models.User, blank=True, related_name="+")
+ user = models.ForeignKey(auth.models.User, related_name="+")
version = models.ForeignKey(ExtensionVersion)
- @property
- def user_email(self):
- if self.user:
- return self.user.email
- else:
- return self.email
-
- @property
- def user_display(self):
- if self.user:
- return self.user.username
- else:
- return self.email
error_reported = Signal(providing_args=["version", "report"])
diff --git a/sweettooth/errorreports/templates/errorreports/report.html b/sweettooth/errorreports/templates/errorreports/report.html
index 19f83bd..afb5ce9 100644
--- a/sweettooth/errorreports/templates/errorreports/report.html
+++ b/sweettooth/errorreports/templates/errorreports/report.html
@@ -11,15 +11,6 @@
<h3> Comments for the author </h3>
<textarea name="comment" id="comment"></textarea>
- {% if not request.user.is_authenticated %}
- <h3> Email address </h3>
- <p>You're not <a href="{% url auth-login %}">logged in</a>.
- In order for the extension author to contact you, you need to provide an email address.
- </p>
-
- <input type="email" name="email" value="">
- {% endif %}
-
<input type="submit" value="Report Errors">
</form>
{% endblock %}
diff --git a/sweettooth/errorreports/templates/errorreports/view.html b/sweettooth/errorreports/templates/errorreports/view.html
index e65197e..0636298 100644
--- a/sweettooth/errorreports/templates/errorreports/view.html
+++ b/sweettooth/errorreports/templates/errorreports/view.html
@@ -1,7 +1,7 @@
{% extends "base.html" %}
{% block title %}Error report on "{{ report.version.extension.name }}" — {{ block.super }}{% endblock %}
{% block body %}
-<h2><em>{{ report.user_display }}'s report for "{{ report.version.extension.name }}"</em></h2>
+<h2><em>{{ report.user }}'s report for "{{ report.version.extension.name }}"</em></h2>
<div id="error_report">
<h3> Comments for the author </h3>
diff --git a/sweettooth/errorreports/views.py b/sweettooth/errorreports/views.py
index 8e34fb3..ad3cf7c 100644
--- a/sweettooth/errorreports/views.py
+++ b/sweettooth/errorreports/views.py
@@ -1,5 +1,6 @@
from django.contrib import messages
+from django.http import HttpResponseForbidden
from django.shortcuts import redirect
from errorreports.models import ErrorReport, error_reported
@@ -15,15 +16,12 @@ def report_error_view(request, obj):
if request.method == 'POST':
comment = request.POST['comment']
- if request.user.is_authenticated():
- user, email = request.user, ""
- else:
- user, email = None, request.POST['email']
+ if not request.user.is_authenticated():
+ return HttpResponseForbidden()
report = ErrorReport(version=version,
comment=comment,
- user=user,
- email=email)
+ user=request.user)
report.save()
error_reported.send(sender=request, version=version, report=report)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]