Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to set a custom subject match method for the rule subject matcher #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.

None yet

2 participants