-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[WEB-2126] chore: guest and viewer role permission #5347
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
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
e724194
chore: user store code refactor
anmolsinghbhatia e1471fe
chore: general unauthorized screen asset added
anmolsinghbhatia aa73ed1
chore: workspace setting sidebar options updated for guest and viewer
anmolsinghbhatia 1089c2f
chore: NotAuthorizedView component code updated
anmolsinghbhatia acac14c
chore: project setting layout code refactor
anmolsinghbhatia 0ff7f12
chore: workspace setting members and exports page permission validati…
anmolsinghbhatia b50ebd3
chore: workspace members and exports settings page improvement
anmolsinghbhatia 8ae4c7c
chore: project invite modal updated
anmolsinghbhatia d2cf355
chore: workspace setting unauthorized access empty state
anmolsinghbhatia fa51873
chore: workspace setting unauthorized access empty state
anmolsinghbhatia f0906ae
chore: project settings sidebar permission updated
anmolsinghbhatia 8818beb
fix: project settings user role permission updated
anmolsinghbhatia af31302
chore: app sidebar role permission validation updated
anmolsinghbhatia 32e9eb5
chore: app sidebar role permission validation
anmolsinghbhatia f0242c2
chore: disabled page empty state validation
anmolsinghbhatia ca47377
chore: app sidebar add project improvement
anmolsinghbhatia bcf9364
chore: guest role changes
NarayanBavisetti ec96701
Merge branch 'fix-user-role-permission' of github.com:makeplane/plane…
NarayanBavisetti 2eeeba3
fix: user favorite
anmolsinghbhatia c03c6f0
chore: changed pages permission
NarayanBavisetti 4260e0e
chore: guest role changes
NarayanBavisetti c4a1cd4
fix: app sidebar project item permission
anmolsinghbhatia caef0d8
fix: project setting empty state flicker
anmolsinghbhatia 8ad025e
fix: workspace setting empty state flicker
anmolsinghbhatia bc35949
chore: granted notification permission to viewer
NarayanBavisetti 7bf6d59
Merge branch 'fix-user-role-permission' of github.com:makeplane/plane…
NarayanBavisetti 50ce413
chore: project invite and edit validation updated
anmolsinghbhatia 4349b5a
chore: favorite validation added for guest and viewer role
anmolsinghbhatia 6c808c4
chore: create view validation updated
anmolsinghbhatia 1e8698c
chore: views permission changes
NarayanBavisetti 2a68a42
Merge branch 'fix-user-role-permission' of github.com:makeplane/plane…
NarayanBavisetti 3151bce
chore: create view empty state validation updated
anmolsinghbhatia 0cdb092
chore: created ENUM for permissions
NarayanBavisetti 05dc43e
Merge branch 'fix-user-role-permission' of github.com:makeplane/plane…
NarayanBavisetti a91e94a
Merge branch 'preview' into fix-user-role-permission
NarayanBavisetti 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,3 +12,4 @@ | |
| ProjectMemberPermission, | ||
| ProjectLitePermission, | ||
| ) | ||
| from .base import allow_permission, ROLE | ||
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,61 @@ | ||
| from plane.db.models import WorkspaceMember, ProjectMember | ||
| from functools import wraps | ||
| from rest_framework.response import Response | ||
| from rest_framework import status | ||
|
|
||
| from enum import Enum | ||
|
|
||
| class ROLE(Enum): | ||
| ADMIN = 20 | ||
| MEMBER = 15 | ||
| VIEWER = 10 | ||
| GUEST = 5 | ||
|
|
||
|
|
||
| def allow_permission(allowed_roles, level="PROJECT", creator=False, model=None): | ||
| def decorator(view_func): | ||
| @wraps(view_func) | ||
| def _wrapped_view(instance, request, *args, **kwargs): | ||
|
|
||
| # Check for creator if required | ||
| if creator and model: | ||
| obj = model.objects.filter( | ||
| id=kwargs["pk"], created_by=request.user | ||
| ).exists() | ||
| if obj: | ||
| return view_func(instance, request, *args, **kwargs) | ||
|
|
||
| # Convert allowed_roles to their values if they are enum members | ||
| allowed_role_values = [ | ||
| role.value if isinstance(role, ROLE) else role | ||
| for role in allowed_roles | ||
| ] | ||
|
|
||
| # Check role permissions | ||
| if level == "WORKSPACE": | ||
| if WorkspaceMember.objects.filter( | ||
| member=request.user, | ||
| workspace__slug=kwargs["slug"], | ||
| role__in=allowed_role_values, | ||
| is_active=True, | ||
| ).exists(): | ||
| return view_func(instance, request, *args, **kwargs) | ||
| else: | ||
| if ProjectMember.objects.filter( | ||
| member=request.user, | ||
| workspace__slug=kwargs["slug"], | ||
| project_id=kwargs["project_id"], | ||
| role__in=allowed_role_values, | ||
| is_active=True, | ||
| ).exists(): | ||
| return view_func(instance, request, *args, **kwargs) | ||
|
|
||
| # Return permission denied if no conditions are met | ||
| return Response( | ||
| {"error": "You don't have the required permissions."}, | ||
| status=status.HTTP_401_UNAUTHORIZED, | ||
| ) | ||
|
|
||
| return _wrapped_view | ||
|
|
||
| return decorator |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unused imports
allow_permissionandROLE.The imports
allow_permissionandROLEfrom.baseare currently unused in this module. Consider removing them or adding them to__all__if they're intended to be part of the module's public API.- from .base import allow_permission, ROLECommittable suggestion
Tools
Ruff
GitHub Check: Codacy Static Code Analysis