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 |
| 'no_tag': 'NO_TAG' in raw_tags, | ||
| 'desc': request.query_params.get("desc"), | ||
| 'user_id': request.query_params.get('user_id') | ||
| } |
There was a problem hiding this comment.
I apologize, but I can't fully review the code snippet you provided because it's incomplete. Without more context, including full import statements, actual function definitions, or additional parts of the code, it's difficult to determine what might be wrong with it.
The post method seems fine at this point, but there are a few suggestions:
-
Permissions Logic: The permission logic appears correct, but make sure that all permissions specified in
PermissionConstants.KNOWLEDGE.get_workspace_knowledge_permission()exist and have been correctly defined elsewhere in your project. -
Field Handling:
"tags[]"should be handled similar to other query parameters in terms of type conversion (e.g., converting from a string list to a comma-separated string).- Ensure that any filtering conditions (
tag,tag_exclude) use proper field lookups if they're not already being used in Django ORM queries.
-
Parameter Naming Consistency: It would help readability if parameter names like
user_idwere consistently named throughout the API endpoints.
Here is an example how some improvements could be made based on these observations:
from typing import List
class QueryData:
def __init__(
self,
workspace_id: str,
knowledge_id: str,
folder_id: str = '',
name: str = None,
tags: List[str] = [],
no_tag: bool = False,
desc: str = None,
user_id: str = ''
):
self.workspace_id = workspace_id
self.knowledge_id = knowledge_id
self.folder_id = folder_id
self.name = name
self.tags = tags
self.no_tag = no_tag
self.desc = desc
self.user_id = user_id
# Simplify processing tags
def parse_tags(query_params) -> (List[int], str):
raw_tags = query_params.getlist("tags[]")
return [int(tag.strip()) for tag in raw_tags if tag.isnumeric()] + ['NO_TAG'], 'NO_TAG' in raw_tags
@app.post("/workspaces/{workspace_id}/knowledge/{knowledge_id}")
@permission_required([PermissionConstants.KNOWLEDGE.get_workspace_knowledge_permission()], CompareConstants.AND)
def post(request: Request, workspace_id: str, knowledge_id: str):
# ... existing code ...
@app.get("/workspaces/{workspace_id}/knowledge/{knowledge_id}")
def get(request: Request, workspace_id: str, knowledge_id: str):
raw_tags, no_tag_value = parse_tags(request.query_params)
data = {
"workspace_id": workspace_id,
"knowledge_id": knowledge_id,
"folder_id": request.query_params.get("folder_id", ''),
"name": request.query_params.get("name", None),
"tags": raw_tags[::],
"no_tag": no_tag_value,
"desc": request.query_params.get("desc", None),
"user_id": request.query_params.get("user_id", '')
}
return result.success(DocumentSerializers.Query(data=data))These changes improve readability, ensure consistent naming conventions, and handle parsing of tags more robustly. Please replace placeholders like result.success and other non-existent functions/variables with real implementations and ensure all necessary imports are included.
feat: Doc list filter parameter