Skip to content

Commit

Permalink
Merge pull request #209 from plone/adopt_user-zope-users
Browse files Browse the repository at this point in the history
Support Zope users in user.adopt_user
  • Loading branch information
zupo committed Feb 4, 2015
2 parents 0d56466 + 5da9319 commit 6e33a54
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
3 changes: 3 additions & 0 deletions docs/CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Changelog
- Fixed `make docs`.
[jaroel]

- Support Zope users in user.adopt_user. Fixes #171 and #157.
[jaroel]

- explicit dependencies in setup.py, explicit zcml loading in tests.
[jensens]

Expand Down
17 changes: 14 additions & 3 deletions src/plone/api/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,22 @@ def adopt_user(username=None, user=None):
# Grab the user object out of acl_users because this function
# accepts 'user' objects that are actually things like MemberData
# objects, which AccessControl isn't so keen on.
acl_users = portal.get().acl_users

unwrapped = None
plone = portal.get()
acls = [plone.acl_users, plone.__parent__.acl_users]

if username is None:
unwrapped = acl_users.getUserById(user.getId())
for acl_users in acls:
unwrapped = acl_users.getUserById(user.getId())
if unwrapped:
break
else:
unwrapped = acl_users.getUser(username)
for acl_users in acls:
unwrapped = acl_users.getUser(username)
if unwrapped:
break

if unwrapped is None:
raise UserNotFoundError

Expand Down
4 changes: 4 additions & 0 deletions src/plone/api/tests/test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,10 @@ def test_adopted_nested_ownership(self):
])
# /user worker

def test_adopting_zope_users(self):
api.env.adopt_user(username='admin')
api.env.adopt_user(user=api.user.get(username='admin'))

def test_empty_warning(self):
"""Tests that empty roles lists get warned about."""
from plone.api.exc import InvalidParameterError
Expand Down

0 comments on commit 6e33a54

Please sign in to comment.