Skip to content
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 apps/common/constants/permission_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -1362,11 +1362,11 @@ class PermissionConstants(Enum):
)
RESOURCE_MODEL_EDIT = Permission(
group=Group.SYSTEM_RES_MODEL, operate=Operate.EDIT, role_list=[RoleConstants.ADMIN],
parent_group=[SystemGroup.RESOURCE]
parent_group=[SystemGroup.RESOURCE_MODEL]
)
RESOURCE_MODEL_DELETE = Permission(
group=Group.SYSTEM_RES_MODEL, operate=Operate.DELETE, role_list=[RoleConstants.ADMIN],
parent_group=[SystemGroup.RESOURCE]
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.

Expand Down
Loading