-
Notifications
You must be signed in to change notification settings - Fork 19
ECHO-551 Replace deprecated anthropic token counter and fix server lint errors #352
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
Changes from all commits
fc334ad
f4507fc
7dc25af
b82f28b
63e53bc
6f12ca5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -201,7 +201,7 @@ def iterfile() -> Generator[bytes, None, None]: | |||||||||||
|
|
||||||||||||
| async def get_latest_project_analysis_run(project_id: str) -> Optional[dict]: | ||||||||||||
| try: | ||||||||||||
| def _get_analysis_run(): | ||||||||||||
| def _get_analysis_run() -> Optional[list[dict]]: | ||||||||||||
| with directus_client_context() as client: | ||||||||||||
| return client.get_items( | ||||||||||||
| "project_analysis_run", | ||||||||||||
|
|
@@ -215,7 +215,7 @@ def _get_analysis_run(): | |||||||||||
| }, | ||||||||||||
| ) | ||||||||||||
|
|
||||||||||||
| analysis_run = await run_in_thread_pool(_get_analysis_run) | ||||||||||||
| analysis_run: Optional[list[dict]] = await run_in_thread_pool(_get_analysis_run) | ||||||||||||
|
|
||||||||||||
| if analysis_run is None: | ||||||||||||
| return None | ||||||||||||
|
|
@@ -247,10 +247,7 @@ async def post_create_project_library( | |||||||||||
| from dembrane.service.project import ProjectNotFoundException | ||||||||||||
|
|
||||||||||||
| try: | ||||||||||||
| project = await run_in_thread_pool( | ||||||||||||
| project_service.get_by_id_or_raise, | ||||||||||||
| project_id | ||||||||||||
| ) | ||||||||||||
| project = await run_in_thread_pool(project_service.get_by_id_or_raise, project_id) | ||||||||||||
| except ProjectNotFoundException as e: | ||||||||||||
| raise HTTPException(status_code=404, detail="Project not found") from e | ||||||||||||
|
|
||||||||||||
|
|
@@ -298,10 +295,7 @@ async def post_create_view( | |||||||||||
| from dembrane.service.project import ProjectNotFoundException | ||||||||||||
|
|
||||||||||||
| try: | ||||||||||||
| project = await run_in_thread_pool( | ||||||||||||
| project_service.get_by_id_or_raise, | ||||||||||||
| project_id | ||||||||||||
| ) | ||||||||||||
| project = await run_in_thread_pool(project_service.get_by_id_or_raise, project_id) | ||||||||||||
| except ProjectNotFoundException as e: | ||||||||||||
| raise HTTPException(status_code=404, detail="Project not found") from e | ||||||||||||
|
|
||||||||||||
|
|
@@ -325,12 +319,13 @@ class CreateReportRequestBodySchema(BaseModel): | |||||||||||
|
|
||||||||||||
|
|
||||||||||||
| @ProjectRouter.post("/{project_id}/create-report") | ||||||||||||
| async def create_report(project_id: str, body: CreateReportRequestBodySchema) -> None: | ||||||||||||
| async def create_report(project_id: str, body: CreateReportRequestBodySchema) -> dict: | ||||||||||||
| language = body.language or "en" | ||||||||||||
| try: | ||||||||||||
| report_content_response = await get_report_content_for_project(project_id, language) | ||||||||||||
| except ContextTooLongException: | ||||||||||||
| def _create_error_report(): | ||||||||||||
|
|
||||||||||||
| def _create_error_report() -> dict: | ||||||||||||
| with directus_client_context() as client: | ||||||||||||
| return client.create_item( | ||||||||||||
| "project_report", | ||||||||||||
|
|
@@ -342,13 +337,13 @@ def _create_error_report(): | |||||||||||
| "error_code": "CONTEXT_TOO_LONG", | ||||||||||||
| }, | ||||||||||||
| )["data"] | ||||||||||||
|
|
||||||||||||
| report = await run_in_thread_pool(_create_error_report) | ||||||||||||
| return report | ||||||||||||
| except Exception as e: | ||||||||||||
| raise e | ||||||||||||
|
|
||||||||||||
|
Comment on lines
343
to
345
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Remove redundant catch/rethrow; log and re-raise cleanly. Catching Exception just to re-raise is noise. Either let it bubble or log then raise. Apply: - except Exception as e:
- raise e
+ except Exception:
+ logger.exception(f"create_report failed for project {project_id}")
+ raise📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||
| def _create_report(): | ||||||||||||
| def _create_report() -> dict: | ||||||||||||
| with directus_client_context() as client: | ||||||||||||
| return client.create_item( | ||||||||||||
| "project_report", | ||||||||||||
|
|
@@ -359,7 +354,7 @@ def _create_report(): | |||||||||||
| "status": "archived", | ||||||||||||
| }, | ||||||||||||
| )["data"] | ||||||||||||
|
|
||||||||||||
| report = await run_in_thread_pool(_create_report) | ||||||||||||
| return report | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
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.
🧩 Analysis chain
Blocker: create_report lacks auth and ownership checks.
This endpoint currently allows anyone to create a report for any project. Mirror the access guard used elsewhere (403 for non-owner, 404 if missing).
Apply:
Also note: return type changed from None to dict — verify API consumers.
🏁 Script executed:
Length of output: 412
🏁 Script executed:
Length of output: 12093
🏁 Script executed:
Length of output: 7113
🏁 Script executed:
Length of output: 722
Blocker: create_report lacks auth and ownership checks.
This endpoint allows unauthenticated requests to create reports for any project. Apply the same access guard pattern used in
create_libraryand other protected endpoints:@ProjectRouter.post("/{project_id}/create-report") -async def create_report(project_id: str, body: CreateReportRequestBodySchema) -> dict: +async def create_report( + project_id: str, + body: CreateReportRequestBodySchema, + auth: DependencyDirectusSession, +) -> dict: language = body.language or "en" + # Ownership / access guard + from dembrane.service import project_service + from dembrane.service.project import ProjectNotFoundException + try: + project = await run_in_thread_pool(project_service.get_by_id_or_raise, project_id) + except ProjectNotFoundException as e: + raise HTTPException(status_code=404, detail="Project not found") from e + if not auth.is_admin and project.get("directus_user_id", "") != auth.user_id: + raise HTTPException(status_code=403, detail="User does not have access to this project")🤖 Prompt for AI Agents