808ef93a52
- Модель search_operations: title, case_id (unique — операция на карточку),
status (planned/active/paused/completed/archived, CheckConstraint),
unit_id, contour_operation_id (заготовка B20-E4), created_by, closed_at.
- Alembic 009_e3_operations.
- backend/routers/operations.py: POST (создание; unit по умолчанию =
подразделение создателя; скоуп-проверка), GET список (скоуп-фильтр),
GET /{id} (403 вне скоупа), GET /summary (active/total/completed_24h),
PATCH (title/unit/status со статусной машиной: planned→active⇄paused→
completed→archived; недопустимые переходы 400; completed ставит closed_at).
Всё с аудитом operation_create/operation_update.
- Скоуп: unit_id ∈ visible_unit_ids (своё+подчинённые); РЦУ РЧС — все.
- Тесты E3 (12): создание с юнитом/дефолт/дубль кейса/cross-unit 403,
скоуп списков, статусная машина, summary, аудит, cross-scope 403.
222 passed, 5 skipped.
67 lines
2.1 KiB
Python
67 lines
2.1 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from backend.database import init_db
|
|
from backend.routers.admin import router as admin_router
|
|
from backend.routers.admin_users import router as admin_users_router
|
|
from backend.routers.operations import router as operations_router
|
|
from backend.routers.analyze import router as analyze_router
|
|
from backend.routers.auth import router as auth_router
|
|
from backend.routers.cases import router as cases_router
|
|
from backend.routers.closed_cases import router as closed_cases_router
|
|
from backend.routers.geocode import router as geocode_router
|
|
from backend.routers.health import router as health_router
|
|
from backend.routers.stats import router as stats_router
|
|
from backend.routers.water import router as water_router
|
|
|
|
|
|
def _parse_origins(value: str) -> list[str]:
|
|
origins = [origin.strip() for origin in value.split(',') if origin.strip()]
|
|
return origins or ['http://localhost:3000', 'http://127.0.0.1:3000']
|
|
|
|
|
|
cors_origins = _parse_origins(os.getenv('CORS_ORIGINS', 'http://localhost:3000,http://127.0.0.1:3000'))
|
|
allow_credentials = os.getenv('CORS_ALLOW_CREDENTIALS', 'true').strip().lower() in {'1', 'true', 'yes', 'on'}
|
|
if '*' in cors_origins:
|
|
allow_credentials = False
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
init_db()
|
|
yield
|
|
|
|
|
|
app = FastAPI(title='Vector API', version='0.1.0', lifespan=lifespan)
|
|
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=cors_origins,
|
|
allow_credentials=allow_credentials,
|
|
allow_methods=['*'],
|
|
allow_headers=['*'],
|
|
)
|
|
|
|
|
|
app.include_router(health_router)
|
|
app.include_router(auth_router)
|
|
app.include_router(analyze_router)
|
|
app.include_router(cases_router)
|
|
app.include_router(closed_cases_router)
|
|
app.include_router(stats_router)
|
|
app.include_router(admin_router)
|
|
app.include_router(admin_users_router)
|
|
app.include_router(operations_router)
|
|
app.include_router(water_router)
|
|
app.include_router(geocode_router)
|
|
|
|
|
|
@app.get('/')
|
|
def root() -> dict[str, str]:
|
|
return {'name': 'Vector API', 'status': 'ok'}
|