Skip to content

Commit

Permalink
[fc] Repository: plone.restapi
Browse files Browse the repository at this point in the history
Branch: refs/heads/main
Date: 2024-11-05T12:55:02-08:00
Author: David Glick (davisagli) <[email protected]>
Commit: plone/plone.restapi@636ef37

Fix handling of errors in aliases CSV upload (#1838)

* Fix handling of errors in aliases CSV upload

* changelog

Files changed:
A news/1837.bugfix
M src/plone/restapi/services/aliases/add.py
  • Loading branch information
davisagli committed Nov 5, 2024
1 parent 5318b23 commit 7c358dc
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions last_commit.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
Repository: plone.app.multilingual
Repository: plone.restapi


Branch: refs/heads/master
Date: 2024-11-04T23:00:11+01:00
Author: Yuri (yurj) <[email protected]>
Commit: https://github.com/plone/plone.app.multilingual/commit/52e6a1946dfacb0d2e03fe0b78c45a34a09ed6f6
Branch: refs/heads/main
Date: 2024-11-05T12:55:02-08:00
Author: David Glick (davisagli) <[email protected]>
Commit: https://github.com/plone/plone.restapi/commit/636ef37ecf1fce3de17c80fa29e6cac7e6ffbcac

Rename 472.bug to 472.bugfix
Fix handling of errors in aliases CSV upload (#1838)

* Fix handling of errors in aliases CSV upload

* changelog

Files changed:
A news/472.bugfix
D news/472.bug
A news/1837.bugfix
M src/plone/restapi/services/aliases/add.py

b'diff --git a/news/472.bug b/news/472.bugfix\nsimilarity index 100%\nrename from news/472.bug\nrename to news/472.bugfix\n'
b'diff --git a/news/1837.bugfix b/news/1837.bugfix\nnew file mode 100644\nindex 0000000000..08502b6c36\n--- /dev/null\n+++ b/news/1837.bugfix\n@@ -0,0 +1 @@\n+URL Management control panel: Fix error handling in CSV upload. @davisagli\ndiff --git a/src/plone/restapi/services/aliases/add.py b/src/plone/restapi/services/aliases/add.py\nindex e54ccc0c67..2894d25b22 100644\n--- a/src/plone/restapi/services/aliases/add.py\n+++ b/src/plone/restapi/services/aliases/add.py\n@@ -101,12 +101,22 @@ def _reply_csv(self):\n raise BadRequest("Uploaded file is not a valid CSV file")\n \n controlpanel = RedirectsControlPanel(self.context, self.request)\n+ csv_errors = controlpanel.csv_errors = []\n storage = getUtility(IRedirectionStorage)\n status = IStatusMessage(self.request)\n portal = getSite()\n controlpanel.upload(file, portal, storage, status)\n file.close()\n \n+ if csv_errors:\n+ self.request.response.setHeader("Content-Type", "application/json")\n+ self.request.response.setStatus(BadRequest)\n+ return {\n+ "type": "BadRequest",\n+ "message": f"Found {len(csv_errors)} errors in CSV file.",\n+ # Skip first item which is a notice about the delimiter\n+ "csv_errors": csv_errors[1:],\n+ }\n if err := status.show():\n if err[0].type == "error":\n raise BadRequest(err[0].message)\n'

0 comments on commit 7c358dc

Please sign in to comment.