diff --git a/docs/changelog.rst b/docs/changelog.rst index 3478b8d..21d4990 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -15,6 +15,7 @@ Changelog applied. Uninstalling from the same panel removes the PAS plugin and the per-user JWT signing secrets. +- #118 Set a file field through its field manager, not the raw mutator - #109 Add a partition operation endpoint - #106 Fix single-valued UID reference fields not settable through the JSON API - #112 Allow updating the Laboratory through the API diff --git a/src/senaite/jsonapi/datamanagers.py b/src/senaite/jsonapi/datamanagers.py index ad3d3e2..2a2cbe2 100644 --- a/src/senaite/jsonapi/datamanagers.py +++ b/src/senaite/jsonapi/datamanagers.py @@ -32,13 +32,23 @@ from senaite.jsonapi.interfaces import IDataManager from senaite.jsonapi.interfaces import IFieldManager from senaite.jsonapi.fieldmanagers import DurationFieldManager +from senaite.jsonapi.fieldmanagers import NamedFileFieldManager from senaite.jsonapi.fieldmanagers import UIDReferenceFieldMixin # Field managers that normalize the incoming value (resolve UIDs, coerce # a duration mapping to a timedelta, ...). For these the raw set # mutator would store the value unconverted, so the data manager must go # through the field manager instead of the setter. -NORMALIZING_FIELD_MANAGERS = (UIDReferenceFieldMixin, DurationFieldManager) +NORMALIZING_FIELD_MANAGERS = ( + UIDReferenceFieldMixin, + DurationFieldManager, + # A file arrives as base64 text and the manager decodes it and + # builds the NamedFile or NamedImage the field holds. The raw + # mutator would store the text itself, which the field then fails + # to validate as the wrong type. NamedImageFieldManager is a + # subclass, so it is covered here too. + NamedFileFieldManager, +) class BaseDataManager(object):