Skip to content

Conversation

@shaohuzhang1
Copy link
Contributor

fix: Application read permission

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Nov 10, 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.

Details

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 Nov 10, 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.

Details 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

PermissionConstants.APPLICATION_READ.get_workspace_permission_workspace_manage_role(),
ViewPermission([RoleConstants.USER.get_workspace_role()],
[PermissionConstants.APPLICATION.get_workspace_application_permission()],
CompareConstants.AND),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code appears to be part of Django REST Framework views that handle CRUD (Create, Read, Update, Delete) operations on application prompts and applications within a workspace. Here are some observations:

Code Snippets Analysis

  1. @has_permissions() Usage:

    • Both PromptGenerateView and OpenView use @has_permissions() decorator with similar logic but differing permission types.
    • The first argument to has_permissions() is for the edit operation (APPLICATION_EDIT), while the second argument covers manage role permissions.
  2. Permission Constants:

    • Replace ApplicationConstants.APPLICATION_EDIT.get_workspace_application_permission() with ApplicationConstants.APPLICATION_READ.get_workspace_application_permission().
    • Similarly, replace ApplicationConstants.APPLICATION_EDIT.get_workspace_permission_workspace_manage_role() with ApplicationConstants.APPLICATION_READ.get_workspace_permission_workspace_manage_role().
  3. Tags in API Routes:

    • Both routes have the same tag "_("Application")", which might not be necessary given their context. Consider using more specific tags.
  4. Role Permissions:

    • There's no change needed in the role-based access control aspects since both views operate under the user being able to read or edit the workspace roles and app related permissions.

Summary

  • Minor Error: Change the permissions from EDIT_APPLICATION to READ_APPLICATION.
  • Suggested Improvement: Remove redundant WorkspaceManageRole checks if they don't add any additional security.
  • Additional Enhancements: Ensure that the tags align with their purpose and make them less generic.

Updated Code Example

class OpenView(APIView):
    @swagger_auto_schema(responses={}, tags=[_('Application')])
    @has_permissions(
        ApplicationConstants.APPLICATION_READ.get_workspace_application_permission(),
        PermissionConstants.APPLICATION_READ.get_workspace_permission_workspace_manage_role()
    )
    def get(self, request):
        # Implement your get logic here
        pass

class PromptGenerateView(APIView):
    @swagger_auto_schema(responses={}, tags=[_('Application')])
    @has_permissions(
        ApplicationConstants.APPLICATION_READ.get_workspace_application_permission(),
        PermissionConstants.APPLICATION_READ.get_workspace_permission_workspace_manage_role()
    )
    def get(self, request):
        # Implement your get logic here
        pass

This revised code addresses the minor issue with permission constants and ensures clarity in the usage of the tags.

PermissionConstants.APPLICATION_READ.get_workspace_permission_workspace_manage_role(),
ViewPermission([RoleConstants.USER.get_workspace_role()],
[PermissionConstants.APPLICATION.get_workspace_application_permission()],
CompareConstants.AND),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is one issue or change proposed in this code snippet:

Original line:

PermissionConstants.APPLICATION_EDIT.get_workspace_application_permission(),
PermissionConstants.APPLICATION_EDIT.get_workspace_permission_workspace_manage_role()

Modified line:

PermissionConstants.APPLICATION_READ.get_workspace_application_permission(),
PermissionConstants.APPLICATION_READ.get_workspace_permission_workspace_manage_role()

Change Description:
The permissions APPLICATION_EDIT have been replaced with APPLICATION_READ, which could lead to fewer access rights being granted compared to previously.

Optimization/Suggestion:
Consider if there was a reason for initially giving edit permissions (e.g., due to system requirements or specific business logic). If not, it may be better to adjust the permissions accordingly.

However, as of now, the current modification removes edit capabilities from users who would typically need that level of permission.

PermissionConst.APPLICATION_READ.getApplicationWorkspaceResourcePermission(source_id)
],
'OR'
),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The code provided has a couple of minor issues:

  1. Duplicate Permissions: The PermissionConst.APPLICATION_EDIT is included twice: once for creating the permission (PermissionConst.APPLICATION Edit.getWorkspacePermissionWorkspaceManageRole) and again with the same conditions but under a different source ID.

    Suggestion:

    new ComplexPermission(
        [
            // Removed duplicate PermissionConst.APPLICATION_EDIT due to OR condition
            RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
            PermissionConst.APPLICATION_READ.getWorkspacePermissionWorkspaceManageRole,
            PermissionConst.APPLICATION_READ.getApplicationWorkspaceResourcePermission(source_id)
        ],
        'OR'
    )
  2. Consistency in Code Formatting: The code could benefit from better formatting consistency. However, this issue might be subjective.

  3. Code Readability: Ensure that each section of the list follows a consistent format for readability. For example, all roles should have their own entry within brackets like [RoleConst.WORKSPACE_MANAGE] instead of just using the role name directly without brackets.

These changes will improve the clarity and maintainability of the code while resolving the identified issues.

@zhanweizhang7 zhanweizhang7 merged commit f1766f9 into v2 Nov 10, 2025
3 of 5 checks passed
@zhanweizhang7 zhanweizhang7 deleted the pr@v2@fix_application_read_permission branch November 10, 2025 03:38
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