diff --git a/src/plone/restapi/deserializer/controlpanels/__init__.py b/src/plone/restapi/deserializer/controlpanels/__init__.py index f27b8fd4b8..53b9a2a07c 100644 --- a/src/plone/restapi/deserializer/controlpanels/__init__.py +++ b/src/plone/restapi/deserializer/controlpanels/__init__.py @@ -9,9 +9,7 @@ from zope.component import adapter from zope.component import getUtility from zope.component import queryMultiAdapter -from zope.i18n import translate from zope.interface import implementer -from zope.interface.exceptions import Invalid from zope.schema import getFields from zope.schema.interfaces import ValidationError @@ -34,7 +32,7 @@ def __init__(self, controlpanel): self.context = self.controlpanel.context self.request = self.controlpanel.request - def __call__(self, mask_validation_errors=True): + def __call__(self): data = json_body(self.controlpanel.request) proxy = self.registry.forInterface(self.schema, prefix=self.schema_prefix) @@ -63,10 +61,10 @@ def __call__(self, mask_validation_errors=True): field.validate(value) # Set the value. setattr(proxy, name, value) + except ValueError as e: + errors.append({"message": str(e), "field": name, "error": e}) except ValidationError as e: errors.append({"message": e.doc(), "field": name, "error": e}) - except (ValueError, Invalid) as e: - errors.append({"message": str(e), "field": name, "error": e}) else: field_data[name] = value @@ -79,10 +77,4 @@ def __call__(self, mask_validation_errors=True): errors.append({"error": error, "message": str(error)}) if errors: - for error in errors: - if mask_validation_errors: - # Drop Python specific error classes in order to be able to better handle - # errors on front-end - error["error"] = "ValidationError" - error["message"] = translate(error["message"], context=self.request) raise BadRequest(errors) diff --git a/src/plone/restapi/tests/test_services_controlpanels.py b/src/plone/restapi/tests/test_services_controlpanels.py index 54a63b13a1..f23affcca5 100644 --- a/src/plone/restapi/tests/test_services_controlpanels.py +++ b/src/plone/restapi/tests/test_services_controlpanels.py @@ -115,22 +115,6 @@ def test_update_required(self): self.assertIn("message", response) self.assertIn("Required input is missing.", response["message"]) - def test_update_validation(self): - response = self.api_session.patch( - "/@controlpanels/socialmedia", json={"twitter_username": "@test"} - ) - response = response.json() - self.assertIn( - 'Twitter username should not include the "@" prefix character.', - response["message"], - ) - - def test_update_validation_status(self): - response = self.api_session.patch( - "/@controlpanels/socialmedia", json={"twitter_username": "@test"} - ) - self.assertEqual(response.status_code, 400) - def test_get_usergroup_control_panel(self): # This control panel does not exist in Plone 5 response = self.api_session.get("/@controlpanels/usergroup")