Skip to content

feat: Doc list filter parameter#4838

Merged
zhanweizhang7 merged 1 commit intov2from
pr@v2@feat_doc_list
Mar 4, 2026
Merged

feat: Doc list filter parameter#4838
zhanweizhang7 merged 1 commit intov2from
pr@v2@feat_doc_list

Conversation

@shaohuzhang1
Copy link
Contributor

feat: Doc list filter parameter

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Mar 4, 2026

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 Mar 4, 2026

[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

'no_tag': 'NO_TAG' in raw_tags,
'desc': request.query_params.get("desc"),
'user_id': request.query_params.get('user_id')
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

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:

  1. 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.

  2. 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.
  3. Parameter Naming Consistency: It would help readability if parameter names like user_id were 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.

@zhanweizhang7 zhanweizhang7 merged commit bb66736 into v2 Mar 4, 2026
3 of 4 checks passed
@zhanweizhang7 zhanweizhang7 deleted the pr@v2@feat_doc_list branch March 4, 2026 02:42
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.

2 participants