-
Notifications
You must be signed in to change notification settings - Fork 0
Adds owner of a group as member of that group #261
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
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
76fd0ad
gwy: user is now added to the group it creates
lucaspar aabf892
gwy: migration: retroactively adds group owners as members
lucaspar 683b49f
gwy: prevents removing users from groups in some situations
lucaspar 86a812b
gwy: new UserSharePermission.is_individual_share flag to track how an…
lucaspar 407bdef
gwy: new scenario test_individual_share_preserved_after_group_revocation
lucaspar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
41 changes: 41 additions & 0 deletions
41
...s_gateway/api_methods/migrations/0020_group_owner_as_member_and_individual_share_field.py
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| """Add each ShareGroup owner as a member of their own group; add is_individual_share to UserSharePermission. | ||
|
|
||
| Existing UserSharePermission rows default to True (individual share), preserving all | ||
| current access. Permissions created purely through a group share are written with | ||
| False so that revoking the group also revokes the permission. | ||
| """ | ||
|
|
||
| from django.db import migrations | ||
| from django.db import models | ||
|
|
||
|
|
||
| def add_owners_as_members(apps, schema_editor): | ||
| ShareGroup = apps.get_model("api_methods", "ShareGroup") | ||
| for group in ShareGroup.objects.filter(is_deleted=False).select_related("owner"): | ||
| group.members.add(group.owner) | ||
|
|
||
|
|
||
| def remove_owners_as_members(apps, schema_editor): | ||
| """Reverse: remove owners who are members solely because of this migration. | ||
|
|
||
| Best-effort — also removes owners added manually before this migration, which | ||
| is an acceptable trade-off for a reversible migration. | ||
| """ | ||
| ShareGroup = apps.get_model("api_methods", "ShareGroup") | ||
| for group in ShareGroup.objects.filter(is_deleted=False).select_related("owner"): | ||
| group.members.remove(group.owner) | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("api_methods", "0019_capture_datasets_file_captures_file_datasets_and_more"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.RunPython(add_owners_as_members, remove_owners_as_members), | ||
| migrations.AddField( | ||
| model_name="usersharepermission", | ||
| name="is_individual_share", | ||
| field=models.BooleanField(default=True), | ||
| ), | ||
| ] |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 0019_capture_datasets_file_captures_file_datasets_and_more | ||
| 0020_group_owner_as_member_and_individual_share_field |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.