[extensions-web] Validate user UUIDs against guidelines



commit 54291b0e46e1a25e63dd7514a6588ee337cfca89
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Wed Oct 26 14:35:39 2011 -0400

    Validate user UUIDs against guidelines

 sweettooth/extensions/models.py                    |   16 ++++++++++++++++
 .../extensions/templates/extensions/upload.html    |    2 +-
 2 files changed, 17 insertions(+), 1 deletions(-)
---
diff --git a/sweettooth/extensions/models.py b/sweettooth/extensions/models.py
index c687e55..5456dbe 100644
--- a/sweettooth/extensions/models.py
+++ b/sweettooth/extensions/models.py
@@ -13,6 +13,7 @@ from django.db import models
 from django.dispatch import Signal
 
 import autoslug
+import re
 from sorl import thumbnail
 
 (STATUS_NEW, STATUS_LOCKED,
@@ -31,6 +32,15 @@ VISIBLE_STATUSES = (STATUS_ACTIVE,)
 REJECTED_STATUSES = (STATUS_REJECTED,)
 REVIEWED_STATUSES = (STATUS_REJECTED, STATUS_INACTIVE, STATUS_ACTIVE)
 
+def validate_uuid(uuid):
+    if re.match('[-a-zA-Z0-9  ]+$', uuid) is None:
+        return False
+
+    if uuid.endswith('.gnome.org'):
+        return False
+
+    return True
+
 class ExtensionManager(models.Manager):
     def visible(self):
         return self.filter(versions__status__in=VISIBLE_STATUSES).distinct()
@@ -82,6 +92,12 @@ class Extension(models.Model):
             return True
         return False
 
+    def clean(self):
+        from django.core.exceptions import ValidationError
+
+        if not validate_uuid(self.uuid):
+            raise ValidationError("Invalid UUID")
+
 class InvalidShellVersion(Exception):
     pass
 
diff --git a/sweettooth/extensions/templates/extensions/upload.html b/sweettooth/extensions/templates/extensions/upload.html
index 84d7adf..7883079 100644
--- a/sweettooth/extensions/templates/extensions/upload.html
+++ b/sweettooth/extensions/templates/extensions/upload.html
@@ -3,7 +3,7 @@
 <div class="step upload">
   <h2 class="steptitle">Step <span>1</span></h2>
   <p>
-    Make your extension. It should be a zip file containing at least the two files <code class="file required">metadata.json</code> and <code class="file required">extension.js</code>
+    Make your extension. It should be a zip file containing at least the two files <code class="file required">metadata.json</code> and <code class="file required">extension.js</code>. Note that the UUID inside your <code class="file">metadata.json</span> must conform to GNOME Shell UUID guidelines. These guidelines can be found on <a href="https://live.gnome.org/GnomeShell/Extensions/UUIDGuidelines";>the GNOME Wiki</a>.
   </p>
 
   <p>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]