Skip to content

Commit

Permalink
change get_owner to get_owners
Browse files Browse the repository at this point in the history
  • Loading branch information
vangheem committed Jul 10, 2017
1 parent 33ea765 commit f77ca08
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
11 changes: 11 additions & 0 deletions guillotina/tests/test_utils.py
@@ -1,5 +1,7 @@
from guillotina import utils
from guillotina.interfaces import IPrincipalRoleManager
from guillotina.interfaces import IResource
from guillotina.tests.utils import create_content
from guillotina.tests.utils import get_mocked_request
from guillotina.tests.utils import get_root

Expand Down Expand Up @@ -97,3 +99,12 @@ def test_valid_id():
assert not utils.valid_id('FooBar-_-.,')
assert not utils.valid_id('FooBar-_-.@#')
assert not utils.valid_id('FooBar-_-.?')


def test_get_owners(dummy_guillotina):
content = create_content()
roleperm = IPrincipalRoleManager(content)
roleperm.assign_role_to_principal('guillotina.Owner', 'foobar')
assert utils.get_owners(content) == ['foobar']
roleperm.assign_role_to_principal('guillotina.Owner', 'foobar2')
assert utils.get_owners(content) == ['foobar', 'foobar2']
10 changes: 6 additions & 4 deletions guillotina/utils.py
Expand Up @@ -326,12 +326,14 @@ def apply_cors(request: IRequest) -> dict:
return headers


def get_owner(obj):
def get_owners(obj):
try:
prinrole = IPrincipalRoleMap(obj)
except TypeError:
return
return []
owners = []
for user, roles in prinrole._bycol.items():
for role in roles:
if role == 'guillotina.Owner' and user in getattr(obj, 'creators', []):
return user
if role == 'guillotina.Owner':
owners.append(user)
return owners

0 comments on commit f77ca08

Please sign in to comment.