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

Add BasePermissionTester interface and generic ModelPermissionTester #11956

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

laymonage
Copy link
Member

A fresh take on #10578.

Instead of making PagePermissionTester a subclass of ModelPermissionTester (and making sure the latter could allow the former to retain its logic), I tried to start off ModelPermissionTester from scratch, so I can better see where the difference lies between the two.

From what I've seen, it's looking a lot like we can delegate most things to ModelPermissionPolicy.user_has_permission{_for_instance}. The only exceptions seem to be can_lock and can_unlock, which saw a conspicuous change in #6156 that went against the documented behaviour of user_can_lock and user_can_unlock. I added more details in the code comments.

This isn't its final form, as ModelPermissionTester.get_permission_policy() is still unimplemented, but I can't see how it can be implemented without subclassing it. The subclass is probably something we generate at runtime when you try to get a tester/policy of a model that hasn't been registered in the registry (the registry is still to be implemented).

Use the permission policies user_has_permission_for_instance under the
hood as much as possible, making sure that we implement the basic checks
in there whenever possible.

This is different to PagePermissionTester that only uses the policy to
query the GroupPagePermission objects, but still does all of the actual
permission checks by itself. This was because it precedes the policy,
and we wanted to avoid making too much breakage.
Copy link

squash-labs bot commented May 16, 2024

Manage this branch in Squash

Test this branch here: https://laymonagemodel-permission-test-9e4tv.squash.io

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

None yet

1 participant