forked from isichos/epa
-
Notifications
You must be signed in to change notification settings - Fork 5
fix the problems with project sharing #478
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
Draft
josihoppe
wants to merge
14
commits into
main
Choose a base branch
from
fix/sharing_rights
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.
Draft
Changes from 6 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2d62955
added decorator for edit and read viewer rights
josihoppe cd0d7db
exchanged repeating check for viewer share rights with decorator in p…
josihoppe dbfc323
fixed worng variable name in decorator
josihoppe c263048
added different return view_func behavior for views with different pa…
josihoppe 15eec75
added decorators and user.has_edit_rights checks to more complex view…
josihoppe 3a8c305
exchanged repeating checks for viewer share rigths with decorator in …
josihoppe fee5c9d
removed doubled viewer right check
josihoppe 668ddc6
added new decorator if just the owner of project has permission
josihoppe 3142fc2
added is owner decorator to project views
josihoppe 5e7e06d
renamed decorators
josihoppe 7b3507e
added another shorter check
josihoppe 989f0e6
changed permission for seeing t and updating imeseries graph to edit …
josihoppe 1280f31
changed permission for duplicating a shared scenario in own project o…
josihoppe 2e81d0d
changed permission for deleting project in own project overview to re…
josihoppe 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| from django.core.exceptions import PermissionDenied | ||
| from django.shortcuts import get_object_or_404 | ||
|
|
||
| from functools import wraps | ||
|
|
||
| from projects.models import Project, Scenario | ||
|
|
||
|
|
||
| def viewer_has_view_rights(view_func): | ||
| @wraps(view_func) | ||
| def _wrapped_view(request, proj_id=None, scen_id=None, *args, **kwargs): | ||
| if proj_id: | ||
| project = get_object_or_404(Project, pk=proj_id) | ||
| elif scen_id: | ||
| scenario = get_object_or_404(Scenario, pk=scen_id) | ||
| project = scenario.project | ||
| # oder ersetzen durch user.has_read_rights | ||
| if (project.user != request.user) and ( | ||
| project.viewers.filter(user__email=request.user.email).exists() is False | ||
| ): | ||
| raise PermissionDenied | ||
| # check for existing parameters to handle the different view parameters | ||
| if proj_id is not None and scen_id is not None: | ||
| return view_func(request, proj_id, scen_id, *args, **kwargs) | ||
| elif proj_id is not None: | ||
| return view_func(request, proj_id, *args, **kwargs) | ||
| elif scen_id is not None: | ||
| return view_func(request, scen_id, *args, **kwargs) | ||
|
|
||
| return _wrapped_view | ||
|
|
||
|
|
||
| def viewer_has_edit_rights(view_func): | ||
| @wraps(view_func) | ||
| def _wrapped_view(request, proj_id=None, scen_id=None, *args, **kwargs): | ||
| if proj_id: | ||
| project = get_object_or_404(Project, pk=proj_id) | ||
| elif scen_id: | ||
| scenario = get_object_or_404(Scenario, pk=scen_id) | ||
| project = scenario.project | ||
| # oder ersetzen durch user.has_edit_rights | ||
| if (project.user != request.user) and ( | ||
| project.viewers.filter( | ||
| user__email=request.user.email, share_rights="edit" | ||
| ).exists() | ||
| is False | ||
| ): | ||
| raise PermissionDenied | ||
| # check for existing parameters to handle the different view parameters | ||
| if proj_id is not None and scen_id is not None: | ||
| return view_func(request, proj_id, scen_id, *args, **kwargs) | ||
| elif proj_id is not None: | ||
| return view_func(request, proj_id, *args, **kwargs) | ||
| elif scen_id is not None: | ||
| return view_func(request, scen_id, *args, **kwargs) | ||
|
|
||
| return _wrapped_view |
Oops, something went wrong.
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.