From f15d40f6974c8f9ba70a1722627549b2de8a3871 Mon Sep 17 00:00:00 2001 From: Kevin_Ramirez Date: Mon, 23 Feb 2026 10:54:39 -0600 Subject: [PATCH] Nuevas funcionalidades y correcciones --- .env.example | 4 +- .../api/v1/modules/core/help_center/routes.py | 40 ++++++++++++++----- .../api/v1/modules/core/help_center/tasks.py | 4 ++ backend/main.py | 2 +- .../lib/components/ui/alert-dialog/index.ts | 3 +- .../src/lib/components/ui/dialog/index.ts | 3 +- frontend/src/lib/components/ui/sheet/index.ts | 3 +- .../help-center/editor/[uuid]/+page.svelte | 9 +++++ 8 files changed, 53 insertions(+), 15 deletions(-) diff --git a/.env.example b/.env.example index 80f6478a..aa99fb54 100644 --- a/.env.example +++ b/.env.example @@ -29,10 +29,10 @@ CORE_DB_PASSWORD=postgres # ----- Frontend ----- NODE_ENV=development -VITE_API_URL=http://localhost:8000/api +VITE_API_URL=http://localhost:8001/api INTERNAL_API_URL=http://backend:8000/api VITE_KEYCLOAK_REALM=master -VITE_KEYCLOAK_URL=http://localhost:8080 +VITE_KEYCLOAK_URL=http://localhost:8081 VITE_KEYCLOAK_CLIENT_ID=anexo76-frontend # ----- Sitar API ----- diff --git a/backend/api/v1/modules/core/help_center/routes.py b/backend/api/v1/modules/core/help_center/routes.py index fe7f0b15..19b8cb83 100644 --- a/backend/api/v1/modules/core/help_center/routes.py +++ b/backend/api/v1/modules/core/help_center/routes.py @@ -27,16 +27,31 @@ def trigger_sync_or_broadcast(article_uuid: UUID): - If we are a Client (CENTRAL_SERVER_URL is set): Trigger upstream sync. - If we are the Hub (No CENTRAL_SERVER, but SPOKE_URLS set): Trigger broadcast. """ - # 1. Upstream Sync (Client -> Hub) - if settings.CENTRAL_SERVER_URL: - sync_single_article_task.delay(str(article_uuid)) + import logging + logger = logging.getLogger(__name__) - # 2. Downstream Broadcast (Hub -> Spokes) - # Only if we are the Hub (no upstream) and have spokes configured. - elif not settings.CENTRAL_SERVER_URL and settings.SPOKE_URLS: - from .tasks import broadcast_help_update - # origin_client_uuid is None because this change originated on the Hub itself - broadcast_help_update.delay(str(article_uuid), None) + try: + logger.info(f"DEBUG: Triggering sync/broadcast for article {article_uuid}") + logger.debug(f"DEBUG: CENTRAL_SERVER_URL='{settings.CENTRAL_SERVER_URL}' SPOKE_URLS='{settings.SPOKE_URLS}'") + + # 1. Upstream Sync (Client -> Hub) + if settings.CENTRAL_SERVER_URL and settings.CENTRAL_SERVER_URL != '""': + logger.info(f"DEBUG: Queueing sync_single_article_task for {article_uuid}") + sync_single_article_task.delay(str(article_uuid)) + + # 2. Downstream Broadcast (Hub -> Spokes) + # Only if we are the Hub (no upstream) and have spokes configured. + elif (not settings.CENTRAL_SERVER_URL or settings.CENTRAL_SERVER_URL == '""') and settings.SPOKE_URLS: + from .tasks import broadcast_help_update + logger.info(f"DEBUG: Queueing broadcast_help_update for {article_uuid}") + # origin_client_uuid is None because this change originated on the Hub itself + broadcast_help_update.delay(str(article_uuid), None) + else: + logger.info(f"DEBUG: No sync/broadcast needed for {article_uuid} (Config empty or Hub mode without spokes)") + + except Exception as e: + logger.error(f"ERROR in trigger_sync_or_broadcast for article {article_uuid}: {str(e)}", exc_info=True) + # We don't re-raise here to avoid returning 500 to the user if the save was successful @router.post("/sync/", response_model=HelpSyncResponse, dependencies=[Depends(verify_sync_token)]) def sync_help_article(sync_data: HelpSyncRequest, db: Session = Depends(get_core_db)): @@ -103,8 +118,15 @@ def get_article(article_uuid: UUID, db: Session = Depends(get_core_db)): @router.post("/articles/", response_model=HelpArticleInDB, status_code=status.HTTP_201_CREATED) def create_article(article: HelpArticleCreate, db: Session = Depends(get_core_db)): """Crea un nuevo artículo.""" + import logging + logger = logging.getLogger(__name__) + logger.info(f"DEBUG: Creating new article: {article.title}") + new_article = HelpCenterService.create(db, article) + logger.info(f"DEBUG: Article created successfully in DB. UUID: {new_article.uuid}") + trigger_sync_or_broadcast(new_article.uuid) + return new_article @router.patch("/articles/{article_uuid}/", response_model=HelpArticleInDB) diff --git a/backend/api/v1/modules/core/help_center/tasks.py b/backend/api/v1/modules/core/help_center/tasks.py index fb7cdf77..437b9f47 100644 --- a/backend/api/v1/modules/core/help_center/tasks.py +++ b/backend/api/v1/modules/core/help_center/tasks.py @@ -64,6 +64,8 @@ def broadcast_help_update(article_uuid_str: str, origin_client_uuid_str: str = N client_title=article.title, client_slug=article.slug, last_editor=article.last_editor, + client_category=article.category, + client_order=article.order, origin_client_uuid=UUID(origin_client_uuid_str) if origin_client_uuid_str else None ).model_dump(mode='json') @@ -117,6 +119,8 @@ def sync_single_article(article_uuid): client_title=article.title, client_slug=article.slug, last_editor=article.last_editor, + client_category=article.category, + client_order=article.order, origin_client_uuid=UUID(settings.CLIENT_UUID) if settings.CLIENT_UUID else None ) diff --git a/backend/main.py b/backend/main.py index a27b65fa..b4768c52 100644 --- a/backend/main.py +++ b/backend/main.py @@ -1,7 +1,7 @@ """ Anexo76 - Aplicación SaaS para gestión de comercio exterior Backend API con FastAPI + Keycloak + SQLAlchemy -""" + """ import logging import subprocess diff --git a/frontend/src/lib/components/ui/alert-dialog/index.ts b/frontend/src/lib/components/ui/alert-dialog/index.ts index cc281c58..98ad2f2c 100644 --- a/frontend/src/lib/components/ui/alert-dialog/index.ts +++ b/frontend/src/lib/components/ui/alert-dialog/index.ts @@ -1,4 +1,5 @@ -import { AlertDialog as AlertDialogPrimitive } from "bits-ui"; +import { AlertDialog } from "bits-ui"; +const AlertDialogPrimitive = AlertDialog; import Trigger from "./alert-dialog-trigger.svelte"; import Title from "./alert-dialog-title.svelte"; import Action from "./alert-dialog-action.svelte"; diff --git a/frontend/src/lib/components/ui/dialog/index.ts b/frontend/src/lib/components/ui/dialog/index.ts index dce1d9dc..efc16e73 100644 --- a/frontend/src/lib/components/ui/dialog/index.ts +++ b/frontend/src/lib/components/ui/dialog/index.ts @@ -1,4 +1,5 @@ -import { Dialog as DialogPrimitive } from "bits-ui"; +import { Dialog } from "bits-ui"; +const DialogPrimitive = Dialog; import Title from "./dialog-title.svelte"; import Footer from "./dialog-footer.svelte"; diff --git a/frontend/src/lib/components/ui/sheet/index.ts b/frontend/src/lib/components/ui/sheet/index.ts index 01d40c80..94a584fb 100644 --- a/frontend/src/lib/components/ui/sheet/index.ts +++ b/frontend/src/lib/components/ui/sheet/index.ts @@ -1,4 +1,5 @@ -import { Dialog as SheetPrimitive } from "bits-ui"; +import { Dialog } from "bits-ui"; +const SheetPrimitive = Dialog; import Trigger from "./sheet-trigger.svelte"; import Close from "./sheet-close.svelte"; import Overlay from "./sheet-overlay.svelte"; diff --git a/frontend/src/routes/dashboard/help-center/editor/[uuid]/+page.svelte b/frontend/src/routes/dashboard/help-center/editor/[uuid]/+page.svelte index e8442723..7eeec691 100644 --- a/frontend/src/routes/dashboard/help-center/editor/[uuid]/+page.svelte +++ b/frontend/src/routes/dashboard/help-center/editor/[uuid]/+page.svelte @@ -1,5 +1,6 @@