From 819dfa0524463600944ccc5b269b9d30a241fdb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=A8=E7=BC=A8?= Date: Mon, 16 Dec 2024 14:12:23 +0800 Subject: [PATCH] fix: solve the issue where the configuration information of robots from other organizations cannot be found (#588) * fix: get the bot config belongs to the org * chore: fix ci * chore: fix ci --- server/bot/router.py | 17 +++++++++++++++-- server/tests/test_main.py | 12 ++++++------ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/server/bot/router.py b/server/bot/router.py index 00775b9e..4bd489ed 100644 --- a/server/bot/router.py +++ b/server/bot/router.py @@ -114,12 +114,25 @@ def get_bot_detail( @router.get("/config") def get_bot_config( id: Optional[str] = Query(None, description="Filter bots by personal category"), - user_id: Annotated[str | None, Depends(get_user_id)] = None, + user: Annotated[User | None, Depends(get_user)] = None, ): + if not user or not user.access_token or not id: + return {"data": []} try: + auth = Auth.Token(token=user.access_token) + github_user = Github(auth=auth).get_user() + orgs_ids = [org.id for org in github_user.get_orgs()] + bot_ids = [] + + repository_config_dao = RepositoryConfigDAO() + bots = repository_config_dao.query_bot_id_by_owners(orgs_ids + [github_user.id]) + + bot_ids = [bot["robot_id"] for bot in bots if bot["robot_id"]] + bot_ids.append(id) + supabase = get_client() data = ( - supabase.table("bots").select("*").eq("id", id).eq("uid", user_id).execute() + supabase.table("bots").select("*").eq("id", id).in_("id", bot_ids).execute() ) return {"data": data.data, "status": 200} except Exception as e: diff --git a/server/tests/test_main.py b/server/tests/test_main.py index e8d343e0..f4ce6371 100644 --- a/server/tests/test_main.py +++ b/server/tests/test_main.py @@ -1,17 +1,17 @@ from fastapi.testclient import TestClient from env import ENVIRONMENT, WEB_URL, API_URL -from petercat_utils import get_env_variable from main import app client = TestClient(app) + def test_health_checker(): response = client.get("/api/health_checker") assert response.status_code == 200 assert response.json() == { - 'ENVIRONMENT': ENVIRONMENT, - 'API_URL': API_URL, - 'CALLBACK_URL': f'{API_URL}/api/auth/callback', - 'WEB_URL': WEB_URL, - } \ No newline at end of file + "ENVIRONMENT": ENVIRONMENT, + "API_URL": API_URL, + "CALLBACK_URL": f"{API_URL}/api/auth/callback", + "WEB_URL": WEB_URL, + }