[ckan-changes] commit/ckan: dread: [logic][s]: #1427 Tag length limit validation.

Bitbucket commits-noreply at bitbucket.org
Thu Oct 27 09:57:56 UTC 2011


1 new commit in ckan:


https://bitbucket.org/okfn/ckan/changeset/ec9a9efc2d40/
changeset:   ec9a9efc2d40
branch:      release-v1.5
user:        dread
date:        2011-10-27 11:57:48
summary:     [logic][s]: #1427 Tag length limit validation.
affected #:  3 files

diff -r a0ce4ba311ce731c7c025bd14baf1446c0a1615a -r ec9a9efc2d4072c6e81d106f44af9e2a0f831731 ckan/logic/validators.py
--- a/ckan/logic/validators.py
+++ b/ckan/logic/validators.py
@@ -5,7 +5,7 @@
 from ckan.authz import Authorizer
 from ckan.logic import check_access, NotAuthorized
 from ckan.lib.helpers import date_str_to_datetime
-
+from ckan.model import MAX_TAG_LENGTH
 
 def package_id_not_changed(value, context):
 
@@ -149,6 +149,10 @@
         raise Invalid(
             _('Tag "%s" length is less than minimum %s') % (value, 2)
         )
+    if len(value) > MAX_TAG_LENGTH:
+        raise Invalid(
+            _('Tag "%s" length is more than maximum %i') % (value, MAX_TAG_LENGTH)
+        )
     return value
 
 def tag_name_validator(value, context):


diff -r a0ce4ba311ce731c7c025bd14baf1446c0a1615a -r ec9a9efc2d4072c6e81d106f44af9e2a0f831731 ckan/model/tag.py
--- a/ckan/model/tag.py
+++ b/ckan/model/tag.py
@@ -9,11 +9,14 @@
 from core import *
 
 __all__ = ['tag_table', 'package_tag_table', 'Tag', 'PackageTag',
-           'PackageTagRevision', 'package_tag_revision_table']
+           'PackageTagRevision', 'package_tag_revision_table',
+           'MAX_TAG_LENGTH']
+
+MAX_TAG_LENGTH = 100
 
 tag_table = Table('tag', metadata,
         Column('id', types.UnicodeText, primary_key=True, default=make_uuid),
-        Column('name', types.Unicode(100), nullable=False, unique=True),
+        Column('name', types.Unicode(MAX_TAG_LENGTH), nullable=False, unique=True),
 )
 
 package_tag_table = Table('package_tag', metadata,


diff -r a0ce4ba311ce731c7c025bd14baf1446c0a1615a -r ec9a9efc2d4072c6e81d106f44af9e2a0f831731 ckan/tests/functional/api/model/test_package.py
--- a/ckan/tests/functional/api/model/test_package.py
+++ b/ckan/tests/functional/api/model/test_package.py
@@ -183,6 +183,17 @@
             plugins.unload('synchronous_search')
             search.common.solr_url = solr_url
 
+    def test_register_post_tag_too_long(self):
+        pkg = {'name': 'test_tag_too_long',
+               'tags': ['tagok', 't'*101]}
+        assert not self.get_package_by_name(pkg['name'])
+        offset = self.package_offset()
+        data = self.dumps(pkg)
+        res = self.post_json(offset, data, status=self.STATUS_409_CONFLICT,
+                             extra_environ=self.extra_environ)
+        assert 'length is more than maximum 100' in res.body, res.body
+        assert 'tagok' not in res.body
+
     def test_entity_get_ok(self):
         package_refs = [self.anna.name, self.anna.id]
         for ref in package_refs:
@@ -468,6 +479,7 @@
         package2_data = {'name': package2_name}
         package2 = self.create_package_roles_revision(package2_data)
         package1_offset = self.package_offset(package1_name)
+        # trying to rename package 1 to package 2's name
         self.post(package1_offset, package2_data, self.STATUS_409_CONFLICT)
 
     def test_entity_update_empty(self):

Repository URL: https://bitbucket.org/okfn/ckan/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.




More information about the ckan-changes mailing list