From e5acfc24b081e1473608fb170353a080d76c4c5d Mon Sep 17 00:00:00 2001 From: David Glick Date: Tue, 5 Nov 2024 11:53:48 -0800 Subject: [PATCH 1/2] Fix handling of errors in aliases CSV upload --- src/plone/restapi/services/aliases/add.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/plone/restapi/services/aliases/add.py b/src/plone/restapi/services/aliases/add.py index e54ccc0c67..2894d25b22 100644 --- a/src/plone/restapi/services/aliases/add.py +++ b/src/plone/restapi/services/aliases/add.py @@ -101,12 +101,22 @@ def _reply_csv(self): raise BadRequest("Uploaded file is not a valid CSV file") controlpanel = RedirectsControlPanel(self.context, self.request) + csv_errors = controlpanel.csv_errors = [] storage = getUtility(IRedirectionStorage) status = IStatusMessage(self.request) portal = getSite() controlpanel.upload(file, portal, storage, status) file.close() + if csv_errors: + self.request.response.setHeader("Content-Type", "application/json") + self.request.response.setStatus(BadRequest) + return { + "type": "BadRequest", + "message": f"Found {len(csv_errors)} errors in CSV file.", + # Skip first item which is a notice about the delimiter + "csv_errors": csv_errors[1:], + } if err := status.show(): if err[0].type == "error": raise BadRequest(err[0].message) From 0940e3770add890bc3eacb39676e669f52a5a8e5 Mon Sep 17 00:00:00 2001 From: David Glick Date: Tue, 5 Nov 2024 11:56:33 -0800 Subject: [PATCH 2/2] changelog --- news/1837.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/1837.bugfix diff --git a/news/1837.bugfix b/news/1837.bugfix new file mode 100644 index 0000000000..08502b6c36 --- /dev/null +++ b/news/1837.bugfix @@ -0,0 +1 @@ +URL Management control panel: Fix error handling in CSV upload. @davisagli