Spaces:
Sleeping
Sleeping
axeronis commited on
Commit ·
ba1fcd9
1
Parent(s): 880042a
feat: admin-editable trust logos via site settings API
Browse files- backend/app/api/site_settings.py +147 -0
- backend/app/main.py +2 -1
- backend/app/models/__init__.py +5 -0
- backend/app/models/system.py +14 -0
- frontend/app/page.tsx +24 -3
backend/app/api/site_settings.py
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Site Settings API - Manage global site configuration like trust logos.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
from fastapi import APIRouter, Depends, HTTPException
|
| 6 |
+
from sqlmodel import Session, select
|
| 7 |
+
from typing import Optional, List
|
| 8 |
+
from pydantic import BaseModel
|
| 9 |
+
from datetime import datetime
|
| 10 |
+
import json
|
| 11 |
+
|
| 12 |
+
from app.core.database import get_session
|
| 13 |
+
from app.core.security import get_current_admin
|
| 14 |
+
from app.models import SiteSettings
|
| 15 |
+
|
| 16 |
+
router = APIRouter(prefix="/site-settings", tags=["site-settings"])
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class SettingUpdate(BaseModel):
|
| 20 |
+
value: str # JSON string or simple string
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
class SettingResponse(BaseModel):
|
| 24 |
+
key: str
|
| 25 |
+
value: str
|
| 26 |
+
updated_at: datetime
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
class TrustLogosUpdate(BaseModel):
|
| 30 |
+
logos: List[str]
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
# Public endpoint - no auth required
|
| 34 |
+
@router.get("/public/{key}")
|
| 35 |
+
async def get_public_setting(
|
| 36 |
+
key: str,
|
| 37 |
+
session: Session = Depends(get_session)
|
| 38 |
+
):
|
| 39 |
+
"""Get a public site setting by key (no auth required)."""
|
| 40 |
+
# Only allow certain keys to be public
|
| 41 |
+
allowed_public_keys = ["trust_logos"]
|
| 42 |
+
|
| 43 |
+
if key not in allowed_public_keys:
|
| 44 |
+
raise HTTPException(status_code=404, detail="Setting not found")
|
| 45 |
+
|
| 46 |
+
setting = session.exec(
|
| 47 |
+
select(SiteSettings).where(SiteSettings.key == key)
|
| 48 |
+
).first()
|
| 49 |
+
|
| 50 |
+
if not setting:
|
| 51 |
+
# Return default values
|
| 52 |
+
if key == "trust_logos":
|
| 53 |
+
return {"value": json.dumps([
|
| 54 |
+
"TechCorp", "StartupHub", "GrowthLab", "SalesForce", "Microsoft",
|
| 55 |
+
"HubSpot", "Intercom", "Zendesk", "Pipedrive", "Zoho"
|
| 56 |
+
])}
|
| 57 |
+
return {"value": ""}
|
| 58 |
+
|
| 59 |
+
return {"value": setting.value}
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
@router.get("/", response_model=List[SettingResponse])
|
| 63 |
+
async def list_settings(
|
| 64 |
+
session: Session = Depends(get_session),
|
| 65 |
+
_admin = Depends(get_current_admin)
|
| 66 |
+
):
|
| 67 |
+
"""List all site settings (admin only)."""
|
| 68 |
+
settings = session.exec(select(SiteSettings)).all()
|
| 69 |
+
return [SettingResponse(key=s.key, value=s.value, updated_at=s.updated_at) for s in settings]
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
@router.get("/{key}", response_model=SettingResponse)
|
| 73 |
+
async def get_setting(
|
| 74 |
+
key: str,
|
| 75 |
+
session: Session = Depends(get_session),
|
| 76 |
+
_admin = Depends(get_current_admin)
|
| 77 |
+
):
|
| 78 |
+
"""Get a site setting by key (admin only)."""
|
| 79 |
+
setting = session.exec(
|
| 80 |
+
select(SiteSettings).where(SiteSettings.key == key)
|
| 81 |
+
).first()
|
| 82 |
+
|
| 83 |
+
if not setting:
|
| 84 |
+
raise HTTPException(status_code=404, detail="Setting not found")
|
| 85 |
+
|
| 86 |
+
return SettingResponse(key=setting.key, value=setting.value, updated_at=setting.updated_at)
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
@router.put("/{key}", response_model=SettingResponse)
|
| 90 |
+
async def update_setting(
|
| 91 |
+
key: str,
|
| 92 |
+
data: SettingUpdate,
|
| 93 |
+
session: Session = Depends(get_session),
|
| 94 |
+
admin = Depends(get_current_admin)
|
| 95 |
+
):
|
| 96 |
+
"""Update or create a site setting (admin only)."""
|
| 97 |
+
setting = session.exec(
|
| 98 |
+
select(SiteSettings).where(SiteSettings.key == key)
|
| 99 |
+
).first()
|
| 100 |
+
|
| 101 |
+
if setting:
|
| 102 |
+
setting.value = data.value
|
| 103 |
+
setting.updated_at = datetime.utcnow()
|
| 104 |
+
setting.updated_by = admin.id
|
| 105 |
+
else:
|
| 106 |
+
setting = SiteSettings(
|
| 107 |
+
key=key,
|
| 108 |
+
value=data.value,
|
| 109 |
+
updated_by=admin.id
|
| 110 |
+
)
|
| 111 |
+
session.add(setting)
|
| 112 |
+
|
| 113 |
+
session.commit()
|
| 114 |
+
session.refresh(setting)
|
| 115 |
+
|
| 116 |
+
return SettingResponse(key=setting.key, value=setting.value, updated_at=setting.updated_at)
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
@router.put("/trust-logos/update")
|
| 120 |
+
async def update_trust_logos(
|
| 121 |
+
data: TrustLogosUpdate,
|
| 122 |
+
session: Session = Depends(get_session),
|
| 123 |
+
admin = Depends(get_current_admin)
|
| 124 |
+
):
|
| 125 |
+
"""Convenience endpoint to update trust logos list (admin only)."""
|
| 126 |
+
setting = session.exec(
|
| 127 |
+
select(SiteSettings).where(SiteSettings.key == "trust_logos")
|
| 128 |
+
).first()
|
| 129 |
+
|
| 130 |
+
value = json.dumps(data.logos)
|
| 131 |
+
|
| 132 |
+
if setting:
|
| 133 |
+
setting.value = value
|
| 134 |
+
setting.updated_at = datetime.utcnow()
|
| 135 |
+
setting.updated_by = admin.id
|
| 136 |
+
else:
|
| 137 |
+
setting = SiteSettings(
|
| 138 |
+
key="trust_logos",
|
| 139 |
+
value=value,
|
| 140 |
+
updated_by=admin.id
|
| 141 |
+
)
|
| 142 |
+
session.add(setting)
|
| 143 |
+
|
| 144 |
+
session.commit()
|
| 145 |
+
session.refresh(setting)
|
| 146 |
+
|
| 147 |
+
return {"success": True, "logos": data.logos}
|
backend/app/main.py
CHANGED
|
@@ -7,7 +7,7 @@ from app.core.config import settings
|
|
| 7 |
from app.core.database import init_pgvector
|
| 8 |
from app.core.logging import configure_logging, get_logger
|
| 9 |
from app.middleware.request_id import RequestIDMiddleware
|
| 10 |
-
from app.api import webhook, leads, knowledge, channels, auth, tenants, analytics, chats, playbook, billing, ai_training, crm, admin, team, telegram_webhook, partners, notifications, products, bookings, jobs, system, meta_webhooks, voice, google_calendar, websocket_voice, oauth, landing
|
| 11 |
|
| 12 |
# ... (omitted lines)
|
| 13 |
|
|
@@ -194,6 +194,7 @@ app.include_router(voice.router, prefix="/api/v1/voice", tags=["Voice"])
|
|
| 194 |
app.include_router(websocket_voice.router, prefix="/ws/voice", tags=["Voice Stream"])
|
| 195 |
app.include_router(google_calendar.router, prefix="/api/v1/google-calendar", tags=["Google Calendar"])
|
| 196 |
app.include_router(landing.router, prefix="/api/v1/landing", tags=["Landing Page"])
|
|
|
|
| 197 |
|
| 198 |
|
| 199 |
@app.on_event("startup")
|
|
|
|
| 7 |
from app.core.database import init_pgvector
|
| 8 |
from app.core.logging import configure_logging, get_logger
|
| 9 |
from app.middleware.request_id import RequestIDMiddleware
|
| 10 |
+
from app.api import webhook, leads, knowledge, channels, auth, tenants, analytics, chats, playbook, billing, ai_training, crm, admin, team, telegram_webhook, partners, notifications, products, bookings, jobs, system, meta_webhooks, voice, google_calendar, websocket_voice, oauth, landing, site_settings
|
| 11 |
|
| 12 |
# ... (omitted lines)
|
| 13 |
|
|
|
|
| 194 |
app.include_router(websocket_voice.router, prefix="/ws/voice", tags=["Voice Stream"])
|
| 195 |
app.include_router(google_calendar.router, prefix="/api/v1/google-calendar", tags=["Google Calendar"])
|
| 196 |
app.include_router(landing.router, prefix="/api/v1/landing", tags=["Landing Page"])
|
| 197 |
+
app.include_router(site_settings.router, prefix="/api/v1", tags=["Site Settings"])
|
| 198 |
|
| 199 |
|
| 200 |
@app.on_event("startup")
|
backend/app/models/__init__.py
CHANGED
|
@@ -19,6 +19,7 @@ from app.models.ai_training import AIFeedback, AITrainingExample, AILearningRule
|
|
| 19 |
from app.models.crm_integration import CRMIntegration, CRMSyncLog, CRMFieldMapping, LeadCRMLink, CRMType, SyncDirection, SyncStatus
|
| 20 |
from app.models.order import Order, OrderItem, OrderStatus
|
| 21 |
from app.models.landing import LandingConfig
|
|
|
|
| 22 |
|
| 23 |
__all__ = [
|
| 24 |
# Tenant
|
|
@@ -83,4 +84,8 @@ __all__ = [
|
|
| 83 |
|
| 84 |
# Landing
|
| 85 |
"LandingConfig",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
]
|
|
|
|
| 19 |
from app.models.crm_integration import CRMIntegration, CRMSyncLog, CRMFieldMapping, LeadCRMLink, CRMType, SyncDirection, SyncStatus
|
| 20 |
from app.models.order import Order, OrderItem, OrderStatus
|
| 21 |
from app.models.landing import LandingConfig
|
| 22 |
+
from app.models.system import SystemAnnouncement, SiteSettings
|
| 23 |
|
| 24 |
__all__ = [
|
| 25 |
# Tenant
|
|
|
|
| 84 |
|
| 85 |
# Landing
|
| 86 |
"LandingConfig",
|
| 87 |
+
|
| 88 |
+
# System
|
| 89 |
+
"SystemAnnouncement",
|
| 90 |
+
"SiteSettings",
|
| 91 |
]
|
backend/app/models/system.py
CHANGED
|
@@ -3,6 +3,7 @@ from sqlmodel import SQLModel, Field
|
|
| 3 |
from datetime import datetime
|
| 4 |
from uuid import UUID, uuid4
|
| 5 |
from typing import Optional
|
|
|
|
| 6 |
|
| 7 |
class SystemAnnouncement(SQLModel, table=True):
|
| 8 |
"""
|
|
@@ -18,3 +19,16 @@ class SystemAnnouncement(SQLModel, table=True):
|
|
| 18 |
created_at: datetime = Field(default_factory=datetime.utcnow)
|
| 19 |
expires_at: Optional[datetime] = None
|
| 20 |
created_by: UUID = Field(default=None) # Admin ID
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from datetime import datetime
|
| 4 |
from uuid import UUID, uuid4
|
| 5 |
from typing import Optional
|
| 6 |
+
from sqlalchemy import Column, JSON
|
| 7 |
|
| 8 |
class SystemAnnouncement(SQLModel, table=True):
|
| 9 |
"""
|
|
|
|
| 19 |
created_at: datetime = Field(default_factory=datetime.utcnow)
|
| 20 |
expires_at: Optional[datetime] = None
|
| 21 |
created_by: UUID = Field(default=None) # Admin ID
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class SiteSettings(SQLModel, table=True):
|
| 25 |
+
"""
|
| 26 |
+
Global site settings configurable by admin.
|
| 27 |
+
"""
|
| 28 |
+
__tablename__ = "site_settings"
|
| 29 |
+
|
| 30 |
+
id: UUID = Field(default_factory=uuid4, primary_key=True)
|
| 31 |
+
key: str = Field(unique=True, index=True) # e.g., "trust_logos", "footer_text"
|
| 32 |
+
value: str = Field(default="") # JSON string for complex values
|
| 33 |
+
updated_at: datetime = Field(default_factory=datetime.utcnow)
|
| 34 |
+
updated_by: Optional[UUID] = None
|
frontend/app/page.tsx
CHANGED
|
@@ -13,7 +13,8 @@ import { useState, useRef, useEffect } from 'react'
|
|
| 13 |
|
| 14 |
// --- DATA ---
|
| 15 |
|
| 16 |
-
|
|
|
|
| 17 |
'TechCorp', 'StartupHub', 'GrowthLab', 'SalesForce', 'Microsoft',
|
| 18 |
'HubSpot', 'Intercom', 'Zendesk', 'Pipedrive', 'Zoho'
|
| 19 |
]
|
|
@@ -262,6 +263,7 @@ export default function HomePage() {
|
|
| 262 |
const [isYearly, setIsYearly] = useState(true)
|
| 263 |
const [lang, setLang] = useState<LangCode>('ru')
|
| 264 |
const [showLangMenu, setShowLangMenu] = useState(false)
|
|
|
|
| 265 |
const t = T[lang]
|
| 266 |
|
| 267 |
// Demo Chat State
|
|
@@ -280,9 +282,28 @@ export default function HomePage() {
|
|
| 280 |
scrollToBottom()
|
| 281 |
}, [messages, isTyping])
|
| 282 |
|
| 283 |
-
// Scroll to top on page load
|
| 284 |
useEffect(() => {
|
| 285 |
window.scrollTo(0, 0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
}, [])
|
| 287 |
|
| 288 |
const handleSendMessage = async () => {
|
|
@@ -459,7 +480,7 @@ export default function HomePage() {
|
|
| 459 |
<section className="py-10 border-y border-white/5 bg-white/[0.01] overflow-hidden">
|
| 460 |
<div className="relative overflow-hidden [mask-image:_linear-gradient(to_right,transparent_0,_black_128px,_black_calc(100%-128px),transparent_100%)]">
|
| 461 |
<div className="flex w-max animate-marquee-infinite">
|
| 462 |
-
{[...
|
| 463 |
<div key={i} className="mx-8 text-xl font-bold text-slate-600/50 uppercase tracking-[0.2em] whitespace-nowrap hover:text-white/80 transition-colors cursor-default">
|
| 464 |
{logo}
|
| 465 |
</div>
|
|
|
|
| 13 |
|
| 14 |
// --- DATA ---
|
| 15 |
|
| 16 |
+
// Default trust logos - can be overridden via admin panel
|
| 17 |
+
const DEFAULT_TRUST_LOGOS = [
|
| 18 |
'TechCorp', 'StartupHub', 'GrowthLab', 'SalesForce', 'Microsoft',
|
| 19 |
'HubSpot', 'Intercom', 'Zendesk', 'Pipedrive', 'Zoho'
|
| 20 |
]
|
|
|
|
| 263 |
const [isYearly, setIsYearly] = useState(true)
|
| 264 |
const [lang, setLang] = useState<LangCode>('ru')
|
| 265 |
const [showLangMenu, setShowLangMenu] = useState(false)
|
| 266 |
+
const [trustLogos, setTrustLogos] = useState<string[]>(DEFAULT_TRUST_LOGOS)
|
| 267 |
const t = T[lang]
|
| 268 |
|
| 269 |
// Demo Chat State
|
|
|
|
| 282 |
scrollToBottom()
|
| 283 |
}, [messages, isTyping])
|
| 284 |
|
| 285 |
+
// Scroll to top on page load and fetch trust logos
|
| 286 |
useEffect(() => {
|
| 287 |
window.scrollTo(0, 0)
|
| 288 |
+
|
| 289 |
+
// Fetch trust logos from API
|
| 290 |
+
fetch(`${process.env.NEXT_PUBLIC_API_URL || 'https://api.microfunnel.online'}/api/v1/site-settings/public/trust_logos`)
|
| 291 |
+
.then(res => res.json())
|
| 292 |
+
.then(data => {
|
| 293 |
+
if (data.value) {
|
| 294 |
+
try {
|
| 295 |
+
const logos = JSON.parse(data.value)
|
| 296 |
+
if (Array.isArray(logos) && logos.length > 0) {
|
| 297 |
+
setTrustLogos(logos)
|
| 298 |
+
}
|
| 299 |
+
} catch (e) {
|
| 300 |
+
console.log('Using default trust logos')
|
| 301 |
+
}
|
| 302 |
+
}
|
| 303 |
+
})
|
| 304 |
+
.catch(() => {
|
| 305 |
+
console.log('Using default trust logos')
|
| 306 |
+
})
|
| 307 |
}, [])
|
| 308 |
|
| 309 |
const handleSendMessage = async () => {
|
|
|
|
| 480 |
<section className="py-10 border-y border-white/5 bg-white/[0.01] overflow-hidden">
|
| 481 |
<div className="relative overflow-hidden [mask-image:_linear-gradient(to_right,transparent_0,_black_128px,_black_calc(100%-128px),transparent_100%)]">
|
| 482 |
<div className="flex w-max animate-marquee-infinite">
|
| 483 |
+
{[...trustLogos, ...trustLogos, ...trustLogos, ...trustLogos].map((logo, i) => (
|
| 484 |
<div key={i} className="mx-8 text-xl font-bold text-slate-600/50 uppercase tracking-[0.2em] whitespace-nowrap hover:text-white/80 transition-colors cursor-default">
|
| 485 |
{logo}
|
| 486 |
</div>
|