fix: board._sidebar_data now handles Gitea workspace cookie — tree persists across all pages
Root cause: board._sidebar_data tried int(gitea:owner:repo) → ValueError → lost context
Library, Trash, page editor pages showed empty workspace tree
Fix: board._sidebar_data now mirrors dashboard._sidebar_data logic:
- Detects gitea: prefixed cookie
- Preserves active_ws_name, workspace_key, gitea_workspace
- Loads local_ws_id for mirror workspace
- Tree stays visible on /library, /trash, page editor, etc.
This commit is contained in:
+41
-6
@@ -225,14 +225,46 @@ def _sidebar_data(request: Request, owner: str = "", repo: str = "") -> dict:
|
|||||||
from app.routers.dashboard import WORKSPACE_COOKIE
|
from app.routers.dashboard import WORKSPACE_COOKIE
|
||||||
ws_cookie = request.cookies.get(WORKSPACE_COOKIE, "")
|
ws_cookie = request.cookies.get(WORKSPACE_COOKIE, "")
|
||||||
active_ws_name = "Workspace"
|
active_ws_name = "Workspace"
|
||||||
if ws_cookie:
|
workspace_pages = []
|
||||||
|
gitea_workspace = False
|
||||||
|
gitea_owner = ""
|
||||||
|
gitea_repo = ""
|
||||||
|
|
||||||
|
if ws_cookie and ws_cookie.startswith("gitea:"):
|
||||||
|
# Gitea workspace: preserve context across pages
|
||||||
|
parts = ws_cookie.split(":", 2)
|
||||||
|
if len(parts) >= 3:
|
||||||
|
gitea_owner = parts[1]
|
||||||
|
gitea_repo = parts[2]
|
||||||
|
active_ws_name = f"{gitea_owner}/{gitea_repo}"
|
||||||
|
gitea_workspace = True
|
||||||
|
workspace_pages = [] # loaded client-side
|
||||||
|
# Get local workspace ID for mirror
|
||||||
|
if user:
|
||||||
|
try:
|
||||||
|
with get_conn() as conn:
|
||||||
|
row = conn.execute(
|
||||||
|
"SELECT id FROM workspaces WHERE owner_id=? AND name=? AND settings_json LIKE ?",
|
||||||
|
(user["id"], f"{gitea_owner}/{gitea_repo}", "%gitea_repo%")
|
||||||
|
).fetchone()
|
||||||
|
if row:
|
||||||
|
local_ws_id = row["id"]
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
elif ws_cookie and user:
|
||||||
try:
|
try:
|
||||||
|
wsi = int(ws_cookie)
|
||||||
with get_conn() as conn:
|
with get_conn() as conn:
|
||||||
ws = conn.execute("SELECT name FROM workspaces WHERE id=?", (int(ws_cookie),)).fetchone()
|
row = conn.execute(
|
||||||
if ws:
|
"SELECT id, name, owner_id FROM workspaces WHERE id=? AND owner_id=?",
|
||||||
active_ws_name = ws["name"]
|
(wsi, user["id"])
|
||||||
|
).fetchone()
|
||||||
|
if row:
|
||||||
|
active_ws_name = row["name"]
|
||||||
|
workspace_pages = _load_workspace_pages(ws_cookie)
|
||||||
except (ValueError, Exception):
|
except (ValueError, Exception):
|
||||||
pass
|
pass
|
||||||
|
local_ws_id = 0
|
||||||
recent = []
|
recent = []
|
||||||
if owner and repo:
|
if owner and repo:
|
||||||
view_map = {
|
view_map = {
|
||||||
@@ -331,12 +363,15 @@ def _sidebar_data(request: Request, owner: str = "", repo: str = "") -> dict:
|
|||||||
|
|
||||||
return {"workspace_name": ws_name, "workspace_initial": ws_name[0].upper() if ws_name else "B",
|
return {"workspace_name": ws_name, "workspace_initial": ws_name[0].upper() if ws_name else "B",
|
||||||
"active_ws_name": active_ws_name,
|
"active_ws_name": active_ws_name,
|
||||||
"workspace_pages": _load_workspace_pages(ws_cookie),
|
"workspace_key": f"{gitea_owner}/{gitea_repo}" if gitea_workspace else ws_key,
|
||||||
|
"workspace_pages": workspace_pages,
|
||||||
|
"gitea_workspace": gitea_workspace,
|
||||||
|
"local_ws_id": local_ws_id,
|
||||||
"current_page": repo or "Dashboard", "last_edited": "now",
|
"current_page": repo or "Dashboard", "last_edited": "now",
|
||||||
"recent_pages": recent, "private_pages": private_items,
|
"recent_pages": recent, "private_pages": private_items,
|
||||||
"favorite_pages": favorites, "shared_pages": shared_pages,
|
"favorite_pages": favorites, "shared_pages": shared_pages,
|
||||||
"published_pages": published_pages,
|
"published_pages": published_pages,
|
||||||
"user": user, "workspace_key": ws_key,
|
"user": user,
|
||||||
"auth_method": auth_method,
|
"auth_method": auth_method,
|
||||||
"gitea_linked": gitea_linked,
|
"gitea_linked": gitea_linked,
|
||||||
"github_linked": github_linked}
|
"github_linked": github_linked}
|
||||||
|
|||||||
Reference in New Issue
Block a user