Skip to content

feat: When resource authorization is set to unauthorized, sub resource cascading is set#4837

Merged
shaohuzhang1 merged 1 commit intov2from
pr@v2@feat_resource_auth
Mar 3, 2026
Merged

feat: When resource authorization is set to unauthorized, sub resource cascading is set#4837
shaohuzhang1 merged 1 commit intov2from
pr@v2@feat_resource_auth

Conversation

@shaohuzhang1
Copy link
Contributor

feat: When resource authorization is set to unauthorized, sub resource cascading is set

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Mar 3, 2026

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 Mar 3, 2026

[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

}
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 provided code generally looks clean and efficient. However, there are a few areas of improvement:

  1. Return early from dfs function: Inside the dfs function, when you find the target node (matching folderId), you should immediately return to avoid unnecessary iterations over subsequent nodes.
if (node.id === folderId) {
  target = node;
  return; // This ensures that no more iterations happen if we found the node.
}

With this change, the function will not continue searching further after finding the matching node, which can improve performance.

  1. Simplifying conditional checks in submitPermissions:
    function submitPermissions(value: string, row: any) {
      const obj = [
        ...row.permissions || [], // Merge existing permissions with new ones to handle undefined case.
      ];
    
      if ('VIEW'.includes(value)) {
        obj.unshift({ permission: value });
        emitSubmitPermissions(...props.data);
        return;
      }
    
      const { id } = row;
      
      // Handle role management cases first
      ...
    
      // Not authorized case specifically for folders
      if ('NOT_AUTH' == row.resource_type && ['NOT_AUTH'].includes(value)) {
        getResourcesByFolderId(props.data, id).forEach((n) => {
          obj.push({ target_id: n.id, permission: 'NOT_AUTH' });
        });
      }
    
      emit('submitPermissions', obj)
    }

This version simplifies how roles are handled in addition to managing specific resource types (NOT_AUTH) for folders, making the function cleaner and potentially reducing boilerplate logic.

  1. Consistent naming conventions: Functions like getResourcesByFolderId, even though written as JavaScript, follow a convention typical in TypeScript or React components. It might be useful to maintain consistency depending on what other languages/technologies you use across your project.

@shaohuzhang1 shaohuzhang1 merged commit 2827bb2 into v2 Mar 3, 2026
3 checks passed
@shaohuzhang1 shaohuzhang1 deleted the pr@v2@feat_resource_auth branch March 3, 2026 09:33
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.

1 participant