Closed Ochita closed 3 years ago
I know this is a bit late (and also I'm not the project maintainer....so take what I say with a grain of salt!) but I think that you can't allow check(user, None)
to return True
or else it would result in global permission checks using user.has_perm()
to return True
when no instance is provided. That's certainly not what you want as it deviates from expected Django behaviour and could let users access resources throughout your application code when they shouldn't.
I think what you would want to do for your admin mixin is something similar to how bridgekeeper handles the rest_framework integration here. That is your has_*_permission()
methods, when called without an object, should use the is_possible_for()
method of bridgekeeper rules. Then the global (without object) level checks return True/False
depending on whether it's possible for the user to have access to instances, and then the more specific object level checks are done as usual, without you having to define additional rules like you did in your example.
Hope that makes sense and maybe gives some ideas to you or other people coming across this.
Unfortunately , this was used in prototype which already closed. But as I know, You absolutely right. There was problems in other part of system with this empty checks, so it used bridgekeeper without any changes. I'm not shure, did they find out is_possible_for() method or use my version with semiduplicated rules, cause I left this project almost immidiatelly. But it's great answer, thank you. I think I will try to use this approach if I would work with same task in future.
Hey, sorry this flew under my radar! @philipstarkey is right, is_possible_for
is what you want to use here.
Hi! Firstly, I want to thank you for this handy module. It's really great. And secondly, I want to discuss a bit about R, Is and In rules behaviour when instance object not passed. I try to use bridgekeeper with default django modelAdmin, I write a little mixin, inspired by your code and some django-rules code. It provides needed functionallity: filter objects list, filter objects in selects, check permissions.
But django admin calls has_*_permission without object for checking what links and icons show to user on first page. And if i had the rule
it returns false without object for non supercompany user and didn't show Users link on page. So i need to make additional condition and additional rules for checking possibility for actions
This case works fine. But maybe R conditions should return True without instanse and there is no need for addtitional rules? Because you can do anything with nothing, it's didn't break the law)) User possibly had some objects to view.
What do you think? Does this break something? I don't know if it used somwhere else without instance.