Phase 1 (Foundation): - Project restructure (presenton-main → backend/ + frontend/) - Database schema (8 new models, Alembic config, seed script) - Auth (Azure AD SSO + dev bypass, JWT sessions, AuthMiddleware) - RBAC (access_service, rbac_middleware, admin routers) - Audit logging (fire-and-forget, AuditMiddleware, admin router) - i18n (react-i18next with 5 namespace files) Phase 2 (Admin Panel & Client Management): - Admin panel shell (sidebar layout, role guard, 12 pages) - Redux admin slice with 18 async thunks - User management (role changes, deactivation) - Client management (CRUD, brand config, team management) - Brand config editor (colors, fonts, logos, voice rules) - Master deck upload & parser (PPTX → HTML → React pipeline) - Audit log viewer with filters and CSV/JSON export Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
import asyncio
|
|
import aiohttp
|
|
from sqlmodel import select
|
|
from enums.webhook_event import WebhookEvent
|
|
from models.sql.webhook_subscription import WebhookSubscription
|
|
from services.database import get_async_session
|
|
|
|
|
|
class WebhookService:
|
|
|
|
@classmethod
|
|
async def send_webhook(cls, event: WebhookEvent, data: dict):
|
|
async for sql_session in get_async_session():
|
|
webhook_subscriptions = await sql_session.scalars(
|
|
select(WebhookSubscription).where(
|
|
WebhookSubscription.event == event.value
|
|
)
|
|
)
|
|
webhook_subscriptions = list(webhook_subscriptions)
|
|
if not webhook_subscriptions:
|
|
return
|
|
|
|
async_tasks = []
|
|
for webhook_subscription in webhook_subscriptions:
|
|
async_tasks.append(
|
|
cls.send_request_to_webhook(webhook_subscription, data)
|
|
)
|
|
|
|
await asyncio.gather(*async_tasks)
|
|
|
|
break
|
|
|
|
@classmethod
|
|
async def send_request_to_webhook(
|
|
cls, subscription: WebhookSubscription, data: dict
|
|
):
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
}
|
|
if subscription.secret:
|
|
headers["Authorization"] = f"Bearer {subscription.secret}"
|
|
|
|
try:
|
|
async with aiohttp.ClientSession() as session:
|
|
async with session.post(
|
|
subscription.url,
|
|
json=data,
|
|
headers=headers,
|
|
) as _:
|
|
pass
|
|
|
|
except Exception as e:
|
|
print(f"Error sending request to webhook {subscription.id}: {e}")
|
|
pass
|