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
Allow batch assignment of multiple permissions to multiple users/groups for multiple objects #777
Open
JCourt1
wants to merge
14
commits into
django-guardian:devel
Choose a base branch
from
JCourt1:feature/multipermassign
base: devel
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
refactor: _get_base_filters feat: add support for removing perms for multiple users_or_groups
Allows removing multiple perms for multiple users over multiple objects
JCourt1
changed the title
Feature/multipermassign
Allow assigning multiple permissions to multiple users/groups for multiple objects
May 9, 2022
JCourt1
changed the title
Allow assigning multiple permissions to multiple users/groups for multiple objects
Allow batch assignment of multiple permissions to multiple users/groups for multiple objects
May 9, 2022
tests cover the different possible argument types for bulk_remove_perms These shortcuts also have a "commit" parameter, meaning the user can eg. bulk create certain permissions for a certain set of groups, other perms for another set, then save them all at the same time.
without this change, there is an error on postgres whenever the object's pk is not varchar. This is due to the fact that guardian's object permission models have a varchar pk, but postgres doesn't automatically convert eg. ints to varchars
JCourt1
force-pushed
the
feature/multipermassign
branch
2 times, most recently
from
May 25, 2022 08:29
cef55f6
to
f0ca148
Compare
JCourt1
force-pushed
the
feature/multipermassign
branch
from
May 25, 2022 08:39
f0ca148
to
3821067
Compare
This fixes a bug where empty Q object was causing a deepcopy in django/db/models/query_utils.py This was causing a bug in certain versions of django when the query involves a model which had a BinaryField inside it. The bug is described here: noripyt/django-cachalot#115
I like this future, could this be merged? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, the methods in the
BaseObjectPermissionManager
do not allow assigning multiple permissions for multiple users and for multiple objects. Likewise, theassign_perm
function in shortcuts does not even allow assigning multiple permissions at once. The problem with this is that permission assignments are very slow, because they cannot be properly batched together.This PR adds in methods to the object permission manager, and also adds two new shortcuts:
bulk_assign_perms
andbulk_remove_perms
. In addition, I have also added acommit
parameter, which allows the user of the shortcuts to go even further with the batching, and accumulate permissions so that they can all be persisted in one fell swoop. I have ensured that previous behaviour is left intact, and the new behaviour is well tested.Having applied these changes in a work project which relies heavily on django guardian, I have seen a big decrease in the time taken for the entire test suite to complete (down to ~20 seconds from 3 minutes).