Skip to content

Conversation

cbrand
Copy link

@cbrand cbrand commented Nov 4, 2014

I needed this to include zope.interface matching to the rules engine.

But I think it is useful for other purposes too, to have a configuration directive for it. To register a custom matcher just use the "custom_subject_matcher" decorator:

from bouncer.test_bouncer.models import Article
from bouncer import authorization_target, authorization_method, custom_subject_matcher


@custom_subject_matcher
def subject_match(rule, subject):
    for subject in rule.subjects:
        if subject == TestAuth.name:
            return True
    return False

@authorization_method
def authorize(user, they):
    they.can(READ, 'Test')

article = Article()
sally = User(name='sally', admin=False)

assert sally.can(READ, article)

@jtushman
Copy link
Contributor

jtushman commented Nov 5, 2014

Cool -- seems like a good feature. I am bit swamped at the moment but will review soon. Thanks for the PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants