Skip to content

Conversation

@shaohuzhang1
Copy link
Contributor

fix: Resource authorization Sub-resource authorization Parent directory cascading authorization

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Oct 24, 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 Oct 24, 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

@shaohuzhang1 shaohuzhang1 merged commit 58f29ee into v2 Oct 24, 2025
4 of 5 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@v2@fix_resource_auth branch October 24, 2025 09:09
}
emit('submitPermissions', obj)
}
const provider_list = ref<Array<Provider>>([])
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 looks well structured but has some optimizations and improvements that could enhance performance and readability.

  1. Optimization:

    • In the emitSubmitPermissions function, 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.
  2. Avoid Global State:

    • The variables obj, permissionValue, and rowFolderId are defined within different scopes (submitPermissions vs. props) but used across both. This might lead to unexpected side effects if they aren't properly scoped or initialized.
  3. Variable Naming:

    • Names such as TreeToFlatten and emitterSubmitPermissions don't clearly state what they represent. It's better to have descriptive names.
  4. 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.

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.assign instead 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.

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.

2 participants