Skip to content
This repository has been archived by the owner on Sep 28, 2022. It is now read-only.

Commit

Permalink
Merge pull request #102 from postatum/102640146_polymorphic_403
Browse files Browse the repository at this point in the history
Rename permission in polymorphic view
  • Loading branch information
jstoiko committed Sep 4, 2015
2 parents 230853d + 620d123 commit 10a6c02
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions nefertari/polymorphic.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def get_resources(self, collections):
class PolymorphicACL(PolymorphicHelperMixin, CollectionACL):
""" ACL used by PolymorphicESView.
Generates ACEs checking whether current request user has 'index'
Generates ACEs checking whether current request user has 'view'
permissions in all of the requested collection views/contexts.
"""
def __init__(self, request):
Expand All @@ -91,7 +91,7 @@ def _get_least_permissions_aces(self, resources):
To have access to polymorph on N collections, user MUST have
access to all of them. If this is true, ACEs are returned, that
allows 'index' permissions to current request principals.
allows 'view' permissions to current request principals.
Otherwise None is returned thus blocking all permissions except
those defined in `nefertari.acl.BaseACL`.
Expand All @@ -104,11 +104,11 @@ def _get_least_permissions_aces(self, resources):
factories = [res.view._factory for res in resources]
contexts = [factory(self.request) for factory in factories]
for ctx in contexts:
if not self.request.has_permission('index', ctx):
if not self.request.has_permission('view', ctx):
return
else:
return [
(Allow, principal, 'index')
(Allow, principal, 'view')
for principal in self.request.effective_principals
]

Expand Down
8 changes: 4 additions & 4 deletions tests/test_polymorphic.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_get_least_permissions_aces_not_allowed(self, mock_meth):
assert acl._get_least_permissions_aces([resource]) is None
resource.view._factory.assert_called_once_with(request)
request.has_permission.assert_called_once_with(
'index', resource.view._factory())
'view', resource.view._factory())

@patch.object(polymorphic.PolymorphicACL, 'set_collections_acl')
def test_get_least_permissions_aces_allowed(self, mock_meth):
Expand All @@ -55,10 +55,10 @@ def test_get_least_permissions_aces_allowed(self, mock_meth):
aces = acl._get_least_permissions_aces([resource])
resource.view._factory.assert_called_once_with(request)
request.has_permission.assert_called_once_with(
'index', resource.view._factory())
'view', resource.view._factory())
assert len(aces) == 2
assert (Allow, 'user', 'index') in aces
assert (Allow, 'admin', 'index') in aces
assert (Allow, 'user', 'view') in aces
assert (Allow, 'admin', 'view') in aces

@patch.object(polymorphic.PolymorphicACL, '_get_least_permissions_aces')
@patch.object(polymorphic.PolymorphicACL, 'get_resources')
Expand Down

0 comments on commit 10a6c02

Please sign in to comment.