Skip to content

Commit

Permalink
do not assign owner if none provided by IGetOwner
Browse files Browse the repository at this point in the history
  • Loading branch information
vangheem committed Dec 6, 2017
1 parent d2a4436 commit 1a6a3ab
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.rst
@@ -1,7 +1,11 @@
2.1.18 (unreleased)
-------------------

- Nothing changed yet.
- get_owners will lookup to parent object for owner.
[vangheem]

- if IGetOwner returns none, no owner will be set on object
[vangheem]


2.1.17 (2017-12-06)
Expand Down
5 changes: 3 additions & 2 deletions guillotina/api/content.py
Expand Up @@ -218,8 +218,9 @@ async def __call__(self):
# Local Roles assign owner as the creator user
get_owner = get_utility(IGetOwner)
roleperm = IPrincipalRoleManager(obj)
roleperm.assign_role_to_principal(
'guillotina.Owner', await get_owner(obj, user))
owner = await get_owner(obj, user)
if owner is not None:
roleperm.assign_role_to_principal('guillotina.Owner', owner)

data['id'] = obj.id
await notify(ObjectAddedEvent(obj, self.context, obj.id, payload=data))
Expand Down
3 changes: 3 additions & 0 deletions guillotina/utils.py
Expand Up @@ -343,6 +343,9 @@ def get_owners(obj):
for role in roles:
if role == 'guillotina.Owner':
owners.append(user)
if len(owners) == 0 and getattr(obj, '__parent__', None) is not None:
# owner can be parent if none found on current object
return get_owners(obj.__parent__)
return owners


Expand Down

0 comments on commit 1a6a3ab

Please sign in to comment.