Skip to content

Conversation

@shaohuzhang1
Copy link
Contributor

fix: Folder permission of workspace manager

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Oct 30, 2025

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.

Instructions 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.

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Oct 30, 2025

[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.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

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,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After reviewing the provided code snippet, I identified several issues and suggestions for improvement:

Issues Found:

  1. Permission Logic Divergence:

    • The create permission checks different group names ({kwargs.get('source')}_FOLDER)
      and resource paths compared to the edit permission.
  2. Duplicate Permissions:

    • There is duplicated logic for checking permissions with resource_path=f"/WORKSPACE/{kwargs.get('workspace_id'):ROLE/WORKSPACE_MANAGE".
  3. Resource Path Formatting:

    • The resource_path formatting differs between CREATE, EDIT, and DELETE.
  4. Type Hint Usage:

    • Typing hints like # type: ignore should be used judiciously and ideally removed if applicable.

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:

  1. Consistent Resource Paths:

    • All permissions now share the same resource_path pattern for clarity and consistency.
  2. Simplified Duplicate Code:

    • Combined duplicate permission conditions into simpler calls where possible.
  3. Removed Type Hint:

    • Removed unnecessary type:ignore lines.

These changes should improve readability, maintainability, and reduce potential errors associated with the original code.

@zhanweizhang7 zhanweizhang7 merged commit ef162bd into v2 Oct 30, 2025
4 of 5 checks passed
@zhanweizhang7 zhanweizhang7 deleted the pr@v2@fix_folder_permission branch October 30, 2025 02:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants