Skip to content

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

Open
cbrand wants to merge 1 commit intobouncer-app:masterfrom
cbrand:master
Open

Added ability to set a custom subject match method for the rule subject matcher#9
cbrand wants to merge 1 commit intobouncer-app:masterfrom
cbrand:master

Conversation

@cbrand
Copy link
Copy Markdown

@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
Copy Markdown
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