Skip to content

Commit

Permalink
Make sure to look against all roles (#101)
Browse files Browse the repository at this point in the history
* get_principals_with_access_content and get_roles_with_access_content was not
  checking against all roles
  • Loading branch information
vangheem committed Jun 23, 2017
1 parent e0dba33 commit 19816d7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.rst
@@ -1,7 +1,9 @@
1.1.0a19 (unreleased)
---------------------

- Nothing changed yet.
- get_principals_with_access_content and get_roles_with_access_content was not
checking against all roles
[vangheem]


1.1.0a18 (2017-06-22)
Expand Down
8 changes: 4 additions & 4 deletions guillotina/security/utils.py
Expand Up @@ -29,9 +29,9 @@ def get_roles_with_access_content(obj, request=None):
interaction = IInteraction(request)
roles = interaction.cached_roles(obj, 'guillotina.AccessContent', 'o')
result = []
all_roles = role.global_roles() + role.local_roles()
for r in roles.keys():
lroles = role.global_roles()
if r in lroles:
if r in all_roles:
result.append(r)
return result

Expand All @@ -44,9 +44,9 @@ def get_principals_with_access_content(obj, request=None):
interaction = IInteraction(request)
roles = interaction.cached_roles(obj, 'guillotina.AccessContent', 'o')
result = []
all_roles = role.global_roles() + role.local_roles()
for r in roles.keys():
lroles = role.local_roles()
if r in lroles:
if r in all_roles:
result.append(r)
users = interaction.cached_principals(obj, result, 'guillotina.AccessContent', 'o')
return list(users.keys())
Expand Down
3 changes: 2 additions & 1 deletion guillotina/tests/test_security.py
Expand Up @@ -67,7 +67,8 @@ async def test_set_local_guillotina(container_requester):
principals = get_principals_with_access_content(testing_object, request)
assert principals == ['root']
roles = get_roles_with_access_content(testing_object, request)
assert roles == ['guillotina.ContainerAdmin']
assert roles == ['guillotina.Reader', 'guillotina.Reviewer', 'guillotina.Owner',
'guillotina.Editor', 'guillotina.ContainerAdmin']

# Now we add the user1 with inherit on the container
response, status = await requester(
Expand Down

0 comments on commit 19816d7

Please sign in to comment.