-
Notifications
You must be signed in to change notification settings - Fork 2.5k
fix: Common user folder permission #4288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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. 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. |
|
[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 |
| variable.get('variable')[1:]) for variable in variable_list] | ||
|
|
||
| def reset_variable(self, variable): | ||
| value = self.workflow_manage.get_reference_field( |
There was a problem hiding this comment.
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:
- 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 ...
- Example:
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 ...
-
Functionality Duplication: The logic within
get_first_non_nullandset_variable_to_jsonmight become redundant if you combine them into one function based on some conditions. -
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() |
There was a problem hiding this comment.
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:
-
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 )
-
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. -
Testing: Ensure thorough testing is performed with various scenarios to validate the permission handling logic correctly.
-
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.
fix: Common user folder permission