Skip to content

Conversation

@shaohuzhang1
Copy link
Contributor

fix: Resource permission list does not display non-regular user roles

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Dec 3, 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 Dec 3, 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

"role_setting.type": "USER",
})
if role_name:
user_query_set = user_query_set.filter(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Your current implementation looks mostly correct, but there are a few improvements to be made for clarity and potential future enhancements:

  1. Consistent Use of Model Class: Ensure that the get_dynamics_model function returns an actual model class instead of just its string representation.

  2. Type Checking: Consider adding type hints within the filter conditions to make it clear what types of values are expected.

  3. Code Readability: Use more descriptive variable names (e.g., role_related_filter_conditions, user_query_filters) to improve code readability.

Here's an optimized version with these considerations:

def get_queryset(self, instance, is_x_pack_ee: bool):
    # Define common query fields and their types
    common_fields = {
        'user_role_relation.workspace_id': models.CharField(),
        'role_setting.type': models.CharField(max_length=100),  # Assuming this field can have different types
    }
    
    # Get the actual Django model based on some logic (not shown here)
    dynamics_model = get_dynamics_model(common_fields.keys())
    
    # Initialize base queryset
    role_name_and_type_qs = QuerySet(
        model=dynamics_model,
        **common_fields
    )
    
    # Add additional filters
    role_related_filter_conditions = {
        'user_role_relation.workspace_id': self.data.get('workspace_id')
    }
    if 'role_setting' in self.data:
        role_related_filter_conditions['role_setting__type'] = "USER"
    
    # Apply all filters to the role-related queryset
    role_name_and_type_qs = role_name_and_type_qs.filter(**role_related_filter_conditions)
    
    try:
        workspace_id = self.data['workspace_id']
    
    except KeyError:
        return QuerySet.empty()

Key Changes:

  • Model Type Return Value: The get_dynamics_model function now returns a valid Django model instead of just a dictionary mapping keys to field types.
  • Field Definition: Added max_length attribute to models.CharField for better data validation.
  • Descriptive Variable Names: Used dynamics_model where appropriate and renamed variables for clarity.
  • Exception Handling: Updated exception handling to ensure safe access to form data attributes without causing unexpected errors.

These changes enhance both functionality and maintainability of the code.

@zhanweizhang7 zhanweizhang7 merged commit e626e0e into v2 Dec 3, 2025
4 of 6 checks passed
@zhanweizhang7 zhanweizhang7 deleted the pr@v2@fix_resource_permission branch December 3, 2025 06:10
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