feat: add VK OAuth connection with health checks

- Add VkConnection model with is_online/last_checked_at fields
- Add /vk OAuth flow (connect/callback/disconnect/page)
- Add VK entry to connections dashboard
- Extend background health checker to check VK tokens via users.get
- Add Alembic migration for vk_connections table
- Add VK_CLIENT_ID/SECRET/SCOPES/API_VERSION config settings

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
mguschin
2026-03-06 15:29:42 +03:00
parent 379f781e1e
commit cfc7229daf
8 changed files with 358 additions and 9 deletions

View File

@@ -5,7 +5,7 @@ from sqlalchemy.orm import Session
from web.auth import get_current_user
from web.database import get_db
from web.models import User, EvotorConnection
from web.models import User, EvotorConnection, VkConnection
router = APIRouter()
templates = Jinja2Templates(directory="web/templates")
@@ -21,6 +21,7 @@ def connections_page(
return RedirectResponse("/login", 303)
evotor = db.query(EvotorConnection).filter(EvotorConnection.user_id == user.id).first()
vk = db.query(VkConnection).filter(VkConnection.user_id == user.id).first()
connections = [
{
@@ -32,7 +33,17 @@ def connections_page(
"details": evotor.store_name if evotor else None,
"connect_url": "/evotor/connect",
"disconnect_url": "/evotor/disconnect",
}
},
{
"name": "ВКонтакте",
"icon": "bi-chat-dots",
"connected": vk is not None,
"is_online": vk.is_online if vk else False,
"last_checked_at": vk.last_checked_at if vk else None,
"details": f"{vk.first_name} {vk.last_name}".strip() if vk and vk.first_name else None,
"connect_url": "/vk",
"disconnect_url": "/vk/disconnect",
},
]
return templates.TemplateResponse("connections.html", {