Skip to content

Conversation

@shaohuzhang1
Copy link
Contributor

feat: About permission

@f2c-ci-robot
Copy link

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

label=_('Update License')
)
SWITCH_LANGUAGE = Permission(group=Group.OTHER, operate=Operate.EDIT,
role_list=[RoleConstants.ADMIN, RoleConstants.USER],
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 mostly correct, but there are some suggestions to improve it:

  1. Remove Redundant READ Enum Member:
    The READ member is repeated in both Operate and PermissionConstants. This redundancy can remove the need for duplicate values.

    class Operate(Enum):
        AUTH = "READ+AUTH" # 资源授权
        TAG = "READ+TAG" # 标签设置
        REPLACE = "READ+REPLACE" # 标签设置
        UPDATE = "READ+UPDATE"

2. **Optimize Documentation Strings**:
   Ensure that documentation strings are concise and descriptive, and keep consistent spacing around them.

   ```python
   class AboutReadPermission(Permission):
       group = Group.OTHER
       operation = Operate.READ
       role_list = [RoleConstants.ADMIN, RoleConstants.USER]
       parent_groups = [SystemGroup.OTHER, WorkspaceGroup.OTHER, UserGroup.OTHER]
       label = _('About')
       

   class AboutUpdatePermission(Permission):
       group = Group.OTHER
       operation = Operate.UPDATE
       role_list = [RoleConstants.ADMIN]
       parent_groups = [SystemGroup.OTHER]
       label = _('Update License')
  1. Separate Permissions into Classes (Optional):
    If your application requires more complex permission checks or organization, consider separating permissions into separate classes.

    class BasePermission(Permission):
        def __init__(self, operation, role_list=[], parent_groups=[]):
            super().__init__(group=Group.OTHER, operate=operation, role_list=role_list, parent_group=parent_groups)
    
    class AboutReadPermission(BasePermission):
        label = _('About')
    
    class AboutUpdatePermission(BasePermission):
        label = _('Update License')

By making these adjustments, the code will be cleaner, more readable, and potentially easier to maintain.

import { PermissionConst, RoleConst } from '@/utils/permission/data'
const {user, theme} = useStore()
const isDefaultTheme = computed(() => {
return theme.isDefaultTheme()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There appears to be an issue with line 49 of the provided code snippet. The v-hasPermission directive seems to have been replaced by v-if, which may cause unexpected behavior if you intend to use permission-based logic for displaying certain components.

Additionally, lines 68-73 should be moved outside of the <template> block as they don't belong there. They appear to define utility functions and store variables, which are typically handled within the setup function in Vue.js.

For optimization, remove the unnecessary import statements for the roles like 'USER' before importing from @/utils/permission/data. Here's the revised version:

<template>
  <!-- Your template content here -->
</template>

<script lang="ts">
import {defineComponent} from "vue";
// import {RoleConst, PermissionConst} from "@/utils/permission/data"; // Remove this line
import userStore from "@/stores/userStore";

export default defineComponent({
  data() {
    return {};
  },
  computed: {
    isDefaultTheme() {
      return this.user.theme.isDefaultTheme();
    }
  }
});
</script>

This approach keeps the scope clean while ensuring all necessary imports are included where needed. Make sure each component has the appropriate role checks based on your application's security requirements.

ABOUT_UPDATE: new Permission('OTHER:READ+UPDATE'),
SWITCH_LANGUAGE: new Permission('OTHER:READ+EDIT'),
CHANGE_PASSWORD: new Permission('OTHER:READ+CREATE'),
SYSTEM_API_KEY_EDIT: new Permission('OTHER:READ+DELETE'),
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 snippet for PermissionConst looks mostly correct with minor formatting and comment changes. Here's a concise review:

  1. Comments: Ensure each permission is well-commented to describe its purpose clearly.

  2. Order of Operations: Permissions related to specific actions (e.g., updating, reading) should be mentioned first. It makes sense to group those at the beginning.

  3. Syntax Consistency: The syntax seems consistent, but ensure there are no typos or extra characters that might cause issues.

  4. Documentation: Consider adding comments describing what each permission string means if it's not clear from context.

Overall, the existing permissions seem logically organized and don't contain known issues. If there are additional requirements or security concerns, consider consulting them further.

@zhanweizhang7 zhanweizhang7 merged commit 4648f08 into v2 Oct 22, 2025
4 of 5 checks passed
@zhanweizhang7 zhanweizhang7 deleted the pr@v2@feat_about_permission branch October 22, 2025 06:13
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