From 167d2be473ff159494434d7d0e7ebb47440b1779 Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Thu, 8 Jul 2021 12:28:02 +0200 Subject: [PATCH] cmis: include descriptions in file upload schema (#54661) --- passerelle/apps/cmis/models.py | 27 +++++++++++++++++++++++---- passerelle/views.py | 8 +++++++- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/passerelle/apps/cmis/models.py b/passerelle/apps/cmis/models.py index 98c6f665..c94fee0c 100644 --- a/passerelle/apps/cmis/models.py +++ b/passerelle/apps/cmis/models.py @@ -45,29 +45,48 @@ FILE_NAME_PATTERN = r'[\w%s\.]+$' % re.escape(SPECIAL_CHARS) UPLOAD_SCHEMA = { 'type': 'object', + 'title': _('CMIS file upload'), 'properties': { 'file': { + 'title': _('File object'), 'type': 'object', 'properties': { 'filename': { 'type': 'string', + 'description': _('Filename (numbers, letters and special caracters "%s" are allowed)') + % SPECIAL_CHARS, 'pattern': FILE_NAME_PATTERN, }, - 'content': {'type': 'string'}, - 'content_type': {'type': 'string'}, + 'content': { + 'type': 'string', + 'description': _('Content'), + }, + 'content_type': { + 'type': 'string', + 'description': _('Content type'), + }, }, 'required': ['content'], }, 'filename': { 'type': 'string', + 'description': _('Filename (takes precendence over filename in "file" object)'), 'pattern': FILE_NAME_PATTERN, }, 'path': { 'type': 'string', + 'description': _('File path (with leading but not trailing slash)'), 'pattern': FILE_PATH_PATTERN, }, - 'object_type': {'type': 'string'}, - 'properties': {'type': 'object', 'additionalProperties': {'type': 'string'}}, + 'object_type': { + 'type': 'string', + 'description': _('CMIS object type'), + }, + 'properties': { + 'type': 'object', + 'title': _('CMIS properties'), + 'additionalProperties': {'type': 'string'}, + }, }, 'required': ['file', 'path'], 'unflatten': True, diff --git a/passerelle/views.py b/passerelle/views.py index 1df311cf..ad432c4b 100644 --- a/passerelle/views.py +++ b/passerelle/views.py @@ -50,7 +50,7 @@ from django.views.generic import ( View, ) from django.views.generic.detail import SingleObjectMixin -from jsonschema import ValidationError, validate +from jsonschema import ValidationError, validate, validators from passerelle.base.models import BaseResource, ResourceLog from passerelle.compat import json_loads @@ -403,6 +403,12 @@ class GenericEndpointView(GenericConnectorMixin, SingleObjectMixin, View): data.update(data.pop('extra', {})) if pre_process is not None: pre_process(self.endpoint.__self__, data) + + # disable validation on description and title in order to allow lazy translation strings + validator = validators.validator_for(json_schema) + del validator.META_SCHEMA['definitions']['description'] + del validator.META_SCHEMA['definitions']['title'] + try: validate(data, json_schema) except ValidationError as e: -- 2.20.1