]> git.ozlabs.org Git - patchwork/commitdiff
bundles: Don't allow slashes in bundle names
authorJeremy Kerr <jk@ozlabs.org>
Sat, 20 Apr 2013 14:34:28 +0000 (22:34 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Sat, 20 Apr 2013 14:45:20 +0000 (22:45 +0800)
Because bundle names are used in URLs, we don't want slashes in them.

Include a SQL migration script.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
apps/patchwork/forms.py
apps/patchwork/utils.py
lib/sql/migration/013-bundle-names.sql [new file with mode: 0644]

index d5e51a2c8b9dfcc52954b13e95bb3d774f0b03c2..82197696588b3ced6f8a86bf71e7db18d8e0dc4b 100644 (file)
@@ -58,11 +58,14 @@ class LoginForm(forms.Form):
     password = forms.CharField(widget = forms.PasswordInput)
 
 class BundleForm(forms.ModelForm):
     password = forms.CharField(widget = forms.PasswordInput)
 
 class BundleForm(forms.ModelForm):
+    name = forms.RegexField(regex = r'^[^/]+$', max_length=50, label=u'Name',
+            error_messages = {'invalid': 'Bundle names can\'t contain slashes'})
+
     class Meta:
         model = Bundle
         fields = ['name', 'public']
 
     class Meta:
         model = Bundle
         fields = ['name', 'public']
 
-class CreateBundleForm(forms.ModelForm):
+class CreateBundleForm(BundleForm):
     def __init__(self, *args, **kwargs):
         super(CreateBundleForm, self).__init__(*args, **kwargs)
 
     def __init__(self, *args, **kwargs):
         super(CreateBundleForm, self).__init__(*args, **kwargs)
 
index 1771167ae12f35fb55479c35aa865be496ce2664..f48e7a59a341ada3bc9a1465c809f181dac4cd3a 100644 (file)
@@ -105,6 +105,9 @@ def set_bundle(user, project, action, data, patches, context):
     bundle = None
     if action == 'create':
         bundle_name = data['bundle_name'].strip()
     bundle = None
     if action == 'create':
         bundle_name = data['bundle_name'].strip()
+        if '/' in bundle_name:
+            return ['Bundle names can\'t contain slashes']
+
         if not bundle_name:
             return ['No bundle name was specified']
 
         if not bundle_name:
             return ['No bundle name was specified']
 
diff --git a/lib/sql/migration/013-bundle-names.sql b/lib/sql/migration/013-bundle-names.sql
new file mode 100644 (file)
index 0000000..3dbbfb1
--- /dev/null
@@ -0,0 +1,6 @@
+BEGIN;
+UPDATE patchwork_bundle
+       SET name = replace(name, '/', '-')
+       WHERE name like '%/%';
+COMMIT;
+