Skip to content

Commit

Permalink
Fixed compatibility with Zope 4.5.2 by making sure Location header is…
Browse files Browse the repository at this point in the history
… string. (#1020)

On Python 2 it could be unicode for the users and groups end points.
Fixes #1019
  • Loading branch information
mauritsvanrees authored and tisto committed Nov 12, 2020
1 parent c2608e3 commit f460108
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions news/1019.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Fixed compatibility with Zope 4.5.2 by making sure Location header is string.
On Python 2 it could be unicode for the users and groups end points.
Fixes `issue 1019 <https://github.com/plone/plone.restapi/issues/1019>`_.
[maurits]
5 changes: 5 additions & 0 deletions src/plone/restapi/services/groups/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from zope.interface import alsoProvides

import plone.protect.interfaces
import six


class GroupsPost(Service):
Expand Down Expand Up @@ -65,6 +66,10 @@ def reply(self):
group.addMember(userid)

self.request.response.setStatus(201)
# Note: to please Zope 4.5.2+ we make sure the header is a string,
# and not unicode on Python 2.
if six.PY2 and not isinstance(groupname, str):
groupname = groupname.encode("utf-8")
self.request.response.setHeader(
"Location", portal.absolute_url() + "/@groups/" + groupname
)
Expand Down
5 changes: 5 additions & 0 deletions src/plone/restapi/services/users/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from zope.publisher.interfaces import IPublishTraverse

import plone.protect.interfaces
import six


try: # pragma: no cover
Expand Down Expand Up @@ -215,6 +216,10 @@ def reply(self):
if send_password_reset:
registration.registeredNotify(username)
self.request.response.setStatus(201)
# Note: to please Zope 4.5.2+ we make sure the header is a string,
# and not unicode on Python 2.
if six.PY2 and not isinstance(username, str):
username = username.encode("utf-8")
self.request.response.setHeader(
"Location", portal.absolute_url() + "/@users/" + username
)
Expand Down

0 comments on commit f460108

Please sign in to comment.