diff --git a/src/documents/serialisers.py b/src/documents/serialisers.py index 30f3dd26d..3c88df026 100644 --- a/src/documents/serialisers.py +++ b/src/documents/serialisers.py @@ -33,6 +33,7 @@ if settings.AUDIT_LOG_ENABLED: from documents import bulk_edit from documents.data_models import DocumentSource +from documents.file_handling import validate_template_and_render from documents.models import Correspondent from documents.models import CustomField from documents.models import CustomFieldInstance @@ -1479,36 +1480,11 @@ class StoragePathSerializer(MatchingModelSerializer, OwnedObjectSerializer): "set_permissions", ) - def validate_path(self, path): - try: - path.format( - title="title", - correspondent="correspondent", - document_type="document_type", - created="created", - created_year="created_year", - created_year_short="created_year_short", - created_month="created_month", - created_month_name="created_month_name", - created_month_name_short="created_month_name_short", - created_day="created_day", - added="added", - added_year="added_year", - added_year_short="added_year_short", - added_month="added_month", - added_month_name="added_month_name", - added_month_name_short="added_month_name_short", - added_day="added_day", - asn="asn", - tags="tags", - tag_list="tag_list", - owner_username="someone", - original_name="testfile", - doc_pk="doc_pk", - ) + def validate_path(self, path: str): + result = validate_template_and_render(path) - except KeyError as err: - raise serializers.ValidationError(_("Invalid variable detected.")) from err + if result is None: + raise serializers.ValidationError(_("Invalid variable detected.")) return path