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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ui/src/router/modules/application-detail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,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_ACCESS_READ.getWorkspacePermissionWorkspaceManageRole], [EditionConst.IS_EE, EditionConst.IS_PE], 'OR')
return new ComplexPermission([RoleConst.WORKSPACE_MANAGE.getWorkspaceRole(),], [PermissionConst.APPLICATION_ACCESS_READ.getWorkspacePermissionWorkspaceManageRole()], [EditionConst.IS_EE, EditionConst.IS_PE], 'OR')
}
},
() => {
Expand Down Expand Up @@ -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.

Expand Down
Loading