fix: Resource authorization Sub-resource authorization Parent directory cascading authorization#4255
Conversation
…ry cascading authorization
|
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 |
| } | ||
| emit('submitPermissions', obj) | ||
| } | ||
| const provider_list = ref<Array<Provider>>([]) |
There was a problem hiding this comment.
The code looks well structured but has some optimizations and improvements that could enhance performance and readability.
-
Optimization:
- In the
emitSubmitPermissionsfunction, you can use array methods like.map()and recursion directly without converting to a flat array with unnecessary steps. Consider using nested loops for more efficient manipulation of children arrays.
- In the
-
Avoid Global State:
- The variables
obj,permissionValue, androwFolderIdare defined within different scopes (submitPermissionsvs.props) but used across both. This might lead to unexpected side effects if they aren't properly scoped or initialized.
- The variables
-
Variable Naming:
- Names such as
TreeToFlattenandemitterSubmitPermissionsdon't clearly state what they represent. It's better to have descriptive names.
- Names such as
-
Return Statement in
submitPermissions:- The
return null;statement is not needed after emitting the event because it doesn't affect the flow. Removing it can make the code cleaner.
- The
Here’s an improved version based on these points:
function submitPermissions(value: string, row: any) {
const permissionObject: { [id: number]: number } = {}
if (value !== 'NOT_AUTH') {
Object.assign(permissionObject, {[active.id]: 0})
}
const filteredItems = TreeToFlatten([active])
.filter(item => item.id !== active.id)
let resultArr = []
if (['VIEW', 'MANAGE', 'ROLE'].includes(value)) {
const emitSubmitPermissions = (treeData: any[], ids: Array<string>, result: Array<any>): void => {
for (const node of treeData) {
const isMatch = node.permission === 'NOT_AUTH' && ids.includes(node.id)
if (isMatch) {
ids.push(node.folder_id)
result.push({target_id: node.id, permission: 'VIEW'})
}
if (node.children?.length > 0) {
emitSubmitPermissions(node.children, ids.slice(), [...result]);
}
}
};
emitSubmitPermissions(props.data, [row.folder_id], []);
}
emit('submitPermissions', permissionObject);
}Key Changes:
- Used
Object.assigninstead of initializing with{}and assignment. - Renamed functions and parameters for clarity.
- Removed unneeded variables.
- Improved loop structure for
emitSubmitPermissions. - Ensured the event emission logic remains simple and clear.
fix: Resource authorization Sub-resource authorization Parent directory cascading authorization