refactor: split calendar source setup orchestration
This commit is contained in:
@@ -99,6 +99,15 @@ from govoplan_core.db.session import get_session
|
||||
router = APIRouter(prefix="/calendar", tags=["calendar"])
|
||||
|
||||
|
||||
def _caldav_discovery_http_error(
|
||||
exc: CalendarError | CalDAVError,
|
||||
) -> HTTPException:
|
||||
return HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
|
||||
detail=str(exc),
|
||||
)
|
||||
|
||||
|
||||
def _require_scope(principal: ApiPrincipal, scope: str) -> None:
|
||||
if not has_scope(principal, scope):
|
||||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=f"Missing scope: {scope}")
|
||||
@@ -492,7 +501,7 @@ def api_discover_caldav_calendars(
|
||||
calendars = discover_caldav_calendars(session, tenant_id=principal.tenant_id, payload=payload)
|
||||
return CalendarCalDavDiscoveryResponse(calendars=calendars)
|
||||
except (CalendarError, CalDAVError) as exc:
|
||||
raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_CONTENT, detail=str(exc)) from exc
|
||||
raise _caldav_discovery_http_error(exc) from exc
|
||||
|
||||
|
||||
@router.post("/caldav/sources", response_model=CalendarCalDavSourceResponse, status_code=status.HTTP_201_CREATED)
|
||||
|
||||
Reference in New Issue
Block a user