Skip to content
Snippets Groups Projects
Commit ee2a79e5 authored by Thorge Petersen's avatar Thorge Petersen
Browse files

Added maximum value for max_tag_length

parent ae5151a3
No related branches found
No related tags found
No related merge requests found
...@@ -98,7 +98,7 @@ Parameter | Type | Default | Description ...@@ -98,7 +98,7 @@ Parameter | Type | Default | Description
`ckanext.odsh.copy_remote_resources` | `boolean` | `False` | Indicates whether remote resources should be copied when creating a resource. `ckanext.odsh.copy_remote_resources` | `boolean` | `False` | Indicates whether remote resources should be copied when creating a resource.
`ckanext.odsh.lenient_with` | `string` | Empty string | Comma seperated list of organization IDs for which certain validations should be more lenient, e.g., `09871195-cd0a-4767-9396-276404c940d9,6389d8d9-4eed-472f-9220-4cc2dd82fb90`. `ckanext.odsh.lenient_with` | `string` | Empty string | Comma seperated list of organization IDs for which certain validations should be more lenient, e.g., `09871195-cd0a-4767-9396-276404c940d9,6389d8d9-4eed-472f-9220-4cc2dd82fb90`.
`ckanext.odsh.min_tag_length` | `integer` | `2` | Minimum characters allowed for tag length. `ckanext.odsh.min_tag_length` | `integer` | `2` | Minimum characters allowed for tag length.
`ckanext.odsh.max_tag_length` | `integer` | `100` | Maximum characters allowed for tag length. `ckanext.odsh.max_tag_length` | `integer` | `100` | Maximum characters allowed for tag length. (Maximum value: 100)
`ckanext.odsh.testuser` | `string` | `None` | Name of user for testing. `ckanext.odsh.testuser` | `string` | `None` | Name of user for testing.
`ckanext.odsh.testuserpass` | `string` | `None` | Password of user for testing. `ckanext.odsh.testuserpass` | `string` | `None` | Password of user for testing.
......
...@@ -119,6 +119,8 @@ def test_tag_name_validator_valid(): ...@@ -119,6 +119,8 @@ def test_tag_name_validator_valid():
def test_tag_length_validator_invalid(): def test_tag_length_validator_invalid():
min = int(toolkit.config.get('ckanext.odsh.min_tag_length',2)) min = int(toolkit.config.get('ckanext.odsh.min_tag_length',2))
max = int(toolkit.config.get('ckanext.odsh.max_tag_length',100)) max = int(toolkit.config.get('ckanext.odsh.max_tag_length',100))
if max_tag_length > 100:
max_tag_length = 100
length = round((min + max) / 2) length = round((min + max) / 2)
test_string = _create_test_string(length) test_string = _create_test_string(length)
with pytest.raises(Exception): with pytest.raises(Exception):
......
...@@ -316,9 +316,12 @@ def tag_length_validator(value, context): ...@@ -316,9 +316,12 @@ def tag_length_validator(value, context):
min_tag_length = int(tk.config.get('ckanext.odsh.min_tag_length',2)) min_tag_length = int(tk.config.get('ckanext.odsh.min_tag_length',2))
max_tag_length = int(tk.config.get('ckanext.odsh.max_tag_length',100)) max_tag_length = int(tk.config.get('ckanext.odsh.max_tag_length',100))
if max_tag_length > 100:
max_tag_length = 100
if len(value) < min_tag_length: if len(value) < min_tag_length:
raise toolkit.Invalid( raise toolkit.Invalid(
_('Tag "%s" length is less than minimum %s') % (value, max_tag_length) _('Tag "%s" length is less than minimum %s') % (value, min_tag_length)
) )
if len(value) > max_tag_length: if len(value) > max_tag_length:
raise toolkit.Invalid( raise toolkit.Invalid(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment