feat: redesign the web console with Vue and isolated account workspaces

This commit is contained in:
AttilaNet
2026-11-11 09:35:54 +08:00
parent 99aff423d8
commit ff6a828f58
46 changed files with 4549 additions and 748 deletions
+40 -3
View File
@@ -4,6 +4,7 @@ import asyncio
import base64
from copy import deepcopy
from datetime import datetime, timedelta, timezone
from html.parser import HTMLParser
import json
import os
from pathlib import Path
@@ -22,6 +23,29 @@ from ranch_web.app import create_app
from ranch_web.config import WebConfig
class FrontendAssets(HTMLParser):
"""Read the built entry so tests also exercise hashed asset URLs."""
def __init__(self, content):
super().__init__()
self.scripts, self.stylesheets, self.preloads = [], [], []
self.feed(content)
def handle_starttag(self, tag, attrs):
attrs = dict(attrs)
if tag == "script" and attrs.get("src"):
self.scripts.append((attrs["src"], attrs.get("type")))
if tag == "link" and attrs.get("href"):
if attrs.get("rel") == "stylesheet":
self.stylesheets.append(attrs["href"])
elif attrs.get("rel") == "modulepreload":
self.preloads.append(attrs["href"])
@property
def urls(self):
return [url for url, _ in self.scripts] + self.stylesheets + self.preloads
class FakeUpdates:
def __init__(self):
self.calls = []
@@ -513,15 +537,28 @@ class ApiTests(unittest.TestCase):
for url in ("/static/.env", "/static/config.py", "/static/../app.py", "/static/%2e%2e/requirements.txt"):
with self.subTest(url=url):
self.assertEqual(self.client.get(url).status_code, 404)
for url in ("/", "/static/index.html", "/static/app.js"):
entry = self.client.get("/")
assets = FrontendAssets(entry.text)
self.assertTrue(assets.scripts, "The console entry must reference its built JavaScript")
self.assertTrue(assets.stylesheets, "The console must load its stylesheet under CSP")
self.assertTrue(all(kind == "module" for _, kind in assets.scripts))
for url in assets.urls:
self.assertTrue(url.startswith("/static/"), url)
for url in ("/", "/static/index.html", *assets.urls):
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.headers["cache-control"], "no-store")
self.assertEqual(response.status_code, 200, url)
if url not in assets.stylesheets:
self.assertEqual(response.headers["cache-control"], "no-store")
self.assertEqual(response.headers["x-content-type-options"], "nosniff")
self.assertIn("frame-ancestors 'none'", response.headers["content-security-policy"])
if url in [script for script, _ in assets.scripts] or url in assets.preloads:
self.assertIn("javascript", response.headers["content-type"], url)
elif url in assets.stylesheets:
self.assertIn("text/css", response.headers["content-type"], url)
for url in ("/", "/static/index.html"):
response = self.client.get(url)
self.assertIn("text/html", response.headers["content-type"])
self.assertEqual(FrontendAssets(response.text).urls, assets.urls)
response = self.client.get("/login", follow_redirects=False)
self.assertEqual(response.status_code, 303)
self.assertEqual(response.headers["location"], "/")