plone / plone.restapi

RESTful API for Plone.
http://plonerestapi.readthedocs.org/
84 stars 73 forks source link

Returns an error message when an Invalid occurs when validating a controlpanel field #1771

Closed wesleybl closed 2 months ago

wesleybl commented 3 months ago

Also translates the message.

Ref: https://github.com/plone/volto/issues/5274

mister-roboto commented 3 months ago

@wesleybl thanks for creating this Pull Request and helping to improve Plone!

TL;DR: Finish pushing changes, pass all other checks, then paste a comment:

@jenkins-plone-org please run jobs

To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass, but it takes 30-60 min. Other CI checks are usually much faster and the Plone Jenkins resources are limited, so when done pushing changes and all other checks pass either start all Jenkins PR jobs yourself, or simply add the comment above in this PR to start all the jobs automatically.

Happy hacking!

netlify[bot] commented 3 months ago

Deploy Preview for plone-restapi canceled.

Name Link
Latest commit c8adc970ee539fdc401a0ff8ac0270094010dccd
Latest deploy log https://app.netlify.com/sites/plone-restapi/deploys/66310358e831fc0008d11827
wesleybl commented 3 months ago

@jenkins-plone-org please run jobs

wesleybl commented 3 months ago

@jenkins-plone-org please run jobs

davisagli commented 2 months ago

@wesleybl Could you add a screenshot of how the error looks now, or give me steps to reproduce it? I can probably figure it out but I'm skimming through a bunch of issues this evening, and it's easier to click "accept" quickly if I can clearly see what the result of the change is.

wesleybl commented 2 months ago

@davisagli the steps to reproduce this on the Volto are described in: https://github.com/plone/volto/issues/5274

But this PR here does not make validation errors appear in Volto. It only leaves the compatible restapi response to be displayed in Volto. I'm preparing a PR on Volto to display the errors. But this PR here doesn't "break the screen" if my Volto PR isn't ready. So it's safe to merge first.

With this PR the response with validation error looks like this:

{
  "message": "[{'message': 'Twitter username should not include the \"@\" prefix character.', 'field': 'twitter_username', 'error': 'ValidationError'}]",
  "traceback": [
    "File \"/home/user/.buildout/eggs/cp311/Zope-5.8.5-py3.11.egg/ZPublisher/WSGIPublisher.py\", line 181, in transaction_pubevents",
    "    yield",
    "",
    "  File \"/home/user/.buildout/eggs/cp311/Zope-5.8.5-py3.11.egg/ZPublisher/WSGIPublisher.py\", line 391, in publish_module",
    "    response = _publish(request, new_mod_info)",
    "               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^",
    "",
    "  File \"/home/user/.buildout/eggs/cp311/Zope-5.8.5-py3.11.egg/ZPublisher/WSGIPublisher.py\", line 285, in publish",
    "    result = mapply(obj,",
    "             ^^^^^^^^^^^",
    "",
    "  File \"/home/user/.buildout/eggs/cp311/Zope-5.8.5-py3.11.egg/ZPublisher/mapply.py\", line 98, in mapply",
    "    return debug(object, args, context)",
    "           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^",
    "",
    "  File \"/home/user/.buildout/eggs/cp311/Zope-5.8.5-py3.11.egg/ZPublisher/WSGIPublisher.py\", line 68, in call_object",
    "    return obj(*args)",
    "           ^^^^^^^^^^",
    "",
    "  File \"/home/user/.buildout/eggs/cp311/plone.rest-3.0.1-py3.11.egg/plone/rest/service.py\", line 22, in __call__",
    "    return self.render()",
    "           ^^^^^^^^^^^^^",
    "",
    "  File \"/home/user/git/plone.restapi/src/plone/restapi/services/__init__.py\", line 19, in render",
    "    content = self.reply()",
    "              ^^^^^^^^^^^^",
    "",
    "  File \"/home/user/git/plone.restapi/src/plone/restapi/services/controlpanels/update.py\", line 41, in reply",
    "    deserializer()  # The deserializer knows where to put it.",
    "    ^^^^^^^^^^^^^^",
    "",
    "  File \"/home/user/git/plone.restapi/src/plone/restapi/deserializer/controlpanels/__init__.py\", line 89, in __call__",
    "    raise BadRequest(errors)"
  ],
  "type": "BadRequest"
}
wesleybl commented 2 months ago

@davisagli I make the Volto PR: https://github.com/plone/volto/pull/5950

wesleybl commented 2 months ago

@jenkins-plone-org please run jobs

wesleybl commented 2 months ago

@tisto @davisagli @sneridagh can you take a look here please?

davisagli commented 2 months ago

@jenkins-plone-org please run jobs

wesleybl commented 2 months ago

@jenkins-plone-org please run jobs