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 checks for EMPTY and UNIVERSAL in query function #26

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

Conversation

johannesd
Copy link

@johannesd johannesd commented Nov 21, 2021

I'm not sure if blanket rules are meant to be nested in Rs, but I think it would definitely be useful:

class MyModel(Model):
    pass


class MyOtherModel(Model):
    parent = models.ForeignKey(MyModel)


@blanket_rule
def is_admin(user):
    # something


perms['myapp.view_mymodel'] = is_admin # and more complex stuff
perms['myapp.view_myothermodel'] = R(parent=perms['myapp.view_mymodel'])

This is a minimal example where I just want to set permissions of MyOtherModel based on the existing permissions of the referenced model MyModel.

This currently leads to

  File "[...]/rest_framework/views.py", line 332, in check_permissions
    if not permission.has_permission(request, self):
  File "[...]/bridgekeeper/rest_framework.py", line 161, in has_permission
    return self.get_permission(request, view).is_possible_for(request.user)
  File "[...]/bridgekeeper/rules.py", line 86, in is_possible_for
    return self.query(user) is not EMPTY
  File "[...]/bridgekeeper/rules.py", line 367, in query
    accumulated_q &= add_prefix(child_q_obj, key)
  File "[...]/bridgekeeper/rules.py", line 535, in add_prefix
    for child in q_obj.children
AttributeError: 'Sentinel' object has no attribute 'children'

I fixed this by added checks for EMPTY and UNIVERSAL in query function and modify query appropriately.

Is this correct?

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.

1 participant