fix: Resource permission list does not display non-regular user roles#4421
fix: Resource permission list does not display non-regular user roles#4421zhanweizhang7 merged 1 commit intov2from
Conversation
|
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. DetailsInstructions 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. |
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| "role_setting.type": "USER", | ||
| }) | ||
| if role_name: | ||
| user_query_set = user_query_set.filter( |
There was a problem hiding this comment.
Your current implementation looks mostly correct, but there are a few improvements to be made for clarity and potential future enhancements:
-
Consistent Use of Model Class: Ensure that the
get_dynamics_modelfunction returns an actual model class instead of just its string representation. -
Type Checking: Consider adding type hints within the filter conditions to make it clear what types of values are expected.
-
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_modelfunction now returns a valid Django model instead of just a dictionary mapping keys to field types. - Field Definition: Added
max_lengthattribute tomodels.CharFieldfor better data validation. - Descriptive Variable Names: Used
dynamics_modelwhere 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.
fix: Resource permission list does not display non-regular user roles