- dashboard.py: decode session cookie and pass user to template - notes.py: pass user to template (both GET and POST) - CSS: .header-right flex layout, #user-info styles, min-height instead of fixed height - Removed duplicate #user-info CSS block - Login now properly shows admin/Deconnexion after authentication
53 lines
2.0 KiB
Python
53 lines
2.0 KiB
Python
"""FlowDeck — Notes markdown par projet."""
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from fastapi import APIRouter, Request
|
|
from fastapi.responses import HTMLResponse
|
|
|
|
from app.db import get_conn
|
|
|
|
logger = logging.getLogger(__name__)
|
|
router = APIRouter(tags=["notes"], prefix="/notes")
|
|
|
|
|
|
@router.get("/{owner}/{repo}", response_class=HTMLResponse)
|
|
async def get_notes(request: Request, owner: str, repo: str):
|
|
with get_conn() as conn:
|
|
row = conn.execute(
|
|
"SELECT content FROM notes WHERE project_owner=? AND project_name=? AND title='Notes'",
|
|
(owner, repo),
|
|
).fetchone()
|
|
content = row["content"] if row else ""
|
|
|
|
from jinja2 import Environment, FileSystemLoader
|
|
from app.auth.session import SessionManager
|
|
env = Environment(loader=FileSystemLoader("app/templates"))
|
|
user = SessionManager.decode_session(request.cookies.get("flowdeck_session", ""))
|
|
template = env.get_template("notes.html")
|
|
return template.render(request=request, owner=owner, repo=repo, content=content, user=user)
|
|
|
|
|
|
@router.post("/{owner}/{repo}", response_class=HTMLResponse)
|
|
async def save_notes(request: Request, owner: str, repo: str):
|
|
form = await request.form()
|
|
content = form.get("content", "")
|
|
|
|
with get_conn() as conn:
|
|
conn.execute(
|
|
"""INSERT INTO notes (project_owner, project_name, title, content, updated_at)
|
|
VALUES (?, ?, 'Notes', ?, CURRENT_TIMESTAMP)
|
|
ON CONFLICT(project_owner, project_name, title)
|
|
DO UPDATE SET content=excluded.content, updated_at=CURRENT_TIMESTAMP""",
|
|
(owner, repo, content),
|
|
)
|
|
conn.commit()
|
|
|
|
from jinja2 import Environment, FileSystemLoader
|
|
from app.auth.session import SessionManager
|
|
env = Environment(loader=FileSystemLoader("app/templates"))
|
|
user = SessionManager.decode_session(request.cookies.get("flowdeck_session", ""))
|
|
template = env.get_template("notes.html")
|
|
return template.render(request=request, owner=owner, repo=repo, content=content, user=user)
|