-
Notifications
You must be signed in to change notification settings - Fork 92
feat: partial editors #3668
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
Open
ThibaudDauce
wants to merge
6
commits into
main
Choose a base branch
from
partial_editors
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
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.
Open
feat: partial editors #3668
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
131a872
feat: partial editors
ThibaudDauce 463c748
apply review comments
ThibaudDauce 07bbc62
use needs instead of overriding allows
ThibaudDauce 042ec56
set assignations inside membership request
ThibaudDauce bccbccb
fix integrity problems
ThibaudDauce d26ea0c
switch to sync endpoint instead of put/delete
ThibaudDauce 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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| from datetime import datetime | ||
|
|
||
| from mongoengine import CASCADE | ||
|
|
||
| from udata.api_fields import field, generate_fields | ||
| from udata.core.owned import Owned | ||
| from udata.core.user.api_fields import user_ref_fields | ||
| from udata.mongo import db | ||
|
|
||
| from .constants import ASSIGNABLE_OBJECT_TYPES | ||
|
|
||
|
|
||
| @generate_fields() | ||
| class Assignment(db.Document): | ||
| user = field( | ||
| db.ReferenceField("User", required=True, reverse_delete_rule=CASCADE), | ||
| nested_fields=user_ref_fields, | ||
| ) | ||
| organization = field( | ||
| db.ReferenceField("Organization", required=True), | ||
| readonly=True, | ||
| ) | ||
| subject = field( | ||
| db.GenericReferenceField(choices=ASSIGNABLE_OBJECT_TYPES, required=True), | ||
| ) | ||
| created_at = field(db.DateTimeField(default=datetime.utcnow), readonly=True) | ||
|
|
||
| meta = { | ||
| "indexes": [ | ||
| {"fields": ["user", "organization"]}, | ||
| {"fields": ["user", "subject"], "unique": True}, | ||
| ], | ||
| } | ||
|
|
||
|
|
||
| def auto_assign_if_partial_editor(obj): | ||
| """Auto-assign an object to the current user if they are a partial editor.""" | ||
| from udata.auth import current_user | ||
|
|
||
| if not obj.organization or not current_user.is_authenticated: | ||
| return | ||
| member = obj.organization.member(current_user._get_current_object()) | ||
| if member and member.role == "partial_editor": | ||
| Assignment( | ||
| user=current_user._get_current_object(), | ||
| organization=obj.organization, | ||
| subject=obj, | ||
| ).save() | ||
|
|
||
|
|
||
| @Owned.on_owner_change.connect | ||
| def clean_assignments_on_owner_change(document, previous): | ||
| """Remove all assignments for an object when its ownership changes (e.g. transfer).""" | ||
| Assignment.objects(subject=document).delete() |
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
Oops, something went wrong.
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.