Skip to content

Commit

Permalink
Fix registration function to use new registry definition
Browse files Browse the repository at this point in the history
  • Loading branch information
Fiveside committed Mar 4, 2014
1 parent 9b3ee8b commit 4498fd7
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions shield/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import absolute_import, unicode_literals, division
import operator
from six.moves import map, reduce
from ._registry import registry, expression
from ._registry import registry, target_registry, bearer_registry, expression


def register(function, *permissions, **kwargs):
Expand All @@ -21,14 +21,20 @@ def register(function, *permissions, **kwargs):
The entity that the bearer is being granted the
permissions for (optional).
"""
target, bearer = kwargs.get('target'), kwargs['bearer']
if permissions and not permissions[0] is None:
for permission in permissions:
key = bearer, target, permission
registry[key] = function

# Generic USER HAS ALL PERMISSIONS ON TARGET type permision
if not len(permissions):
target_registry[kwargs['bearer'], kwargs['target']] = function

# Generic USER CAN X permission.
elif not 'target' in kwargs:
for perm in permissions:
bearer_registry[kwargs['bearer'], perm] = function

# Specific USER CAN X ON TARGET permission.
else:
registry[bearer, target] = function
for perm in permissions:
registry[kwargs['bearer'], kwargs['target'], perm] = function


def has(*permissions, **kwargs):
Expand Down

0 comments on commit 4498fd7

Please sign in to comment.