dfunckt / django-rules

Awesome Django authorization, without the database

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Predicates do not include the tested permission in the context

beruic opened this issue · comments

I'm implementing a custom rule system where a user can have different answers to a permission depending on the obj that is supplied to the predicates. In order to check these permissions fully, I need access to the name of the rule being checked in my predicates.

Is this possible without making obj in my predicates a tuple containing the name as well as the object I want to check on?

I am working on some small changes which will make predicates support fn(user, obj, perm). There will be a pulle request soon.

This sounds like something useful to have in rules. The clean way to do it is change Predicate.test() to accept the rule as the first argument. This will be a breaking change, so it must come with a major version bump, but I expect impact to be low since probably noone uses this method directly.

I just ran into an issue like this, too.

I tried to work around it by partially-applying the rule to the predicate function before wrapping it in Predicate but it didn't work because the wrapped function returned by partial() was missing attributes like __name__ and __module__.

Hey @jonathanpglick can you try the context-rule-name branch and see if that works for you? This is WIP, feedback is welcome.