Skip to content

Commit

Permalink
Revert "Returns an error message when an Invalid occurs when validati…
Browse files Browse the repository at this point in the history
…ng a controlpanel field (#1771)"

This reverts commit 5e989dd.
  • Loading branch information
mamico committed Jul 9, 2024
1 parent 86e6241 commit 9200c6a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 27 deletions.
14 changes: 3 additions & 11 deletions src/plone/restapi/deserializer/controlpanels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down Expand Up @@ -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

Expand All @@ -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)
16 changes: 0 additions & 16 deletions src/plone/restapi/tests/test_services_controlpanels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 9200c6a

Please sign in to comment.