فهرست منبع

HUE-6109 [core] Remove the restriction on Document2 invalid chars

Jenny Kim 8 سال پیش
والد
کامیت
20ba1c1

+ 7 - 3
desktop/core/src/desktop/converter_tests.py

@@ -159,7 +159,7 @@ class TestDocumentConverter(object):
       query.delete()
       query2.delete()
 
-  def test_convert_hive_query_with_invalid_name(self):
+  def test_convert_hive_query_with_special_chars(self):
     sql = 'SELECT * FROM sample_07'
     settings = [
       {'key': 'hive.exec.scratchdir', 'value': '/tmp/mydir'},
@@ -188,8 +188,12 @@ class TestDocumentConverter(object):
       assert_equal(1, Document2.objects.filter(owner=self.user, type='query-hive').count())
 
       doc2 = Document2.objects.get(owner=self.user, type='query-hive', is_history=False)
-      # Verify Document2 name is stripped of invalid chars
-      assert_equal('Test  Hive query', doc2.data_dict['name'])
+
+      # Verify name is maintained
+      assert_equal('Test / Hive query', doc2.name)
+
+      # Verify Document2 path is stripped of invalid chars
+      assert_equal('/Test%20/%20Hive%20query', doc2.path)
     finally:
       query.delete()
 

+ 1 - 4
desktop/core/src/desktop/converters.py

@@ -17,15 +17,13 @@
 
 import json
 import logging
-import re
 import time
 
 from django.db import transaction
 from django.utils.translation import ugettext as _
 
 from desktop.lib.exceptions_renderable import PopupException
-from desktop.models import Document, DocumentPermission, DocumentTag, Document2, Directory, Document2Permission, \
-  DOC2_NAME_INVALID_CHARS
+from desktop.models import Document, DocumentPermission, DocumentTag, Document2, Directory, Document2Permission
 from notebook.api import _historify
 from notebook.models import import_saved_beeswax_query
 
@@ -218,7 +216,6 @@ class DocumentConverter(object):
     try:
       with transaction.atomic():
         name = name if name else document.name
-        name = re.sub(DOC2_NAME_INVALID_CHARS, '', name)
 
         document2 = Document2.objects.create(
           owner=self.user,

+ 4 - 10
desktop/core/src/desktop/models.py

@@ -19,7 +19,7 @@ import calendar
 import json
 import logging
 import os
-import re
+import urllib
 import uuid
 
 from itertools import chain
@@ -53,8 +53,6 @@ SAMPLE_USER_OWNERS = ['hue', 'sample']
 UTC_TIME_FORMAT = "%Y-%m-%dT%H:%MZ"
 HUE_VERSION = None
 
-DOC2_NAME_INVALID_CHARS = "[<>/~`]"
-
 
 def uuid_default():
   return str(uuid.uuid4())
@@ -1076,10 +1074,11 @@ class Document2(models.Model):
 
   @property
   def path(self):
+    quoted_name = urllib.quote(self.name)
     if self.parent_directory:
-      return '%s/%s' % (self.parent_directory.path, self.name)
+      return '%s/%s' % (self.parent_directory.path, quoted_name)
     else:
-      return self.name
+      return quoted_name
 
   @property
   def dirname(self):
@@ -1195,11 +1194,6 @@ class Document2(models.Model):
     self.inherit_permissions()
 
   def validate(self):
-    # Validate document name
-    invalid_chars = re.findall(re.compile(DOC2_NAME_INVALID_CHARS), self.name)
-    if invalid_chars:
-      raise FilesystemException(_('Document %s contains some special characters: %s') % (self.name, ', '.join(invalid_chars)))
-
     # Validate home and Trash directories are only created once per user and cannot be created or modified after
     if self.name in [Document2.HOME_DIR, Document2.TRASH_DIR] and self.type == 'directory' and \
           Document2.objects.filter(name=self.name, owner=self.owner, type='directory').exists():

+ 0 - 9
desktop/core/src/desktop/tests_doc2.py

@@ -323,15 +323,6 @@ class TestDocument2(object):
     assert_equal(Document2.TRASH_DIR, data['children'][0]['name'])
 
 
-  def test_validate_name(self):
-    # Test invalid names
-    invalid_name = '/invalid'
-    response = self.client.post('/desktop/api2/doc/mkdir', {'parent_uuid': json.dumps(self.home_dir.uuid), 'name': json.dumps(invalid_name)})
-    data = json.loads(response.content)
-    assert_equal(-1, data['status'], data)
-    assert_true("contains some special characters: /" in data['message'])
-
-
   def test_validate_immutable_user_directories(self):
     # Test that home and Trash directories cannot be recreated or modified
     test_dir = Directory.objects.create(name='test_dir', owner=self.user, parent_directory=self.home_dir)

+ 1 - 3
desktop/libs/notebook/src/notebook/models.py

@@ -18,13 +18,11 @@
 import json
 import math
 import numbers
-import re
 import uuid
 
 from django.utils.html import escape
 
 from desktop.lib.i18n import smart_unicode
-from desktop.models import DOC2_NAME_INVALID_CHARS
 
 from notebook.connectors.base import Notebook
 
@@ -192,7 +190,7 @@ def import_saved_beeswax_query(bquery):
   design = bquery.get_design()
 
   return make_notebook(
-      name=re.sub(DOC2_NAME_INVALID_CHARS, '', bquery.name),
+      name=bquery.name,
       description=bquery.desc,
       editor_type=_convert_type(bquery.type, bquery.data),
       statement=design.hql_query,