diff --git a/.gitignore b/.gitignore index a56320c..03d9a38 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .venv/ +.venv-host/ node_modules/ dist/ *.pyc diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..d664e7f --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,10 @@ +# Dashboard widget contract + +- Render every widget inside the shared minimal base card using existing CSS tokens. Keep widget data and business logic outside the card. +- Register widgets with a stable type ID and validated title, description, icon, template, span, settings keys, permissions, and multi-instance policy. +- The dashboard layout engine alone owns add, drag, drop, order, size, and per-user, per-page persistence. Widget scripts must initialize and clean up within their own root, including after partial page updates. +- Provide keyboard and touch alternatives to dragging, clear focus, screen-reader status, reduced motion, and WCAG 2.2 AA interaction and contrast. +- Show loading, empty, error, and stale states honestly. Show visible provider attribution when required. +- Require Django authentication and CSRF for layout changes. Validate configuration on the server, enforce ownership, and keep upstream secrets out of browser code. +- Test registry validation, user and page isolation, reorder persistence, and widget lifecycle when adding widgets. +- The card's `data-widget-platform` and `data-instance-id` are passive geometry hooks for future integrations. Do not add companion behavior here. diff --git a/README.md b/README.md index a12f359..5e1879b 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,25 @@ npm run dev The dashboard runs at `http://127.0.0.1:8765/`. `npm run dev` uses the existing package scripts; `npm run dev:mcp` starts the MCP process at `http://127.0.0.1:8766/mcp`. If Node.js is unavailable, use `.venv/bin/uvicorn mcp_server.server:app --host 127.0.0.1 --port 8766`. Port 8766 is separate from TasksNest's MCP listener. -`/projects/` contains active and archived projects. New projects seed editable To-do, In Progress, and Done columns. New cards use the board's selected default column and Medium priority. Cards store raw Markdown, a revision history, explicit blockers, comments, and activity. HTML output is sanitized. Git URLs are metadata; the server does not fetch or clone them. +### Persistent local services + +This host runs systemd with Python 3.12, while the development shell's `.venv` uses Python 3.13. The user services in `deploy/systemd/` therefore use the project-local `.venv-host`. To recreate it on the host, run `python3 -m venv .venv-host` and `.venv-host/bin/python -m pip install -r requirements.txt` there. Keep both virtualenvs out of Git. + +The linked `common-ground-django.service` and `common-ground-mcp.service` start on login or boot through the systemd user manager. The local Django service binds to `127.0.0.1:8765`; MCP binds only to the host's Tailscale address, `100.91.62.59:8766`. Manage them with: + +```sh +systemctl --user status common-ground-django.service common-ground-mcp.service +systemctl --user restart common-ground-django.service common-ground-mcp.service +journalctl --user -u common-ground-mcp.service -f +``` + +The Django process on port 8765 provides a local dashboard and OAuth server. The public Caddy configuration currently forwards the dashboard and OAuth routes to a separate Django process at `100.91.62.59:2345`, and MCP routes to `100.91.62.59:8766`. An unauthenticated `GET /mcp` should return HTTP 401. Optional settings for the user services belong in `~/.config/common-ground/env`, outside the repository. After changing that file, restart the affected service. + +Remote clients use the public HTTPS reverse proxy. Route `/mcp` and `/.well-known/oauth-protected-resource/mcp` to the Tailscale-only MCP listener on port 8766, and the dashboard plus OAuth discovery and `/o/` to the Django process on port 2345. The processes must share the same database and `DJANGO_SECRET_KEY`. Keep MCP off public and LAN interfaces; the Tailscale address is reachable through the authenticated tailnet. + +For `https://projects.jorendegraaf.eu`, MCP advertises `MCP_PUBLIC_URL=https://projects.jorendegraaf.eu/mcp` and `OAUTH_ISSUER_URL=https://projects.jorendegraaf.eu`. Set these in the public Django process too, especially to make its Profile configuration check agree. Profile shows the visiting HTTPS origin plus `/mcp`; on localhost it retains the separate development port. OAuth discovery, protected-resource metadata, and the reverse proxy must agree on the public URLs before a remote client can connect. Redirect the singular `project.jorendegraaf.eu` alias to the canonical plural hostname so OAuth resource identifiers remain consistent. Keep `DJANGO_ALLOWED_HOSTS` restricted to served hostnames. Caddy forwards the original `Host` and `X-Forwarded-Proto` headers by default. + +`/projects/` contains active and archived projects. New projects seed editable To-do, In Progress, and Done columns. New cards use the board's selected default column and Medium priority. Cards store raw Markdown, a revision history, explicit blockers, comments, and activity. HTML output is sanitized. Git URLs are metadata; the server does not fetch or clone them. Profile timezone accepts an IANA name and controls timestamps on authenticated pages; the default is Europe/Amsterdam. ## OAuth and MCP @@ -22,6 +40,8 @@ The Django server hosts OAuth authorization, token, revocation, and discovery en Authenticated dynamic client registration is enabled at `/o/register/`. A signed-in user can register a client; session requests also need a CSRF token. Anonymous registration is denied. You can also create a public authorization-code client in Django admin, setting its exact HTTPS redirect URI and the needed scopes. Profile shows active grants and revocation controls. +For ChatGPT's custom MCP plugin, open Advanced OAuth settings and choose a provided/registered client rather than dynamic registration. Use the public authorization-code client registered with redirect URI `https://chatgpt.com/connector_platform_oauth_redirect`, token endpoint authentication method `none`, and default scope `projects:read` (add `projects:write` to enable edits). The server URL is `https://projects.jorendegraaf.eu/mcp`; the authorization and token endpoints are `https://projects.jorendegraaf.eu/o/authorize/` and `https://projects.jorendegraaf.eu/o/token/`. The protected-resource metadata's authorization server must exactly match the OAuth discovery issuer, including its trailing slash. + Local accounts work by default. To enable separate OIDC sign-in to the dashboard, set `OIDC_OP_ISSUER`, `OIDC_OP_AUTHORIZATION_ENDPOINT`, `OIDC_OP_TOKEN_ENDPOINT`, `OIDC_OP_USER_ENDPOINT`, `OIDC_OP_JWKS_ENDPOINT`, `OIDC_RP_CLIENT_ID`, and `OIDC_RP_CLIENT_SECRET`. Register `/oidc/callback/` at the provider. OIDC identities are linked by verified issuer and subject; a matching email does not link an existing local account. The actual provider callback still needs an integration test with your provider configuration. Set `MCP_PUBLIC_URL` and `OAUTH_ISSUER_URL` to the public HTTPS MCP endpoint and Django origin. Route `/mcp` and `/.well-known/oauth-protected-resource/mcp` to port 8766, and OAuth routes to the Django process. Preserve the Authorization header. The MCP process and Django must use the same database and `DJANGO_SECRET_KEY`. diff --git a/config/settings.py b/config/settings.py index 0c65050..9daf68f 100644 --- a/config/settings.py +++ b/config/settings.py @@ -7,12 +7,16 @@ SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', 'django-insecure-local-developm DEBUG = os.environ.get('DJANGO_DEBUG', '1') == '1' if not DEBUG and (SECRET_KEY.startswith('django-insecure-') or len(SECRET_KEY) < 50): raise ImproperlyConfigured('Set a strong DJANGO_SECRET_KEY when DJANGO_DEBUG=0.') -ALLOWED_HOSTS = os.environ.get('DJANGO_ALLOWED_HOSTS', 'localhost,127.0.0.1').split(',') +ALLOWED_HOSTS = [host.strip() for host in os.environ.get( + 'DJANGO_ALLOWED_HOSTS', + 'localhost,127.0.0.1,100.91.62.59,projects.jorendegraaf.eu,project.jorendegraaf.eu', +).split(',') if host.strip()] INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.sessions', 'django.contrib.messages', "django.contrib.contenttypes", "django.contrib.staticfiles", "core", + "dashboard", 'projects', 'oauth2_provider', ] @@ -22,6 +26,7 @@ MIDDLEWARE = [ "django.middleware.common.CommonMiddleware", 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'projects.middleware.ProfileTimezoneMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] @@ -40,6 +45,13 @@ USE_TZ = True STATICFILES_DIRS = [BASE_DIR / "dist"] if (BASE_DIR / "dist").exists() else [] DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField" DATABASES = {'default': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': BASE_DIR / 'db.sqlite3'}} +CACHES = { + 'default': {'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}, + 'weather': { + 'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache', + 'LOCATION': os.environ.get('DASHBOARD_WEATHER_CACHE_DIR', '/tmp/django_dashboard_weather_cache'), + }, +} LOGIN_URL = 'login' LOGIN_REDIRECT_URL = 'projects:list' LOGOUT_REDIRECT_URL = 'login' @@ -49,11 +61,12 @@ SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https') SECURE_SSL_REDIRECT = not DEBUG SECURE_HSTS_SECONDS = 31536000 if not DEBUG else 0 CSRF_TRUSTED_ORIGINS = [item for item in os.environ.get('DJANGO_CSRF_TRUSTED_ORIGINS', '').split(',') if item] -MCP_PUBLIC_URL = os.environ.get('MCP_PUBLIC_URL', 'http://127.0.0.1:8766/mcp') -OAUTH_ISSUER_URL = os.environ.get('OAUTH_ISSUER_URL', 'http://127.0.0.1:8765/') +MCP_PUBLIC_URL = os.environ.get('MCP_PUBLIC_URL', 'https://projects.jorendegraaf.eu/mcp').strip() +OAUTH_ISSUER_URL = os.environ.get('OAUTH_ISSUER_URL', 'https://projects.jorendegraaf.eu').strip().rstrip('/') if not DEBUG and (not MCP_PUBLIC_URL.startswith('https://') or not OAUTH_ISSUER_URL.startswith('https://')): raise ImproperlyConfigured('MCP_PUBLIC_URL and OAUTH_ISSUER_URL must use HTTPS in production.') OAUTH2_PROVIDER = { + 'OIDC_ISS_ENDPOINT': f'{OAUTH_ISSUER_URL}/', 'SCOPES': {'projects:read': 'Read projects and cards', 'projects:write': 'Create and edit projects and cards'}, 'DEFAULT_SCOPES': ['projects:read'], 'ALLOWED_REDIRECT_URI_SCHEMES': ['http', 'https'] if DEBUG else ['https'], @@ -65,6 +78,7 @@ OAUTH2_PROVIDER = { 'REFRESH_TOKEN_REUSE_PROTECTION': True, 'DCR_ENABLED': True, 'DCR_REGISTRATION_PERMISSION_CLASSES': ['oauth2_provider.dcr.IsAuthenticatedDCRPermission'], + 'OAUTH2_TOKEN_ENDPOINT_AUTH_METHODS_SUPPORTED': ['none', 'client_secret_post', 'client_secret_basic'], 'COMPLIANT_BCP_RFC9700_IMPLICIT_GRANT': True, 'COMPLIANT_BCP_RFC9700_PASSWORD_GRANT': True, 'COMPLIANT_BCP_RFC9700_AUTHZ_RESPONSE_ISS': True, diff --git a/config/urls.py b/config/urls.py index 1bb07e6..006c218 100644 --- a/config/urls.py +++ b/config/urls.py @@ -14,7 +14,8 @@ urlpatterns = [ path('accounts/logout/', auth_views.LogoutView.as_view(), name='logout'), path('accounts/password/change/', auth_views.PasswordChangeView.as_view(template_name='projects/form.html', success_url='/projects/profile/'), name='password_change'), path('projects/', include('projects.urls')), - path("", views.today, name="today"), + path("", include('dashboard.urls')), + path("examples/today/", views.today, name="today"), path("health/", views.health, name="health"), path("energy/", views.energy, name="energy"), path("home/", views.home, name="home"), diff --git a/core/static/core/theme-bridge.css b/core/static/core/theme-bridge.css new file mode 100644 index 0000000..fa082d3 --- /dev/null +++ b/core/static/core/theme-bridge.css @@ -0,0 +1,163 @@ +/* Keep Bootstrap components in the same palette as the dashboard shell. */ +html[data-theme] { + --bs-body-bg: var(--page-bg); + --bs-body-color: var(--text); + --bs-emphasis-color: var(--text); + --bs-secondary-color: var(--text-secondary); + --bs-secondary-bg: var(--surface-secondary); + --bs-tertiary-bg: var(--surface); + --bs-border-color: var(--border); + --bs-border-color-translucent: var(--border); + --bs-heading-color: var(--text); + --bs-link-color: var(--accent); + --bs-link-hover-color: var(--positive); + --bs-code-color: var(--accent); + --bs-form-valid-color: var(--positive); + --bs-form-invalid-color: var(--negative); +} + +html[data-theme] .card, +html[data-theme] .dropdown-menu, +html[data-theme] .modal-content, +html[data-theme] .list-group-item, +html[data-theme] .accordion-item { + --bs-card-bg: var(--surface); + --bs-card-color: var(--text); + background-color: var(--surface); + color: var(--text); + border-color: var(--border); +} + +html[data-theme] .card-header, +html[data-theme] .card-footer, +html[data-theme] .accordion-button { + background-color: var(--surface-secondary); + color: var(--text); + border-color: var(--border); +} + +html[data-theme] .form-control, +html[data-theme] .form-select, +html[data-theme] select, +html[data-theme] textarea, +html[data-theme] input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]) { + background-color: var(--surface); + color: var(--text); + border-color: var(--border); +} + +html[data-theme] main form p label { + display: block; + margin-bottom: .3rem; + color: var(--text-secondary); + font-weight: 600; +} + +html[data-theme] main form p input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="color"]), +html[data-theme] main form p textarea, +html[data-theme] main form p select { + display: block; + width: 100%; + max-width: 100%; + padding: .5rem .75rem; + border: 1px solid var(--border); + border-radius: .5rem; +} + +html[data-theme] .form-control::placeholder, +html[data-theme] textarea::placeholder, +html[data-theme] input::placeholder { + color: var(--text-muted); + opacity: 1; +} + +html[data-theme] .form-control:focus, +html[data-theme] .form-select:focus, +html[data-theme] select:focus, +html[data-theme] textarea:focus, +html[data-theme] input:focus:not([type="checkbox"]):not([type="radio"]) { + background-color: var(--surface); + color: var(--text); + border-color: var(--focus); + box-shadow: 0 0 0 .2rem color-mix(in srgb, var(--focus) 25%, transparent); +} + +html[data-theme] .form-control:disabled, +html[data-theme] .form-select:disabled, +html[data-theme] select:disabled, +html[data-theme] input:disabled { + background-color: var(--surface-secondary); + color: var(--text-muted); +} + +html[data-theme] option { + background-color: var(--surface); + color: var(--text); +} + +html[data-theme] .form-check-input { + background-color: var(--surface); + border-color: var(--text-muted); +} + +html[data-theme] .form-check-input:checked { + background-color: var(--positive); + border-color: var(--positive); +} + +html[data-theme] .text-bg-light, +html[data-theme] .bg-light { + background-color: var(--surface-secondary) !important; + color: var(--text) !important; +} + +html[data-theme] .text-muted, +html[data-theme] .text-secondary { + color: var(--text-secondary) !important; +} + +html[data-theme] .btn-outline-secondary { + --bs-btn-color: var(--text-secondary); + --bs-btn-border-color: var(--border); + --bs-btn-hover-color: var(--text); + --bs-btn-hover-bg: var(--surface-secondary); + --bs-btn-hover-border-color: var(--text-muted); + --bs-btn-active-color: var(--text); + --bs-btn-active-bg: var(--surface-secondary); + --bs-btn-active-border-color: var(--text-muted); +} + +html[data-theme] .btn-outline-danger { + --bs-btn-color: var(--negative); + --bs-btn-border-color: var(--negative); + --bs-btn-hover-color: var(--page-bg); + --bs-btn-hover-bg: var(--negative); + --bs-btn-hover-border-color: var(--negative); +} + +html[data-theme] .btn-success { + --bs-btn-bg: var(--positive); + --bs-btn-border-color: var(--positive); + --bs-btn-color: var(--page-bg); + --bs-btn-hover-bg: var(--accent); + --bs-btn-hover-border-color: var(--accent); + --bs-btn-hover-color: var(--page-bg); +} + +html[data-theme] .table { + --bs-table-bg: var(--surface); + --bs-table-color: var(--text); + --bs-table-border-color: var(--border); + --bs-table-striped-bg: var(--surface-secondary); + --bs-table-striped-color: var(--text); +} + +html[data-theme="dark"] .form-select { + background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23b5c4b9' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e"); +} + +@media (prefers-color-scheme: dark) { + html[data-theme="system"] .form-select { + background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23b5c4b9' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e"); + } +} diff --git a/core/templates/core/base.html b/core/templates/core/base.html index 4e33023..0761521 100644 --- a/core/templates/core/base.html +++ b/core/templates/core/base.html @@ -11,22 +11,19 @@ {% vite_assets %} +
Skip to content