Skip to content

Conversation

@shaohuzhang1
Copy link
Contributor

fix: Common user folder permission

@f2c-ci-robot
Copy link

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

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 29, 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.

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

variable.get('variable')[1:]) for variable in variable_list]

def reset_variable(self, variable):
value = self.workflow_manage.get_reference_field(
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 appears to be functioning correctly, but I can suggest a few improvements:

  1. Readability: It would be helpful to add more meaningful names to variables and method parameters for better understanding.
    • Example:
      def get_first_non_empty_value(self, variable_list):
          # ... existing code ...

2. **Type Hints**: Adding type hints to `set_variable_to_json`'s return type could make it clearer what kind of data is expected to be returned.
   - Proposed change:
     ```python
     def set_variable_to_json(self, variable_list) -> List[Union[str, list, dict]]:
         # ... existing code ...
  1. Functionality Duplication: The logic within get_first_non_null and set_variable_to_json might become redundant if you combine them into one function based on some conditions.

  2. Error Handling: Consider adding error handling to manage cases where the input values or references cannot be retrieved from workflow_manage.

Here's an improved version incorporating these comments and suggestions:

from typing import Union, List

class ReferenceManager:
    @staticmethod
    def get_reference_field(reference_id: str, path: List[str]) -> Union[str, list, dict]:
        # Placeholder implementation
        pass

class WorkflowManager:
    class Variable:
        def __init__(self, name: str, reference: tuple, optional_parts: list):
            self.name = name
            self.reference = reference
            self.optional_parts = optional_parts

    def __init__(self):
        self.variables = {}

    def register_variable(self, name: str, reference: tuple, optional_parts: list = []):
        self.variables[name] = self.Variable(name, reference, optional_parts)

def process_variables(workflow_manager: WorkflowManager) -> None:
    def get_first_non_empty_value(variable_list: List['WorkflowManager.Variable']) -> Union[None, str, list, dict]:
        for variable in variable_list:
            value = workflow_manager.register_variable.get_reference_field(
                variable.reference,
                variable.optional_parts)
            if value is not None and not (
                    isinstance(value, (str, list, dict)) and len(value) == 0):
                return value
        return None

    def map_variablesToJson(variable_list: List['WorkflowManager.Variable']) -> Dict[str, Union[str, list, dict]]:
        return {
            variable.name: workflow_manager.register_variable.get_reference_field(
                variable.reference,
                variable.optional_parts)
            for variable in variable_list}

    def reset_variables(variable: 'WorkflowManager.Variable') -> None:
        value = workflow_manager.register_variable.get_reference_field(
            variable.reference,
            variable.optional_parts)
        if value is not None:
            # Implement resetting logic here using the obtained value
            print(f"Resetting variable {variable.name} with value {value}")

# Example usage
manager = WorkflowManager()
process_variables(manager)
reset_variables(manager.register_variable("example", ("ref1", "part1")))

This revised code includes the suggested improvements and organizes the functionality into methods that perform specific tasks related to processing and managing workflows and their variables.

operate=Operate.EDIT,
resource_path=f"/WORKSPACE/{kwargs.get('workspace_id')}/{kwargs.get('source')}/{kwargs.get('folder_id')}"
)], CompareConstants.AND),
RoleConstants.WORKSPACE_MANAGE.get_workspace_role()
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 appears correct and does not contain significant issues or optimizations at this time. It sets up permissions that allow users to view their own folders within a workspace, but it allows others (Workspace Managers) to edit any folder regardless of who owns it.

Suggestions:

  1. Permissions Clarification: Consider adding more specific role-based checks if you want to distinguish between the owner and other editors.

    # Example: Only owners can edit their own folders
    lambda r, kwargs: ViewPermission(
        [RoleConstants.USER.get_workspace_role(kwargs['source'], 'owner'),
         RoleConstants.WORKSPACE_MANAGE.get_workspace_role()],
        [Permission(...)], CompareConstants.OR
    )
  2. Parameterization: If these functions could be reused for different sources (e.g., files), consider parameterizing them with the source type for better reusability and readability.

  3. Testing: Ensure thorough testing is performed with various scenarios to validate the permission handling logic correctly.

  4. Documentation: Add comments or documentation to explain the purpose of each function and how permissions are applied.

By implementing some of the proposed changes, you can further enhance the security and flexibility of your application's access control mechanisms.

@zhanweizhang7 zhanweizhang7 merged commit c86306a into v2 Oct 29, 2025
4 of 5 checks passed
@zhanweizhang7 zhanweizhang7 deleted the pr@v2@fix_common_user branch October 29, 2025 10:32
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