mirror of
https://github.com/Sea-Haven-Industries/open-swe.git
synced 2026-09-30 17:23:15 +00:00
* feat: gate workflow pushes with approval Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com> * fix: preserve proxy refresh test compatibility Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com> * fix: bind workflow approvals to pushed ref Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com> --------- Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
55 lines
2.2 KiB
Python
55 lines
2.2 KiB
Python
"""REST API for approving workflow-file pushes."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException
|
|
|
|
from .oauth import require_same_origin_for_mutations, require_session
|
|
from .plan_api import _dispatch_followup, _thread_metadata
|
|
from .thread_api import _user_owns_thread
|
|
from .workflow_approval import decide_workflow_push_approval
|
|
|
|
workflow_approval_router = APIRouter(
|
|
prefix="/dashboard/api/workflow-approval",
|
|
tags=["workflow-approval"],
|
|
dependencies=[Depends(require_same_origin_for_mutations)],
|
|
)
|
|
_SESSION_DEP = Depends(require_session)
|
|
|
|
|
|
@workflow_approval_router.post("/{thread_id}/{fingerprint}/approve")
|
|
async def approve_workflow_push(
|
|
thread_id: str, fingerprint: str, session: dict[str, Any] = _SESSION_DEP
|
|
) -> dict[str, Any]:
|
|
metadata = await _thread_metadata(thread_id)
|
|
if not _user_owns_thread(metadata, session["sub"], session.get("email")):
|
|
raise HTTPException(403, "only the thread owner can approve workflow pushes")
|
|
record = await decide_workflow_push_approval(
|
|
thread_id, fingerprint, approved=True, actor=session["sub"]
|
|
)
|
|
if record is None:
|
|
raise HTTPException(404, "workflow push approval not found")
|
|
await _dispatch_followup(
|
|
thread_id,
|
|
metadata,
|
|
"The workflow-file push approval was approved. Retry the blocked git push now; do not alter workflow files before pushing.",
|
|
plan_mode=False,
|
|
)
|
|
return {"status": "approved", "fingerprint": fingerprint}
|
|
|
|
|
|
@workflow_approval_router.post("/{thread_id}/{fingerprint}/reject")
|
|
async def reject_workflow_push(
|
|
thread_id: str, fingerprint: str, session: dict[str, Any] = _SESSION_DEP
|
|
) -> dict[str, Any]:
|
|
metadata = await _thread_metadata(thread_id)
|
|
if not _user_owns_thread(metadata, session["sub"], session.get("email")):
|
|
raise HTTPException(403, "only the thread owner can reject workflow pushes")
|
|
record = await decide_workflow_push_approval(
|
|
thread_id, fingerprint, approved=False, actor=session["sub"]
|
|
)
|
|
if record is None:
|
|
raise HTTPException(404, "workflow push approval not found")
|
|
return {"status": "rejected", "fingerprint": fingerprint}
|