-
Notifications
You must be signed in to change notification settings - Fork 22
Add admin delete submission API endpoint #448
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
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -835,3 +835,35 @@ async def delete_user_submission( | |||||
| raise | ||||||
| except Exception as e: | ||||||
| raise HTTPException(status_code=500, detail=f"Error deleting submission: {e}") from e | ||||||
|
|
||||||
|
|
||||||
| @app.delete("/admin/submissions/{submission_id}") | ||||||
| async def admin_delete_submission( | ||||||
| submission_id: int, | ||||||
| x_admin_secret: Optional[str] = Header(None, alias="X-Admin-Secret"), | ||||||
| db_context=Depends(get_db), | ||||||
| ) -> dict: | ||||||
| """Admin-only: delete any submission by ID, regardless of ownership. | ||||||
|
|
||||||
| Protected by a shared secret between kernelboard and kernelbot. | ||||||
|
Comment on lines
+843
to
+848
|
||||||
| Kernelboard verifies admin identity (whitelist) before calling this. | ||||||
| """ | ||||||
| await simple_rate_limit() | ||||||
|
|
||||||
| if not env.ADMIN_API_SECRET or x_admin_secret != env.ADMIN_API_SECRET: | ||||||
| raise HTTPException(status_code=403, detail="Admin access required") | ||||||
|
|
||||||
| try: | ||||||
|
||||||
| with db_context as db: | ||||||
| submission = db.get_submission_by_id(submission_id) | ||||||
| if submission is None: | ||||||
| raise HTTPException(status_code=404, detail="Submission not found") | ||||||
|
|
||||||
| db.delete_submission(submission_id) | ||||||
| return {"message": f"Submission {submission_id} deleted successfully"} | ||||||
|
||||||
| return {"message": f"Submission {submission_id} deleted successfully"} | |
| return {"status": "ok", "submission_id": submission_id} |
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.
The
ADMIN_API_SECRETshould be accessed through theenvmodule following the codebase convention, not directly viaos.environ.get(). Addenv.ADMIN_API_SECRET = os.getenv("ADMIN_API_SECRET", "")tosrc/kernelbot/env.py(similar to line 19 for ADMIN_TOKEN), then useenv.ADMIN_API_SECREThere instead ofADMIN_API_SECRET. This maintains consistency with how other environment variables likeADMIN_TOKENare handled throughout the codebase.