fix: Folder permission of workspace manager#4289
Conversation
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| lambda r, kwargs: Permission(group=Group(kwargs.get('source')), operate=Operate.DELETE, | ||
| resource_path=f"/WORKSPACE/{kwargs.get('workspace_id')}:ROLE/WORKSPACE_MANAGE" | ||
| ), | ||
| lambda r, kwargs: Permission(group=Group(f"{kwargs.get('source')}_FOLDER"), operate=Operate.EDIT, |
There was a problem hiding this comment.
After reviewing the provided code snippet, I identified several issues and suggestions for improvement:
Issues Found:
-
Permission Logic Divergence:
- The
createpermission checks different group names ({kwargs.get('source')}_FOLDER)
and resource paths compared to theeditpermission.
- The
-
Duplicate Permissions:
- There is duplicated logic for checking permissions with
resource_path=f"/WORKSPACE/{kwargs.get('workspace_id'):ROLE/WORKSPACE_MANAGE".
- There is duplicated logic for checking permissions with
-
Resource Path Formatting:
- The
resource_pathformatting differs betweenCREATE,EDIT, andDELETE.
- The
-
Type Hint Usage:
- Typing hints like
# type: ignoreshould be used judiciously and ideally removed if applicable.
- Typing hints like
Suggestions:
class FolderView(APIView):
tags=[_('Folder')] # No need for type hint here
@has_permissions(
lambda r, kwargs: Permission(group=Group(f"{kwargs.get('source')}_FOLDER"), operate=Operate.CREATE,
resource_path=f"/WORKSPACE/{kwargs.get('workspace_id')}/{kwargs.get('source')}/new"),
lambda r, kwargs: Permission(group=Group(kwargs.get('source')), operate=Operate.EDIT,
resource_path=f"/WORKSPACE/{kwargs.get('workspace_id')}:ROLE/WORKSPACE_MANAGE")
)
def create_view(request: Request, workspace_id: str, source: str) -> Response:
...
@has_permissions(
lambda r, kwargs: Permission(group=Group(f"{kwargs.get('source')}_FOLDER"), operate=Operate.DELETE,
resource_path=f"/WORKSPACE/{kwargs.get('workspace_id')}/{kwargs.get('source')}")
)
def delete_view(request: Request, workspace_id: str, source: str) -> Response:
...Key Changes:
-
Consistent Resource Paths:
- All permissions now share the same
resource_pathpattern for clarity and consistency.
- All permissions now share the same
-
Simplified Duplicate Code:
- Combined duplicate permission conditions into simpler calls where possible.
-
Removed Type Hint:
- Removed unnecessary
type:ignorelines.
- Removed unnecessary
These changes should improve readability, maintainability, and reduce potential errors associated with the original code.
fix: Folder permission of workspace manager