-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: Workspace manager folder #4267
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 |
| 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')}/{r.data.get('parent_id')}"), | ||
| lambda r, kwargs: Permission(group=Group(kwargs.get('source')), operate=Operate.EDIT, | ||
| resource_path=f"/WORKSPACE/{kwargs.get('workspace_id')}:ROLE/WORKSPACE_MANAGE" |
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 seems to be an error in the code snippet you provided. In the @has_permissions decorators:
- The operation being checked is mixed between
Operation.UPDATEandOPERATE.CREATE. Typically, one should use eitherUPDATEorCREATE, not both.
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')}/{r.data.get('parent_id')}"),
lambda r, kwargs: Permission(group=Group(kwargs.get('source')), operate=Operate.EDIT,
resource_path=f"/WORKSPACE/{kwargs.get('workspace_id')}:ROLE/WORKSPACE_MANAGE")This will result in an inconsistency and might lead to unexpected behavior in your application.
-
Ensure that all parameters used (
'source', 'workspace_id', 'parent_id') are correctly set before accessing them with.get(). Using these values directly without setting it first could throw a KeyError if those keys do not exist in the request data. -
Consider whether the logic for checking permissions should be more specific or general based on additional fields or context within your application.
-
If you intend to perform different operations depending on certain conditions, ensure that each decorator uses the appropriate constants from your library (e.g.,
Permission.Operation.UPDATEvs.Permission.Operate.CREATE).
| bus.emit('select_node', data.folder_id) | ||
| openCreateMcpDialog(data) | ||
| return | ||
| } |
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 looks mostly correct but can be simplified for better readability and maintainability. Here's an optimized version:
function openCreateDialog(data?: any) {
if (!data || !this.isToolTypeSupported(data.tool_type)) {
return;
}
this.selectNodeFromData(data);
this.openCreateMcpDialog(data);
this.handlePostOpenCreateDialog();
}
handlePostOpenCreateDialog() {
// Add any additional cleanup or logging here
}Optimization Suggestions:
-
Early Return: The early
returnafter checking!data || !this.isToolTypeSupported(data.tool_type)ensures that unnecessary checks are skipped when the input data is insufficient. -
Code Clarity: Breaking complex logic into separate methods (
selectNodeFromData,openCreateMcpDialog) improves code modularity and clarity. -
Method Name Clarification: The method name could be made more descriptive, such as
prepareAndOpenDialog. -
Add Additional Checks: If necessary, you may want to add more robust error handling or validation of
data.
fix: Workspace manager folder