Skip to content

Conversation

@shaohuzhang1
Copy link
Contributor

fix: The role-based authorization option is temporarily hidden --bug=1060787 --user=张展玮 【资源管理】偶先不展示按角色授权选项的现象 https://www.tapd.cn/62980211/s/1760688

--bug=1060787 --user=张展玮 【资源管理】偶先不展示按角色授权选项的现象 https://www.tapd.cn/62980211/s/1760688
@f2c-ci-robot
Copy link

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

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 current code is mostly clean but can be optimized and improved in several ways:

  1. Function Name: The name getPermissionOptions more accurately reflects what the function does compared to permissionOptions. It's clearer that this function returns an array of permission options based on environment edition.

  2. Semicolon Placement: There are unnecessary semicolons after some lines (e.g., ,) which should be removed for consistency.

  3. Redundant Comments: Some comments might be redundant since their purpose aligns with the preceding logic.

  4. Line Continuation: Although not strictly necessary, it might improve readability to add line continuation characters (\\) or use template literals where appropriate.

Here's a revised version of the code with these suggestions applied:

import { AuthorizationEnum } from '@/enums/system';
import { t } from '@/locales';
import { hasPermission } from '@/utils/permission';
import { EditionConst } from '@/utils/permission/data';

const permissionOptions = [
  {
    label: t('views.system.resourceAuthorization.setting.notAuthorized'),
    value: 'NOT_AUTHORIZED',
  },
  // Other permissions...
];

function getPermissionOptions() {
  if (hasPermission([EditionConst.IS_EE, EditionConst.IS_PE], 'OR')) {
    return [...permissionOptions, {
      label: t('views.system.resourceAuthorization.setting.role'),
      value: AuthorizationEnum.ROLE,
      desc: t('views.system.resourceAuthorization.setting.roleDesc'),
    }];
  }
  return permissionOptions;
}

export { getPermissionOptions };

Key Changes:

  • Variable Naming: Changed notCommunity to getPermissionOptions.
  • Removed Unnecessary Semicolons.
  • Improved Comments: Removed redundancies in comments.
  • Enhanced Code Clarity: Improved code readability by separating concerns better and using modern JavaScript features like arrow functions and array spread syntax.

})
const permissionObj = ref<any>({
APPLICATION: new ComplexPermission(
[RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE],
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 does not contain significant irregularities or critical issues. However, here are some optimizations and suggestions:

  1. Refactor Computed Property: The permissionOptions computed property could be more efficient if it directly calls the asynchronous function without wrapping it in a computed. This allows you to call getPermissionOptions() only when necessary.

  2. Type Assertion: Ensure that the type of user.roleName is explicitly defined or correctly inferred. For example, using as RoleConst.Admin can help improve TypeScript's understanding of the expected input.

  3. Documentation Comments: Add comments explaining where relevant variables and functions are used or returned to enhance readability and maintainability.

Here's an improved version based on these suggestions:

@@ -142,8 +142,9 @@ import { isAppIcon, resetUrl } from '@/utils/common'
 import { RoleConst, PermissionConst } from '@/utils/permission/data'
 import { hasPermission } from '@/utils/permission/index'
 import { ComplexPermission } from '@/utils/permission/type'
-import { permissionOptions } from '@/views/system/resource-authorization/constant'
+import { getPermissionOptions } from '@/views/system/resource-authorization/constant'

 const store = useStore()
 const { model, user } = storeToRefs(store) // Using Vue 3 composition API for refs
 const route = useRoute()

 const props = defineProps<{
   getData?: () => void
 }>()

 const emit = defineEmits(['submitPermissions'])

// Explicitly declare user.roleName as RoleConst type (assuming it should be one of those)
const permissionOptions = computed(() => {
  return getPermissionOptions() as Promise<ComplexPermission[]>; // Adjust return type accordingly
});

const permissionObj = ref<any>({
  APPLICATION: new ComplexPermission(
    [RoleConst.ADMIN, RoleConst.WORKSPACE_MANAGE],

By making these changes, the code becomes more robust and easier to understand. Make sure to adjust any specific type assumptions based on your actual application logic and data structure.

@zhanweizhang7 zhanweizhang7 merged commit f84d093 into v2 Aug 25, 2025
3 of 6 checks passed
@zhanweizhang7 zhanweizhang7 deleted the pr@v2@fix_role_based_authorization branch August 25, 2025 07:26
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.

3 participants