-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: Application read permission #4338
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
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 |
| PermissionConstants.APPLICATION_READ.get_workspace_permission_workspace_manage_role(), | ||
| ViewPermission([RoleConstants.USER.get_workspace_role()], | ||
| [PermissionConstants.APPLICATION.get_workspace_application_permission()], | ||
| CompareConstants.AND), |
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.
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
-
@has_permissions()Usage:- Both
PromptGenerateViewandOpenViewuse@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.
- Both
-
Permission Constants:
- Replace
ApplicationConstants.APPLICATION_EDIT.get_workspace_application_permission()withApplicationConstants.APPLICATION_READ.get_workspace_application_permission(). - Similarly, replace
ApplicationConstants.APPLICATION_EDIT.get_workspace_permission_workspace_manage_role()withApplicationConstants.APPLICATION_READ.get_workspace_permission_workspace_manage_role().
- Replace
-
Tags in API Routes:
- Both routes have the same tag
"_("Application")", which might not be necessary given their context. Consider using more specific tags.
- Both routes have the same tag
-
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_APPLICATIONtoREAD_APPLICATION. - Suggested Improvement: Remove redundant
WorkspaceManageRolechecks 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
passThis 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), |
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.
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' | ||
| ), |
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.
The code provided has a couple of minor issues:
-
Duplicate Permissions: The
PermissionConst.APPLICATION_EDITis 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' )
-
Consistency in Code Formatting: The code could benefit from better formatting consistency. However, this issue might be subjective.
-
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.
fix: Application read permission