From ee2a79e57eb2012150f365d8d06e1fc5d4ed56a2 Mon Sep 17 00:00:00 2001
From: Thorge Petersen <petersen@rz.uni-kiel.de>
Date: Fri, 30 Jun 2023 12:55:40 +0200
Subject: [PATCH] Added maximum value for max_tag_length

---
 README.md                                 | 2 +-
 ckanext/odsh/tests_wip/test_validation.py | 2 ++
 ckanext/odsh/validation.py                | 5 ++++-
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/README.md b/README.md
index f8ee14f3..e674dced 100644
--- a/README.md
+++ b/README.md
@@ -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.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.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.testuserpass` | `string` | `None` | Password of user for testing.
 
diff --git a/ckanext/odsh/tests_wip/test_validation.py b/ckanext/odsh/tests_wip/test_validation.py
index f21ee446..55136e2d 100644
--- a/ckanext/odsh/tests_wip/test_validation.py
+++ b/ckanext/odsh/tests_wip/test_validation.py
@@ -119,6 +119,8 @@ def test_tag_name_validator_valid():
 def test_tag_length_validator_invalid():
     min = int(toolkit.config.get('ckanext.odsh.min_tag_length',2))
     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)
     test_string = _create_test_string(length)
     with pytest.raises(Exception):
diff --git a/ckanext/odsh/validation.py b/ckanext/odsh/validation.py
index 0ad3d7fe..6c14d7a6 100644
--- a/ckanext/odsh/validation.py
+++ b/ckanext/odsh/validation.py
@@ -316,9 +316,12 @@ def tag_length_validator(value, context):
     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))
 
+    if max_tag_length > 100:
+        max_tag_length = 100
+
     if len(value) < min_tag_length:
         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:
         raise toolkit.Invalid(
-- 
GitLab