Skip to content

Conversation

@shaohuzhang1
Copy link
Contributor

fix: Resource model permission

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Jul 28, 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 Jul 28, 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

@zhanweizhang7 zhanweizhang7 merged commit f4ef5f2 into v2 Jul 28, 2025
3 of 4 checks passed
@zhanweizhang7 zhanweizhang7 deleted the pr@v2@fix_resource_model_permission branch July 28, 2025 08:12
parent_group=[SystemGroup.RESOURCE_MODEL]
)
OPERATION_LOG_READ = Permission(
group=Group.OPERATION_LOG, operate=Operate.READ, role_list=[RoleConstants.ADMIN],
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 looks mostly correct for defining permissions in Django's PermissionConstants enum using the enum.Enum class. However, there are a couple of improvements you can make:

  1. Consistent Enum Naming Conventions: It's conventional to use snake_case naming for enum values, which is already followed here.

  2. Optimization for Readability: The parent groups (i.e., [SystemGroup.RESOURCE], [SystemGroup.RESOURCE_MODEL]) are duplicated across multiple entries with similar operations (Edit, Delete). This could be consolidated to save space while maintaining clarity.

Here's an optimized version of the code:

from django.contrib.auth.models import Group

# Define system groups for better readability
class SystemGroup(Enum):
    RESOURCE = "resource"
    RESOURCE_MODEL = "resource_model"

# Define roles for better readability
class RoleConstants(Enum):
    ADMIN = "admin"

# Define permission constants
class Permission(ConstantsEnum):
    RESOURCE_MODEL = Permission(
        group=SysGrp.RESOURCE_MODEL,
        operate="EDIT",
        role_list=[RoleConsts.ADMIN],
        parent_group=[SystemGroup.RESOURCE_MODEL]
    )

    DELETE = Permission(
        group=SysGrp.RESOURCE_MODEL,
        operate="DELETE",
        role_list=[RoleConsts.ADMIN],
        parent_group=[SystemGroup.RESOURCE_MODEL]
    )

    # Add more permissions as needed

Summary of Changes:

  • Consistent Naming: Consistsently uses snake_case for variables and enums.
  • Optimized Parent Groups: Consolidates parent group lists in a single place for consistency within related resources or models. Adjusted variable names accordingly to fit the new structure. If you prefer not to consolidate, this might have been intentional based on context or specific requirements; if so, simply leave it unchanged.

Ensure that the updated definitions match other parts of your codebase where these enums are used, ensuring compatibility.

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