Skip to content

refactor(api): add user Depends for list api #766

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

Merged
merged 3 commits into from
Mar 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions server/rag/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,14 @@


@router.post("/knowledge/list", dependencies=[Depends(verify_rate_limit)])
async def get_knowledge_list(params: PageParams[Knowledge]):
async def get_knowledge_list(
params: PageParams[Knowledge],
user: Annotated[User | None, Depends(get_user)] = None,
):
if user is None:
raise HTTPException(

Check warning on line 83 in server/rag/router.py

View check run for this annotation

Codecov / codecov/patch

server/rag/router.py#L82-L83

Added lines #L82 - L83 were not covered by tests
status_code=status.HTTP_401_UNAUTHORIZED, detail="Github Login needed"
)
try:
api_client = APIClient(
base_url=get_env_variable("WHISKER_API_URL"),
Expand All @@ -101,7 +108,14 @@


@router.post("/task/list", dependencies=[Depends(verify_rate_limit)])
async def get_rag_task(params: PageParams[Task]):
async def get_rag_task(
params: PageParams[Task],
user: Annotated[User | None, Depends(get_user)] = None,
):
if user is None:

Choose a reason for hiding this comment

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

The addition of a user dependency and the subsequent check for user authentication is a critical change. It ensures that only authenticated users can access these endpoints, which is important for maintaining security and data integrity.

raise HTTPException(

Check warning on line 116 in server/rag/router.py

View check run for this annotation

Codecov / codecov/patch

server/rag/router.py#L115-L116

Added lines #L115 - L116 were not covered by tests
status_code=status.HTTP_401_UNAUTHORIZED, detail="Github Login needed"
)
try:
api_client = APIClient(
base_url=get_env_variable("WHISKER_API_URL"),
Expand All @@ -114,7 +128,14 @@


@router.post("/task/restart", dependencies=[Depends(verify_rate_limit)])
async def restart_rag_task(params: RestartTaskRequest):
async def restart_rag_task(
params: RestartTaskRequest,
user: Annotated[User | None, Depends(get_user)] = None,
):
if user is None:
raise HTTPException(

Check warning on line 136 in server/rag/router.py

View check run for this annotation

Codecov / codecov/patch

server/rag/router.py#L135-L136

Added lines #L135 - L136 were not covered by tests
status_code=status.HTTP_401_UNAUTHORIZED, detail="Github Login needed"
)
try:
api_client = APIClient(
base_url=get_env_variable("WHISKER_API_URL"),
Expand Down