Skip to content

fix: Application detail #3798

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

Merged
merged 1 commit into from
Aug 4, 2025
Merged

fix: Application detail #3798

merged 1 commit into from
Aug 4, 2025

Conversation

zhanweizhang7
Copy link
Contributor

What this PR does / why we need it?

Summary of your change

Please indicate you've done the following:

  • Made sure tests are passing and test coverage is added if needed.
  • Made sure commit message follow the rule of Conventional Commits specification.
  • Considered the docs impact and opened a new docs issue or PR with docs changes if needed.

Copy link

f2c-ci-robot bot commented Aug 4, 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.

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.

Copy link

f2c-ci-robot bot commented Aug 4, 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.

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

@zhanweizhang7 zhanweizhang7 merged commit ecd019a into v2 Aug 4, 2025
2 of 4 checks passed
@zhanweizhang7 zhanweizhang7 deleted the pr@V2@fix_application_deatil branch August 4, 2025 02:38
@@ -171,7 +171,7 @@ const ApplicationDetailRouter = {
() => {
const to: any = get_next_route()
if (to.params.from == 'resource-management') { } else {
return new ComplexPermission([RoleConst.WORKSPACE_MANAGE.getWorkspaceRole], [PermissionConst.APPLICATION_CHAT_USER_READ.getWorkspacePermissionWorkspaceManageRole], [EditionConst.IS_EE, EditionConst.IS_PE], 'OR')
return new ComplexPermission([RoleConst.WORKSPACE_MANAGE.getWorkspaceRole()], [PermissionConst.APPLICATION_CHAT_USER_READ.getWorkspacePermissionWorkspaceManageRole()], [EditionConst.IS_EE, EditionConst.IS_PE], 'OR')
}
},
() => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code seems to have formatting issues with unnecessary parentheses around function calls, which can make it harder to read and potentially cause errors due to incorrect syntax. Here are some improvements:

  1. Remove unnecessary parentheses:

    const ApplicationDetailRouter = {
      checkAppAccessRead(...args) {
        const to = get_next_route();
        if (to.params.from !== 'resource-management' && args.includes(RoleConst.WORKSPACE_MANAGE)) {
          return new ComplexPermission(args);
        }
      },
    
      // Similar methods for other access checks...
    };
  2. Consider extracting common logic into separate helper functions or variables if applicable:

    • For example, extract getComplexPermission that takes the role and permission arrays as arguments.
  3. Ensure consistent usage of arrow functions without unnecessary parameters:

    • This can help avoid confusion about implicit this behavior:
const appRouterHelper = {};

appRouterHelper.getComplexPermission = (roleArray, permArray, editionArray, operator) => {
  return new ComplexPermission(roleArray, permArray, editionArray, operator);
};

const AppDetailRouter = {
  checkAppAccessRead(roleConst, permConst, editionConst) {
    const to = get_next_route();
    if (to.params.from !== 'resource-management') {
      appRouterHelper.getComplexPermission([roleConst], [permConst], [editionConst], OR);
    }
  },

  // Similar methods for other access checks using the same helper
};
  1. Add type annotations where appropriate to improve readability and maintainability:
    const appRouterHelper = {};
    
    interface RoleConstant {
      manageWorkspace(): string;
    }
    
    interface PermissionConstant {
      applicationAccessRead(workspaceManageRole: string): string;
    }
    
    interface EditionConstant {
      isEE() boolean;
      isPE() boolean;
    }
    
    class ComplexPermission {
      constructor(
        roles: readonly string[],
        permissions: readonly string[],
        editions: readonly string[],
        operator: "AND" | "OR"
      ) {}
    }
    
    const appRouterHelper = {
      getComplexPermission: (
        rolesArray: readonly string[],
        permArray: readonly string[],
        editionArray: readonly string[],
        operator: "AND" | "OR"
      ): ComplexPermission => {
        return new ComplexPermission(rolesArray, permArray, editionArray, operator);
      },
    };
    
    const AppDetailRouter = {
      checkAppAccessRead(roleConst: Pick<RoleConstant, 'manageWorkspace'>, permConst: Pick<PermissionConstant, 'applicationAccessRead'>, editionConst: Pick<EditionConstant, 'isEE'|'isPE'>) {
        const to = get_next_route();
        if (to.params.from !== 'resource-management' && appRouterHelper.isWorkSpaceManageRoleUsed(to, roleConst)) {
          appRouterHelper.getComplexPermission([roleConst.manageWorkspace()], [permConst.applicationAccessRead(roleConst.manageWorkspace())), [editionConst.isEE(), editionConst.isPE()], "OR");
        }
      },
    
      // Similar methods using the same structure...
    
      private isWorkSpaceManageRoleUsed(route: any, roleConst: Pick<RoleConstant, 'manageWorkspace'>) {
        return Object.getOwnPropertyNames(route).includes('from', route['from'] === 'resource-management');
      }
    };

These changes should improve readability, reduce potential parsing issues, simplify method signatures, and add more clarity to the codebase.

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