diff --git a/guillotina/tests/test_utils.py b/guillotina/tests/test_utils.py index 1f1cdcd1c..37b5cd681 100644 --- a/guillotina/tests/test_utils.py +++ b/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 @@ -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'] diff --git a/guillotina/utils.py b/guillotina/utils.py index f81ad4882..8baa7418a 100644 --- a/guillotina/utils.py +++ b/guillotina/utils.py @@ -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