feat(api): add authentication to all endpoints and update OpenAPI schema

This commit is contained in:
Fanilo-Nantenaina 2026-01-20 11:49:57 +03:00
parent e0f08fd83a
commit 9bd0f62459

127
api.py
View file

@ -175,6 +175,28 @@ app = FastAPI(
) """ ) """
def custom_openapi():
if app.openapi_schema:
return app.openapi_schema
openapi_schema = app.openapi()
# Définir deux schémas de sécurité
openapi_schema["components"]["securitySchemes"] = {
"HTTPBearer": {"type": "http", "scheme": "bearer", "bearerFormat": "JWT"},
"ApiKeyAuth": {"type": "apiKey", "in": "header", "name": "X-API-Key"},
}
openapi_schema["security"] = [{"HTTPBearer": []}, {"ApiKeyAuth": []}]
app.openapi_schema = openapi_schema
return app.openapi_schema
# Après app = FastAPI(...), ajouter:
app.openapi = custom_openapi
setup_cors(app, mode="open") setup_cors(app, mode="open")
app.add_middleware(SwaggerAuthMiddleware) app.add_middleware(SwaggerAuthMiddleware)
app.add_middleware(ApiKeyMiddleware) app.add_middleware(ApiKeyMiddleware)
@ -189,6 +211,7 @@ app.include_router(entreprises_router)
@app.get("/clients", response_model=List[ClientDetails], tags=["Clients"]) @app.get("/clients", response_model=List[ClientDetails], tags=["Clients"])
async def obtenir_clients( async def obtenir_clients(
query: Optional[str] = Query(None), query: Optional[str] = Query(None),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -202,6 +225,7 @@ async def obtenir_clients(
@app.get("/clients/{code}", response_model=ClientDetails, tags=["Clients"]) @app.get("/clients/{code}", response_model=ClientDetails, tags=["Clients"])
async def lire_client_detail( async def lire_client_detail(
code: str, code: str,
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -224,6 +248,7 @@ async def modifier_client(
code: str, code: str,
client_update: ClientUpdate, client_update: ClientUpdate,
session: AsyncSession = Depends(get_session), session: AsyncSession = Depends(get_session),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -249,6 +274,7 @@ async def modifier_client(
async def ajouter_client( async def ajouter_client(
client: ClientCreate, client: ClientCreate,
session: AsyncSession = Depends(get_session), session: AsyncSession = Depends(get_session),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -273,6 +299,7 @@ async def ajouter_client(
@app.get("/articles", response_model=List[Article], tags=["Articles"]) @app.get("/articles", response_model=List[Article], tags=["Articles"])
async def rechercher_articles( async def rechercher_articles(
query: Optional[str] = Query(None), query: Optional[str] = Query(None),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -291,6 +318,7 @@ async def rechercher_articles(
) )
async def creer_article( async def creer_article(
article: ArticleCreate, article: ArticleCreate,
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -331,6 +359,7 @@ async def creer_article(
async def modifier_article( async def modifier_article(
reference: str = Path(..., description="Référence de l'article à modifier"), reference: str = Path(..., description="Référence de l'article à modifier"),
article: ArticleUpdate = Body(...), article: ArticleUpdate = Body(...),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -374,6 +403,7 @@ async def modifier_article(
@app.get("/articles/{reference}", response_model=Article, tags=["Articles"]) @app.get("/articles/{reference}", response_model=Article, tags=["Articles"])
async def lire_article( async def lire_article(
reference: str = Path(..., description="Référence de l'article"), reference: str = Path(..., description="Référence de l'article"),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -403,6 +433,7 @@ async def lire_article(
@app.post("/devis", response_model=Devis, status_code=201, tags=["Devis"]) @app.post("/devis", response_model=Devis, status_code=201, tags=["Devis"])
async def creer_devis( async def creer_devis(
devis: DevisRequest, devis: DevisRequest,
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -442,6 +473,7 @@ async def modifier_devis(
id: str, id: str,
devis_update: DevisUpdate, devis_update: DevisUpdate,
session: AsyncSession = Depends(get_session), session: AsyncSession = Depends(get_session),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -487,6 +519,7 @@ async def modifier_devis(
async def creer_commande( async def creer_commande(
commande: CommandeCreate, commande: CommandeCreate,
session: AsyncSession = Depends(get_session), session: AsyncSession = Depends(get_session),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -536,6 +569,7 @@ async def modifier_commande(
id: str, id: str,
commande_update: CommandeUpdate, commande_update: CommandeUpdate,
session: AsyncSession = Depends(get_session), session: AsyncSession = Depends(get_session),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -584,6 +618,7 @@ async def lister_devis(
inclure_lignes: bool = Query( inclure_lignes: bool = Query(
True, description="Inclure les lignes de chaque devis" True, description="Inclure les lignes de chaque devis"
), ),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -600,6 +635,7 @@ async def lister_devis(
@app.get("/devis/{id}", tags=["Devis"]) @app.get("/devis/{id}", tags=["Devis"])
async def lire_devis( async def lire_devis(
id: str, id: str,
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -620,6 +656,7 @@ async def lire_devis(
@app.get("/devis/{id}/pdf", tags=["Devis"]) @app.get("/devis/{id}/pdf", tags=["Devis"])
async def telecharger_devis_pdf( async def telecharger_devis_pdf(
id: str, id: str,
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -642,6 +679,7 @@ async def telecharger_document_pdf(
description="Type de document (0=Devis, 10=Commande, 30=Livraison, 60=Facture, 50=Avoir)", description="Type de document (0=Devis, 10=Commande, 30=Livraison, 60=Facture, 50=Avoir)",
), ),
numero: str = Path(..., description="Numéro du document"), numero: str = Path(..., description="Numéro du document"),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -698,6 +736,7 @@ async def envoyer_devis_email(
id: str, id: str,
request: EmailEnvoi, request: EmailEnvoi,
session: AsyncSession = Depends(get_session), session: AsyncSession = Depends(get_session),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -753,6 +792,7 @@ async def changer_statut_document(
nouveau_statut: int = Query( nouveau_statut: int = Query(
..., ge=0, le=6, description="0=Saisi, 1=Confirmé, 2=Accepté" ..., ge=0, le=6, description="0=Saisi, 1=Confirmé, 2=Accepté"
), ),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
document_type_sql = None document_type_sql = None
@ -869,6 +909,7 @@ async def changer_statut_document(
@app.get("/commandes/{id}", tags=["Commandes"]) @app.get("/commandes/{id}", tags=["Commandes"])
async def lire_commande( async def lire_commande(
id: str, id: str,
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -887,6 +928,7 @@ async def lire_commande(
async def lister_commandes( async def lister_commandes(
limit: int = Query(100, le=1000), limit: int = Query(100, le=1000),
statut: Optional[int] = Query(None), statut: Optional[int] = Query(None),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -902,6 +944,7 @@ async def lister_commandes(
async def devis_vers_commande( async def devis_vers_commande(
id: str, id: str,
session: AsyncSession = Depends(get_session), session: AsyncSession = Depends(get_session),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -946,6 +989,7 @@ async def devis_vers_commande(
async def commande_vers_facture( async def commande_vers_facture(
id: str, id: str,
session: AsyncSession = Depends(get_session), session: AsyncSession = Depends(get_session),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -1047,6 +1091,7 @@ async def envoyer_emails_lot(
async def valider_remise( async def valider_remise(
client_id: str = Query(..., min_length=1), client_id: str = Query(..., min_length=1),
remise_pourcentage: float = Query(0.0, ge=0, le=100), remise_pourcentage: float = Query(0.0, ge=0, le=100),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -1080,6 +1125,7 @@ async def relancer_devis_signature(
id: str, id: str,
relance: RelanceDevis, relance: RelanceDevis,
session: AsyncSession = Depends(get_session), session: AsyncSession = Depends(get_session),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -1146,6 +1192,7 @@ class ContactClientResponse(BaseModel):
@app.get("/devis/{id}/contact", response_model=ContactClientResponse, tags=["Devis"]) @app.get("/devis/{id}/contact", response_model=ContactClientResponse, tags=["Devis"])
async def recuperer_contact_devis( async def recuperer_contact_devis(
id: str, id: str,
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -1173,6 +1220,7 @@ async def recuperer_contact_devis(
async def lister_factures( async def lister_factures(
limit: int = Query(100, le=1000), limit: int = Query(100, le=1000),
statut: Optional[int] = Query(None), statut: Optional[int] = Query(None),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -1187,6 +1235,7 @@ async def lister_factures(
@app.get("/factures/{numero}", tags=["Factures"]) @app.get("/factures/{numero}", tags=["Factures"])
async def lire_facture_detail( async def lire_facture_detail(
numero: str, numero: str,
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -1213,6 +1262,7 @@ class RelanceFacture(BaseModel):
async def creer_facture( async def creer_facture(
facture: FactureCreate, facture: FactureCreate,
session: AsyncSession = Depends(get_session), session: AsyncSession = Depends(get_session),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -1262,6 +1312,7 @@ async def modifier_facture(
id: str, id: str,
facture_update: FactureUpdate, facture_update: FactureUpdate,
session: AsyncSession = Depends(get_session), session: AsyncSession = Depends(get_session),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -1331,6 +1382,7 @@ async def relancer_facture(
id: str, id: str,
relance: RelanceFacture, relance: RelanceFacture,
session: AsyncSession = Depends(get_session), session: AsyncSession = Depends(get_session),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -1401,6 +1453,7 @@ async def journal_emails(
destinataire: Optional[str] = Query(None), destinataire: Optional[str] = Query(None),
limit: int = Query(100, le=1000), limit: int = Query(100, le=1000),
session: AsyncSession = Depends(get_session), session: AsyncSession = Depends(get_session),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
query = select(EmailLog) query = select(EmailLog)
@ -1436,6 +1489,7 @@ async def journal_emails(
async def exporter_logs_csv( async def exporter_logs_csv(
statut: Optional[StatutEmail] = Query(None), statut: Optional[StatutEmail] = Query(None),
session: AsyncSession = Depends(get_session), session: AsyncSession = Depends(get_session),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
query = select(EmailLog) query = select(EmailLog)
@ -1592,6 +1646,7 @@ async def supprimer_template(
@app.post("/templates/emails/preview", tags=["Emails"]) @app.post("/templates/emails/preview", tags=["Emails"])
async def previsualiser_email( async def previsualiser_email(
preview: TemplatePreview, preview: TemplatePreview,
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
if preview.template_id not in templates_email_db: if preview.template_id not in templates_email_db:
@ -1630,6 +1685,7 @@ async def previsualiser_email(
@app.get("/prospects", tags=["Prospects"]) @app.get("/prospects", tags=["Prospects"])
async def rechercher_prospects( async def rechercher_prospects(
query: Optional[str] = Query(None), query: Optional[str] = Query(None),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -1643,6 +1699,7 @@ async def rechercher_prospects(
@app.get("/prospects/{code}", tags=["Prospects"]) @app.get("/prospects/{code}", tags=["Prospects"])
async def lire_prospect( async def lire_prospect(
code: str, code: str,
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -1662,6 +1719,7 @@ async def lire_prospect(
) )
async def rechercher_fournisseurs( async def rechercher_fournisseurs(
query: Optional[str] = Query(None), query: Optional[str] = Query(None),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -1683,6 +1741,7 @@ async def rechercher_fournisseurs(
async def ajouter_fournisseur( async def ajouter_fournisseur(
fournisseur: FournisseurCreate, fournisseur: FournisseurCreate,
session: AsyncSession = Depends(get_session), session: AsyncSession = Depends(get_session),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -1712,6 +1771,7 @@ async def modifier_fournisseur(
code: str, code: str,
fournisseur_update: FournisseurUpdate, fournisseur_update: FournisseurUpdate,
session: AsyncSession = Depends(get_session), session: AsyncSession = Depends(get_session),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -1734,6 +1794,7 @@ async def modifier_fournisseur(
@app.get("/fournisseurs/{code}", tags=["Fournisseurs"]) @app.get("/fournisseurs/{code}", tags=["Fournisseurs"])
async def lire_fournisseur( async def lire_fournisseur(
code: str, code: str,
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -1752,6 +1813,7 @@ async def lire_fournisseur(
async def lister_avoirs( async def lister_avoirs(
limit: int = Query(100, le=1000), limit: int = Query(100, le=1000),
statut: Optional[int] = Query(None), statut: Optional[int] = Query(None),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -1765,6 +1827,7 @@ async def lister_avoirs(
@app.get("/avoirs/{numero}", tags=["Avoirs"]) @app.get("/avoirs/{numero}", tags=["Avoirs"])
async def lire_avoir( async def lire_avoir(
numero: str, numero: str,
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -1783,6 +1846,7 @@ async def lire_avoir(
async def creer_avoir( async def creer_avoir(
avoir: AvoirCreate, avoir: AvoirCreate,
session: AsyncSession = Depends(get_session), session: AsyncSession = Depends(get_session),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -1830,6 +1894,7 @@ async def modifier_avoir(
id: str, id: str,
avoir_update: AvoirUpdate, avoir_update: AvoirUpdate,
session: AsyncSession = Depends(get_session), session: AsyncSession = Depends(get_session),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -1875,6 +1940,7 @@ async def modifier_avoir(
async def lister_livraisons( async def lister_livraisons(
limit: int = Query(100, le=1000), limit: int = Query(100, le=1000),
statut: Optional[int] = Query(None), statut: Optional[int] = Query(None),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -1888,6 +1954,7 @@ async def lister_livraisons(
@app.get("/livraisons/{numero}", tags=["Livraisons"]) @app.get("/livraisons/{numero}", tags=["Livraisons"])
async def lire_livraison( async def lire_livraison(
numero: str, numero: str,
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -1906,6 +1973,7 @@ async def lire_livraison(
async def creer_livraison( async def creer_livraison(
livraison: LivraisonCreate, livraison: LivraisonCreate,
session: AsyncSession = Depends(get_session), session: AsyncSession = Depends(get_session),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -1959,6 +2027,7 @@ async def modifier_livraison(
id: str, id: str,
livraison_update: LivraisonUpdate, livraison_update: LivraisonUpdate,
session: AsyncSession = Depends(get_session), session: AsyncSession = Depends(get_session),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -2004,6 +2073,7 @@ async def modifier_livraison(
async def livraison_vers_facture( async def livraison_vers_facture(
id: str, id: str,
session: AsyncSession = Depends(get_session), session: AsyncSession = Depends(get_session),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -2047,6 +2117,7 @@ async def livraison_vers_facture(
async def devis_vers_facture_direct( async def devis_vers_facture_direct(
id: str, id: str,
session: AsyncSession = Depends(get_session), session: AsyncSession = Depends(get_session),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -2107,6 +2178,7 @@ async def devis_vers_facture_direct(
async def commande_vers_livraison( async def commande_vers_livraison(
id: str, id: str,
session: AsyncSession = Depends(get_session), session: AsyncSession = Depends(get_session),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -2178,6 +2250,7 @@ async def commande_vers_livraison(
) )
async def lister_familles( async def lister_familles(
filtre: Optional[str] = Query(None, description="Filtre sur code ou intitulé"), filtre: Optional[str] = Query(None, description="Filtre sur code ou intitulé"),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -2203,6 +2276,7 @@ async def lister_familles(
) )
async def lire_famille( async def lire_famille(
code: str = Path(..., description="Code de la famille (ex: ZDIVERS)"), code: str = Path(..., description="Code de la famille (ex: ZDIVERS)"),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -2238,6 +2312,7 @@ async def lire_famille(
) )
async def creer_famille( async def creer_famille(
famille: FamilleCreate, famille: FamilleCreate,
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -2281,6 +2356,7 @@ async def creer_famille(
) )
async def creer_entree_stock( async def creer_entree_stock(
entree: EntreeStock, entree: EntreeStock,
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -2317,6 +2393,7 @@ async def creer_entree_stock(
) )
async def creer_sortie_stock( async def creer_sortie_stock(
sortie: SortieStock, sortie: SortieStock,
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -2352,6 +2429,7 @@ async def creer_sortie_stock(
) )
async def lire_mouvement_stock( async def lire_mouvement_stock(
numero: str = Path(..., description="Numéro du mouvement (ex: ME00123 ou MS00124)"), numero: str = Path(..., description="Numéro du mouvement (ex: ME00123 ou MS00124)"),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -2384,6 +2462,7 @@ async def lire_mouvement_stock(
summary="Statistiques sur les familles", summary="Statistiques sur les familles",
) )
async def statistiques_familles( async def statistiques_familles(
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -2492,6 +2571,7 @@ async def statistiques_utilisateurs(session: AsyncSession = Depends(get_session)
async def creer_contact( async def creer_contact(
numero: str, numero: str,
contact: ContactCreate, contact: ContactCreate,
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -2524,6 +2604,7 @@ async def creer_contact(
@app.get("/tiers/{numero}/contacts", response_model=List[Contact], tags=["Contacts"]) @app.get("/tiers/{numero}/contacts", response_model=List[Contact], tags=["Contacts"])
async def lister_contacts( async def lister_contacts(
numero: str, numero: str,
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -2542,6 +2623,7 @@ async def lister_contacts(
async def obtenir_contact( async def obtenir_contact(
numero: str, numero: str,
contact_numero: int, contact_numero: int,
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -2567,6 +2649,7 @@ async def modifier_contact(
numero: str, numero: str,
contact_numero: int, contact_numero: int,
contact: ContactUpdate, contact: ContactUpdate,
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -2598,6 +2681,7 @@ async def modifier_contact(
async def supprimer_contact( async def supprimer_contact(
numero: str, numero: str,
contact_numero: int, contact_numero: int,
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -2612,6 +2696,7 @@ async def supprimer_contact(
async def definir_contact_defaut( async def definir_contact_defaut(
numero: str, numero: str,
contact_numero: int, contact_numero: int,
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -2633,6 +2718,7 @@ async def obtenir_tiers(
description="Filtre par type: 0/client, 1/fournisseur, 2/prospect, 3/all ou strings", description="Filtre par type: 0/client, 1/fournisseur, 2/prospect, 3/all ou strings",
), ),
query: Optional[str] = Query(None, description="Recherche sur code ou intitulé"), query: Optional[str] = Query(None, description="Recherche sur code ou intitulé"),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -2647,6 +2733,7 @@ async def obtenir_tiers(
@app.get("/tiers/{code}", response_model=TiersDetails, tags=["Tiers"]) @app.get("/tiers/{code}", response_model=TiersDetails, tags=["Tiers"])
async def lire_tiers_detail( async def lire_tiers_detail(
code: str, code: str,
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -2684,6 +2771,7 @@ async def lister_collaborateurs(
actifs_seulement: bool = Query( actifs_seulement: bool = Query(
True, description="Exclure les collaborateurs en sommeil" True, description="Exclure les collaborateurs en sommeil"
), ),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
"""Liste tous les collaborateurs""" """Liste tous les collaborateurs"""
@ -2702,6 +2790,7 @@ async def lister_collaborateurs(
) )
async def lire_collaborateur_detail( async def lire_collaborateur_detail(
numero: int, numero: int,
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
"""Lit un collaborateur par son numéro""" """Lit un collaborateur par son numéro"""
@ -2728,6 +2817,7 @@ async def lire_collaborateur_detail(
) )
async def creer_collaborateur( async def creer_collaborateur(
collaborateur: CollaborateurCreate, collaborateur: CollaborateurCreate,
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
"""Crée un nouveau collaborateur""" """Crée un nouveau collaborateur"""
@ -2754,6 +2844,7 @@ async def creer_collaborateur(
async def modifier_collaborateur( async def modifier_collaborateur(
numero: int, numero: int,
collaborateur: CollaborateurUpdate, collaborateur: CollaborateurUpdate,
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
"""Modifie un collaborateur existant""" """Modifie un collaborateur existant"""
@ -2776,6 +2867,7 @@ async def modifier_collaborateur(
@app.get("/societe/info", response_model=SocieteInfo, tags=["Société"]) @app.get("/societe/info", response_model=SocieteInfo, tags=["Société"])
async def obtenir_informations_societe( async def obtenir_informations_societe(
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -2795,6 +2887,7 @@ async def obtenir_informations_societe(
@app.get("/societe/logo", tags=["Société"]) @app.get("/societe/logo", tags=["Société"])
async def obtenir_logo_societe( async def obtenir_logo_societe(
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
"""Retourne le logo en tant qu'image directe""" """Retourne le logo en tant qu'image directe"""
@ -2819,6 +2912,7 @@ async def obtenir_logo_societe(
@app.get("/societe/preview", response_class=HTMLResponse, tags=["Société"]) @app.get("/societe/preview", response_class=HTMLResponse, tags=["Société"])
async def preview_societe( async def preview_societe(
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
"""Page HTML pour visualiser les infos société avec logo""" """Page HTML pour visualiser les infos société avec logo"""
@ -2892,6 +2986,7 @@ async def preview_societe(
async def valider_facture( async def valider_facture(
numero_facture: str, numero_facture: str,
_: AsyncSession = Depends(get_session), _: AsyncSession = Depends(get_session),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -2915,6 +3010,7 @@ async def valider_facture(
async def devalider_facture( async def devalider_facture(
numero_facture: str, numero_facture: str,
_: AsyncSession = Depends(get_session), _: AsyncSession = Depends(get_session),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -2938,6 +3034,7 @@ async def devalider_facture(
async def get_statut_validation_facture( async def get_statut_validation_facture(
numero_facture: str, numero_facture: str,
_: AsyncSession = Depends(get_session), _: AsyncSession = Depends(get_session),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -2958,6 +3055,7 @@ async def regler_facture(
numero_facture: str, numero_facture: str,
reglement: ReglementFactureCreate, reglement: ReglementFactureCreate,
session: AsyncSession = Depends(get_session), session: AsyncSession = Depends(get_session),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -3001,6 +3099,7 @@ async def regler_facture(
async def regler_factures_multiple( async def regler_factures_multiple(
reglement: ReglementMultipleCreate, reglement: ReglementMultipleCreate,
session: AsyncSession = Depends(get_session), session: AsyncSession = Depends(get_session),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -3039,6 +3138,7 @@ async def regler_factures_multiple(
async def get_reglements_facture( async def get_reglements_facture(
numero_facture: str, numero_facture: str,
session: AsyncSession = Depends(get_session), session: AsyncSession = Depends(get_session),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -3063,6 +3163,7 @@ async def get_reglements_client(
date_fin: Optional[datetime] = Query(None, description="Date fin"), date_fin: Optional[datetime] = Query(None, description="Date fin"),
inclure_soldees: bool = Query(True, description="Inclure les factures soldées"), inclure_soldees: bool = Query(True, description="Inclure les factures soldées"),
session: AsyncSession = Depends(get_session), session: AsyncSession = Depends(get_session),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -3087,6 +3188,7 @@ async def get_reglements_client(
@app.get("/journaux/banque", tags=["Règlements"]) @app.get("/journaux/banque", tags=["Règlements"])
async def get_journaux_banque( async def get_journaux_banque(
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
try: try:
@ -3099,6 +3201,7 @@ async def get_journaux_banque(
@app.get("/reglements/modes", tags=["Référentiels"]) @app.get("/reglements/modes", tags=["Référentiels"])
async def get_modes_reglement( async def get_modes_reglement(
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
"""Liste des modes de règlement disponibles dans Sage""" """Liste des modes de règlement disponibles dans Sage"""
@ -3112,6 +3215,7 @@ async def get_modes_reglement(
@app.get("/devises", tags=["Référentiels"]) @app.get("/devises", tags=["Référentiels"])
async def get_devises( async def get_devises(
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
"""Liste des devises disponibles dans Sage""" """Liste des devises disponibles dans Sage"""
@ -3125,6 +3229,7 @@ async def get_devises(
@app.get("/journaux/tresorerie", tags=["Référentiels"]) @app.get("/journaux/tresorerie", tags=["Référentiels"])
async def get_journaux_tresorerie( async def get_journaux_tresorerie(
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
"""Liste des journaux de trésorerie (banque + caisse)""" """Liste des journaux de trésorerie (banque + caisse)"""
@ -3143,6 +3248,7 @@ async def get_comptes_generaux(
None, None,
description="client | fournisseur | banque | caisse | tva | produit | charge", description="client | fournisseur | banque | caisse | tva | produit | charge",
), ),
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
"""Liste des comptes généraux""" """Liste des comptes généraux"""
@ -3156,6 +3262,7 @@ async def get_comptes_generaux(
@app.get("/tva/taux", tags=["Référentiels"]) @app.get("/tva/taux", tags=["Référentiels"])
async def get_tva_taux( async def get_tva_taux(
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
"""Liste des taux de TVA""" """Liste des taux de TVA"""
@ -3169,6 +3276,7 @@ async def get_tva_taux(
@app.get("/parametres/encaissement", tags=["Référentiels"]) @app.get("/parametres/encaissement", tags=["Référentiels"])
async def get_parametres_encaissement( async def get_parametres_encaissement(
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
"""Paramètres TVA sur encaissement""" """Paramètres TVA sur encaissement"""
@ -3215,6 +3323,7 @@ async def get_reglement_detail(rg_no):
@app.get("/health", tags=["System"]) @app.get("/health", tags=["System"])
async def health_check( async def health_check(
user: User = Depends(get_current_user),
sage: SageGatewayClient = Depends(get_sage_client_for_user), sage: SageGatewayClient = Depends(get_sage_client_for_user),
): ):
gateway_health = sage.health() gateway_health = sage.health()
@ -3236,9 +3345,23 @@ async def health_check(
async def root(): async def root():
return { return {
"api": "Sage 100c Dataven - VPS Linux", "api": "Sage 100c Dataven - VPS Linux",
"version": "2.0.0", "version": "3.0.0",
"documentation": "/docs", "documentation": "/docs (authentification requise)",
"health": "/health", "health": "/health",
"authentication": {
"methods": [
{
"type": "JWT",
"header": "Authorization: Bearer <token>",
"endpoint": "/api/auth/login",
},
{
"type": "API Key",
"header": "X-API-Key: sdk_live_xxx",
"endpoint": "/api/api-keys",
},
]
},
} }