8 Commits

Author SHA1 Message Date
cbaff5614a feat(docker): add script to run Docker container for calminer application
Some checks failed
CI / lint (push) Successful in 17s
Deploy - Coolify / deploy (push) Failing after 5s
CI / test (push) Successful in 1m3s
CI / build (push) Successful in 2m18s
2025-11-15 19:58:55 +01:00
f9feb51d33 refactor(docker): update .gitignore for devcontainer files and remove version from docker-compose
Some checks failed
CI / lint (push) Successful in 16s
Deploy - Coolify / deploy (push) Failing after 5s
CI / test (push) Successful in 1m4s
CI / build (push) Successful in 2m19s
2025-11-15 15:41:43 +01:00
eb2687829f refactor(navigation): remove legacy navigation.js and integrate logic into navigation_sidebar.js
Some checks failed
CI / lint (push) Successful in 17s
Deploy - Coolify / deploy (push) Failing after 5s
CI / test (push) Successful in 1m21s
CI / build (push) Successful in 2m25s
2025-11-15 13:53:50 +01:00
ea101d1695 Merge branch 'main' of https://git.allucanget.biz/allucanget/calminer
Some checks failed
CI / lint (push) Successful in 17s
Deploy - Coolify / deploy (push) Failing after 5s
CI / test (push) Successful in 1m3s
CI / build (push) Successful in 2m15s
2025-11-14 21:22:37 +01:00
722f93b41c refactor(ci): remove deployment context capture and simplify API call for Coolify deployment 2025-11-14 21:20:37 +01:00
e2e5e12f46 Merge pull request 'merge develop to main' (#13) from develop into main
Some checks failed
Deploy - Coolify / deploy (push) Failing after 6s
CI / lint (push) Successful in 17s
CI / test (push) Successful in 1m3s
CI / build (push) Successful in 2m16s
Reviewed-on: #13
2025-11-14 20:49:10 +01:00
4e60168837 Merge https://git.allucanget.biz/allucanget/calminer into develop
All checks were successful
CI / lint (push) Successful in 16s
CI / lint (pull_request) Successful in 16s
CI / test (push) Successful in 1m4s
CI / test (pull_request) Successful in 1m2s
CI / build (push) Successful in 1m49s
CI / build (pull_request) Successful in 1m51s
2025-11-14 20:32:03 +01:00
854b1ac713 Merge pull request 'feat:v2' (#12) from develop into main
All checks were successful
CI / lint (push) Successful in 16s
CI / test (push) Successful in 1m3s
CI / build (push) Successful in 2m17s
Reviewed-on: #12
2025-11-14 18:02:54 +01:00
10 changed files with 385 additions and 186 deletions

View File

@@ -20,31 +20,6 @@ jobs:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Capture deployment context
id: context
run: |
set -euo pipefail
repo="${GITEA_REPOSITORY:-${GITHUB_REPOSITORY:-}}"
if [ -z "$repo" ]; then
repo="$(git remote get-url origin | sed 's#.*/\(.*\)\.git#\1#')"
fi
ref_name="${GITEA_REF_NAME:-${GITHUB_REF_NAME:-}}"
full_ref="${GITEA_REF:-${GITHUB_REF:-}}"
if [ -z "$ref_name" ] && [ -n "$full_ref" ]; then
ref_name="${full_ref##*/}"
fi
if [ -z "$ref_name" ]; then
ref_name="$(git rev-parse --abbrev-ref HEAD)"
fi
sha="${GITEA_SHA:-${GITHUB_SHA:-}}"
if [ -z "$sha" ]; then
sha="$(git rev-parse HEAD)"
fi
echo "repository=$repo" >> "$GITHUB_OUTPUT"
echo "ref=${ref_name:-main}" >> "$GITHUB_OUTPUT"
echo "sha=$sha" >> "$GITHUB_OUTPUT"
- name: Prepare compose bundle - name: Prepare compose bundle
run: | run: |
set -euo pipefail set -euo pipefail
@@ -72,12 +47,10 @@ jobs:
fi fi
- name: Trigger deployment via Coolify API - name: Trigger deployment via Coolify API
env:
HEAD_SHA: ${{ steps.context.outputs.sha }}
run: | run: |
set -euo pipefail set -euo pipefail
api_url="$COOLIFY_BASE_URL/api/v1/applications/${COOLIFY_APPLICATION_ID}/deploy" api_url="$COOLIFY_BASE_URL/api/v1/deploy"
payload=$(jq -n --arg sha "$HEAD_SHA" '{ commitSha: $sha }') payload=$(jq -n --arg uuid "$COOLIFY_APPLICATION_ID" '{ uuid: $uuid }')
response=$(curl -sS -w '\n%{http_code}' \ response=$(curl -sS -w '\n%{http_code}' \
-X POST "$api_url" \ -X POST "$api_url" \
-H "Authorization: Bearer $COOLIFY_API_TOKEN" \ -H "Authorization: Bearer $COOLIFY_API_TOKEN" \

4
.gitignore vendored
View File

@@ -54,3 +54,7 @@ local*.db
# Act runner files # Act runner files
.runner .runner
# Devcontainer files
.devcontainer/devcontainer.json
.devcontainer/docker-compose.yml

View File

@@ -1,112 +1,124 @@
# Changelog # Changelog
## 2025-11-15
- Fixed dev container setup by reviewing logs, identifying mount errors, implementing fixes, and validating the configuration.
## 2025-11-14
- Completed Coolify deployment automation with workflow and documentation.
- Improved build workflow for registry authentication and tagging.
- Updated production compose and added deployment guidance.
- Added optional Kubernetes deployment toggle.
## 2025-11-13 ## 2025-11-13
- Completed the UI alignment initiative by consolidating shared form and button styles into `static/css/forms.css` and `static/css/main.css`, introducing the semantic palette in `static/css/theme-default.css`, and spot-checking key pages plus contrast reports. - Aligned UI styles and ensured accessibility.
- Refactored the architecture data model docs by turning `calminer-docs/architecture/08_concepts/02_data_model.md` into a concise overview that links to new detail pages covering SQLAlchemy models, navigation metadata, enumerations, Pydantic schemas, and monitoring tables. - Restructured navigation under project-scenario-calculation hierarchy.
- Nested the calculator navigation under Projects by updating `scripts/init_db.py` seeds, teaching `services/navigation.py` to resolve scenario-scoped hrefs for profitability/opex/capex, and extending sidebar coverage through `tests/integration/test_navigation_sidebar_calculations.py` plus `tests/services/test_navigation_service.py` to validate admin/viewer visibility and contextual URL generation. - Reorganized documentation for better structure.
- Added navigation sidebar integration coverage by extending `tests/conftest.py` with role-switching headers, seeding admin/viewer test users, and adding `tests/integration/test_navigation_sidebar.py` to assert ordered link rendering for admins, viewer filtering of admin-only entries, and anonymous rejection of the endpoint. - Refactored navigation sidebar with database-driven data.
- Finalised the financial data import/export templates by inventorying required fields, defining CSV column specs with validation rules, drafting Excel workbook layouts, documenting end-user workflows in `calminer-docs/userguide/data_import_export.md`, and recording stakeholder review steps alongside updated TODO/DONE tracking. - Migrated sidebar rendering to API endpoint.
- Scoped profitability calculator UI under the scenario hierarchy by adding `/calculations/projects/{project_id}/scenarios/{scenario_id}/profitability` GET/POST handlers, updating scenario templates and sidebar navigation to link to the new route, and extending `tests/test_project_scenario_routes.py` with coverage for the scenario path plus legacy redirect behaviour (module run: 14 passed). - Created templates for data import and export.
- Extended scenario frontend regression coverage by updating `tests/test_project_scenario_routes.py` to assert project/scenario breadcrumbs and calculator navigation, normalising escaped URLs, and re-running the module tests (13 passing). - Updated relationships for projects, scenarios, and profitability.
- Cleared FastAPI and Pydantic deprecation warnings by migrating `scripts/init_db.py` to `@field_validator`, replacing the `main.py` startup hook with a lifespan handler, auditing template response call signatures, confirming HTTP 422 constant usage, and re-running the full pytest suite to ensure a clean warning slate. - Enhanced scenario frontend templates with project context.
- Delivered the capex planner end-to-end: added scaffolded UI in `templates/scenarios/capex.html`, wired GET/POST handlers through `routes/calculations.py`, implemented calculation logic plus snapshot persistence in `services/calculations.py` and `models/capex_snapshot.py`, updated navigation links, and introduced unit tests in `tests/services/test_calculations_capex.py`. - Scoped profitability calculator to scenario level.
- Updated UI navigation to surface the opex planner by adding the sidebar link in `templates/partials/sidebar_nav.html`, wiring a scenario detail action in `templates/scenarios/detail.html`. - Added navigation links for opex planner.
- Completed manual validation of the Capex Planner UI flows (sidebar entry, scenario deep link, validation errors, successful calculation) with results captured in `manual_tests/capex.md`, documented snapshot verification steps, and noted the optional JSON client check for future follow-up. - Documented opex planner features.
- Added opex calculation unit tests in `tests/services/test_calculations_opex.py` covering success metrics, currency validation, frequency enforcement, and evaluation horizon extension. - Integrated opex calculations with persistence and tests.
- Documented the Opex Planner workflow in `calminer-docs/userguide/opex_planner.md`, linked it from the user guide index, extended `calminer-docs/architecture/08_concepts/02_data_model.md` with snapshot coverage, and captured the completion in `.github/instructions/DONE.md`. - Implemented capex calculations end-to-end.
- Implemented opex integration coverage in `tests/integration/test_opex_calculations.py`, exercising HTML and JSON flows, verifying snapshot persistence, and asserting currency mismatch handling for form and API submissions. - Added basic profitability calculations.
- Executed the full pytest suite with coverage (211 tests) to confirm no regressions or warnings after the opex documentation updates. - Developed reporting endpoints and templates.
- Completed the navigation sidebar API migration by finalising the database-backed service, refactoring `templates/partials/sidebar_nav.html` to consume the endpoint, hydrating via `static/js/navigation_sidebar.js`, and updating HTML route dependencies (`routes/projects.py`, `routes/scenarios.py`, `routes/reports.py`, `routes/imports.py`, `routes/calculations.py`) to use redirect-aware guards so anonymous visitors receive login redirects instead of JSON errors (manual verification via curl across projects, scenarios, reports, and calculations pages). - Integrated charting for visualizations.
- Performed manual testing of capex planner.
- Added unit tests for opex service.
- Added integration tests for opex.
## 2025-11-12 ## 2025-11-12
- Fixed critical 500 error in reporting dashboard by correcting route reference in reporting.html template - changed 'reports.project_list_page' to 'projects.project_list_page' to resolve NoMatchFound error when accessing /ui/reporting. - Fixed reporting dashboard error by correcting route reference.
- Completed navigation validation by inventorying all sidebar navigation links, identifying missing routes for simulations, reporting, settings, themes, and currencies, created new UI routes in routes/ui.py with proper authentication guards, built corresponding templates (simulations.html, reporting.html, settings.html, theme_settings.html, currencies.html), registered the UI router in main.py, updated sidebar navigation to use route names instead of hardcoded URLs, and enhanced navigation.js to use dynamic URL resolution for proper route handling. - Completed navigation validation by adding missing routes and templates for various pages.
- Fixed critical template rendering error in sidebar_nav.html where URL objects from `request.url_for()` were being used with string methods, causing TypeError. Added `|string` filters to convert URL objects to strings for proper template rendering. - Fixed template rendering error with URL objects.
- Integrated Plotly charting for interactive visualizations in reporting templates, added chart generation methods to ReportingService (`generate_npv_comparison_chart`, `generate_distribution_histogram`), updated project summary and scenario distribution contexts to include chart JSON data, enhanced templates with chart containers and JavaScript rendering, added chart-container CSS styling, and validated all reporting tests pass. - Integrated charting for interactive visualizations.
- Verified local application startup and routes.
- Completed local run verification: started application with `uvicorn main:app --reload` without errors, verified authenticated routes (/login, /, /projects/ui, /projects) load correctly with seeded data, and summarized findings for deployment pipeline readiness. - Fixed docker-compose configuration.
- Fixed docker-compose.override.yml command array to remove duplicate "uvicorn" entry, enabling successful container startup with uvicorn reload in development mode. - Verified deployment pipeline.
- Completed deployment pipeline verification: built Docker image without errors, validated docker-compose configuration, deployed locally with docker-compose (app and postgres containers started successfully), and confirmed application startup logs showing database bootstrap and seeded data initialization. - Documented data models.
- Completed documentation of current data models: updated `calminer-docs/architecture/08_concepts/02_data_model.md` with comprehensive SQLAlchemy model schemas, enumerations, Pydantic API schemas, and analysis of discrepancies between models and schemas. - Updated performance model to clear warnings.
- Switched `models/performance_metric.py` to reuse the shared declarative base from `config.database`, clearing the SQLAlchemy 2.0 `declarative_base` deprecation warning and verifying repository tests still pass. - Replaced migration system with simpler initializer.
- Replaced the Alembic migration workflow with the idempotent Pydantic-backed initializer (`scripts/init_db.py`), added a guarded reset utility (`scripts/reset_db.py`), removed migration artifacts/tooling (Alembic directory, config, Docker entrypoint), refreshed the container entrypoint to invoke `uvicorn` directly, and updated installation/architecture docs plus the README to direct developers to the new seeding/reset flow. - Removed hardcoded secrets from tests.
- Eliminated Bandit hardcoded-secret findings by replacing literal JWT tokens and passwords across auth/security tests with randomized helpers drawn from `tests/utils/security.py`, ensuring fixtures still assert expected behaviours. - Centralized security scanning config.
- Centralized Bandit configuration in `pyproject.toml`, reran `bandit -c pyproject.toml -r calminer tests`, and verified the scan now reports zero issues. - Fixed admin setup with migration.
- Diagnosed admin bootstrap failure caused by legacy `roles` schema, added Alembic migration `20251112_00_add_roles_metadata_columns.py` to backfill `display_name`, `description`, `created_at`, and `updated_at`, and verified the migration via full pytest run in the activated `.venv`. - Resolved code style warnings.
- Resolved Ruff E402 warnings by moving module docstrings ahead of `from __future__ import annotations` across currency and pricing service modules, dropped the unused `HTTPException` import in `monitoring/__init__.py`, and confirmed a clean `ruff check .` run. - Enhanced deploy logging.
- Enhanced the deploy job in `.gitea/workflows/cicache.yml` to capture Kubernetes pod, deployment, and container logs into `/logs/deployment/` for staging/production rollouts and publish them via a `deployment-logs` artifact, updating CI/CD documentation with retrieval instructions. - Fixed CI template issue.
- Fixed CI dashboard template lookup failures by renaming `templates/Dashboard.html` to `templates/dashboard.html` and verifying `tests/test_dashboard_route.py` locally to ensure TemplateNotFound no longer occurs on case-sensitive filesystems. - Added SQLite database support.
- Implemented SQLite support as primary local database with environment-driven backend switching (`CALMINER_USE_SQLITE=true`), updated `scripts/init_db.py` for database-agnostic DDL generation (PostgreSQL enums vs SQLite CHECK constraints), tested compatibility with both backends, and verified application startup and seeded data initialization work seamlessly across SQLite and PostgreSQL.
## 2025-11-11 ## 2025-11-11
- Collapsed legacy Alembic revisions into `alembic/versions/00_initial.py`, removed superseded migration files, and verified the consolidated schema via SQLite upgrade and Postgres version stamping. - Combined old migration files into one initial schema.
- Implemented base URL routing to redirect unauthenticated users to login and authenticated users to dashboard. - Added base routing to redirect users to login or dashboard.
- Added comprehensive end-to-end tests for login flow, including redirects, session handling, and error messaging for invalid/inactive accounts. - Added end-to-end tests for login flow.
- Updated header and footer templates to consistently use `logo_big.png` image instead of text logo, with appropriate CSS styling for sizing. - Updated templates to use logo image consistently.
- Centralised ISO-4217 currency validation across scenarios, imports, and export filters (`models/scenario.py`, `routes/scenarios.py`, `schemas/scenario.py`, `schemas/imports.py`, `services/export_query.py`) so malformed codes are rejected consistently at every entry point. - Centralized currency validation across the app.
- Updated scenario services and UI flows to surface friendly validation errors and added regression coverage for imports, exports, API creation, and lifecycle flows ensuring currencies are normalised end-to-end. - Updated services to show friendly error messages.
- Linked projects to their pricing settings by updating SQLAlchemy models, repositories, seeding utilities, and migrations, and added regression tests to cover the new association and default backfill. - Linked projects to pricing settings.
- Bootstrapped database-stored pricing settings at application startup, aligned initial data seeding with the database-first metadata flow, and added tests covering pricing bootstrap creation, project assignment, and idempotency. - Bootstrapped pricing settings at startup.
- Extended pricing configuration support to prefer persisted metadata via `dependencies.get_pricing_metadata`, added retrieval tests for project/default fallbacks, and refreshed docs (`calminer-docs/specifications/price_calculation.md`, `pricing_settings_data_model.md`) to describe the database-backed workflow and bootstrap behaviour. - Extended pricing support with persisted data.
- Added `services/financial.py` NPV, IRR, and payback helpers with robust cash-flow normalisation, convergence safeguards, and fractional period support, plus comprehensive pytest coverage exercising representative project scenarios and failure modes. - Added financial helpers for NPV, IRR, payback.
- Authored `calminer-docs/specifications/financial_metrics.md` capturing DCF assumptions, solver behaviours, and worked examples, and cross-linked the architecture concepts to the new reference for consistent navigation. - Documented financial metrics.
- Implemented `services/simulation.py` Monte Carlo engine with configurable distributions, summary aggregation, and reproducible RNG seeding, introduced regression tests in `tests/test_simulation.py`, and documented configuration/usage in `calminer-docs/specifications/monte_carlo_simulation.md` with architecture cross-links. - Implemented Monte Carlo simulation engine.
- Polished reporting HTML contexts by cleaning stray fragments in `routes/reports.py`, adding download action metadata for project and scenario pages, and generating scenario comparison download URLs with correctly serialised repeated `scenario_ids` parameters. - Cleaned up reporting contexts.
- Consolidated Alembic history into a single initial migration (`20251111_00_initial_schema.py`), removed superseded revision files, and ensured Alembic metadata still references the project metadata for clean bootstrap. - Consolidated migration history.
- Added `scripts/run_migrations.py` and a Docker entrypoint wrapper to run Alembic migrations before `uvicorn` starts, removed the fallback `Base.metadata.create_all` call, and updated `calminer-docs/admin/installation.md` so developers know how to apply migrations locally or via Docker. - Added migration script and updated entrypoint.
- Configured pytest defaults to collect coverage (`--cov`) with an 80% fail-under gate, excluded entrypoint/reporting scaffolds from the calculation, updated contributor docs with the standard `pytest` command, and verified the suite now reports 83% coverage. - Configured test coverage.
- Standardized color scheme and typography by moving alert styles to `main.css`, adding typography rules with CSS variables, updating auth templates for consistent button classes, and ensuring all templates use centralized color and spacing variables. - Standardized colors and typography.
- Improved navigation flow by adding two big chevron buttons on top of the navigation sidebar to allow users to navigate to the previous and next page in the page navigation list, including JavaScript logic for determining current page and handling navigation. - Improved navigation with chevron buttons.
- Established pytest-based unit and integration test suites with coverage thresholds, achieving 83% coverage across 181 tests, with configuration in pyproject.toml and documentation in CONTRIBUTING.md. - Established test suites with coverage.
- Configured CI pipelines to run tests, linting, and security checks on each change, adding Bandit security scanning to the workflow and verifying execution on pushes and PRs to main/develop branches. - Configured CI pipelines for tests and security.
- Added deployment automation with Docker Compose for local development and Kubernetes manifests for production, ensuring environment parity and documenting processes in calminer-docs/admin/installation.md. - Added deployment automation with Docker and Kubernetes.
- Completed monitoring instrumentation by adding business metrics observation to project and scenario repository operations, and simulation performance tracking to Monte Carlo service with success/error status and duration metrics. - Completed monitoring instrumentation.
- Updated TODO list to reflect completed monitoring implementation tasks and validated changes with passing simulation tests. - Implemented performance monitoring.
- Implemented comprehensive performance monitoring for scalability (FR-006) with Prometheus metrics collection for HTTP requests, import/export operations, and general application metrics. - Added metric storage and endpoints.
- Added database model for persistent metric storage with aggregation endpoints for KPIs like request latency, error rates, and throughput. - Created middleware for metrics.
- Created FastAPI middleware for automatic request metric collection and background persistence to database. - Extended monitoring router.
- Extended monitoring router with performance metrics API endpoints and detailed health checks. - Added migration for metrics table.
- Added Alembic migration for performance_metrics table and updated model imports. - Completed concurrent testing.
- Completed concurrent interaction testing implementation, validating database transaction isolation under threading and establishing async testing framework for future concurrency enhancements. - Implemented deployment automation.
- Implemented comprehensive deployment automation with Docker Compose configurations for development, staging, and production environments ensuring environment parity. - Set up Kubernetes manifests.
- Set up Kubernetes manifests with resource limits, health checks, and secrets management for production deployment. - Configured CI/CD workflows.
- Configured CI/CD workflows for automated Docker image building, registry pushing, and Kubernetes deployment to staging/production environments. - Documented deployment processes.
- Documented deployment processes, environment configurations, and CI/CD workflows in project documentation. - Validated deployment setup.
- Validated deployment automation through Docker Compose configuration testing and CI/CD pipeline structure.
## 2025-11-10 ## 2025-11-10
- Added dedicated pytest coverage for guard dependencies, exercising success plus failure paths (missing session, inactive user, missing roles, project/scenario access errors) via `tests/test_dependencies_guards.py`. - Added tests for guard dependencies.
- Added integration tests in `tests/test_authorization_integration.py` verifying anonymous 401 responses, role-based 403s, and authorized project manager flows across API and UI endpoints. - Added integration tests for authorization.
- Implemented environment-driven admin bootstrap settings, wired the `bootstrap_admin` helper into FastAPI startup, added pytest coverage for creation/idempotency/reset logic, and documented operational guidance in the RBAC plan and security concept. - Implemented admin bootstrap settings.
- Retired the legacy authentication RBAC implementation plan document after migrating its guidance into live documentation and synchronized the contributor instructions to reflect the removal. - Retired old RBAC plan document.
- Completed the Authentication & RBAC checklist by shipping the new models, migrations, repositories, guard dependencies, and integration tests. - Completed authentication and RBAC features.
- Documented the project/scenario import/export field mapping and file format guidelines in `calminer-docs/requirements/FR-008.md`, and introduced `schemas/imports.py` with Pydantic models that normalise incoming CSV/Excel rows for projects and scenarios. - Documented import/export field mappings.
- Added `services/importers.py` to load CSV/XLSX files into the new import schemas, pulled in `openpyxl` for Excel support, and covered the parsing behaviour with `tests/test_import_parsing.py`. - Added import service for CSV/Excel.
- Expanded the import ingestion workflow with staging previews, transactional persistence commits, FastAPI preview/commit endpoints under `/imports`, and new API tests (`tests/test_import_ingestion.py`, `tests/test_import_api.py`) ensuring end-to-end coverage. - Expanded import workflow with previews and commits.
- Added persistent audit logging via `ImportExportLog`, structured log emission, Prometheus metrics instrumentation, `/metrics` endpoint exposure, and updated operator/deployment documentation to guide monitoring setup. - Added audit logging for imports/exports.
## 2025-11-09 ## 2025-11-09
- Captured current implementation status, requirements coverage, missing features, and prioritized roadmap in `calminer-docs/implementation_status.md` to guide future development. - Captured implementation status and roadmap.
- Added core SQLAlchemy domain models, shared metadata descriptors, and Alembic migration setup (with initial schema snapshot) to establish the persistence layer foundation. - Added core database models and migration setup.
- Introduced repository and unit-of-work helpers for projects, scenarios, financial inputs, and simulation parameters to support service-layer operations. - Introduced repository helpers for data operations.
- Added SQLite-backed pytest coverage for repository and unit-of-work behaviours to validate persistence interactions. - Added tests for repository behaviors.
- Exposed project and scenario CRUD APIs with validated schemas and integrated them into the FastAPI application. - Exposed CRUD APIs for projects and scenarios.
- Connected project and scenario routers to new Jinja2 list/detail/edit views with HTML forms and redirects. - Connected routers to HTML views.
- Implemented FR-009 client-side enhancements with responsive navigation toggle, mobile-first scenario tables, and shared asset loading across templates. - Implemented client-side enhancements.
- Added scenario comparison validator, FastAPI comparison endpoint, and comprehensive unit tests to enforce FR-009 validation rules through API errors. - Added scenario comparison validator.
- Delivered a new dashboard experience with `templates/dashboard.html`, dedicated styling, and a FastAPI route supplying real project/scenario metrics via repository helpers. - Delivered new dashboard experience.
- Extended repositories with count/recency utilities and added pytest coverage, including a dashboard rendering smoke test validating empty-state messaging. - Extended repositories with utilities.
- Brought project and scenario detail pages plus their forms in line with the dashboard visuals, adding metric cards, layout grids, and refreshed CTA styles. - Updated detail pages with new visuals.
- Reordered project route registration to prioritize static UI paths, eliminating 422 errors on `/projects/ui` and `/projects/create`, and added pytest smoke coverage for the navigation endpoints. - Fixed route registration issues.
- Added end-to-end integration tests for project and scenario lifecycles, validating HTML redirects, template rendering, and API interactions, and updated `ProjectRepository.get` to deduplicate joined loads for detail views. - Added end-to-end tests for lifecycles.
- Updated all Jinja2 template responses to the new Starlette signature to eliminate deprecation warnings while keeping request-aware context available to the templates. - Updated template responses.
- Introduced `services/security.py` to centralize Argon2 password hashing utilities and JWT creation/verification with typed payloads, and added pytest coverage for hashing, expiry, tampering, and token type mismatch scenarios. - Introduced security utilities.
- Added `routes/auth.py` with registration, login, and password reset flows, refreshed auth templates with error messaging, wired navigation links, and introduced end-to-end pytest coverage for the new forms and token flows. - Added authentication routes.
- Implemented cookie-based authentication session middleware with automatic access token refresh, logout handling, navigation adjustments, and documentation/test updates capturing the new behaviour. - Implemented session middleware.
- Delivered idempotent seeding utilities with `scripts/initial_data.py`, entry-point runner `scripts/00_initial_data.py`, documentation updates, and pytest coverage to verify role/admin provisioning. - Delivered seeding utilities.
- Secured project and scenario routers with RBAC guard dependencies, enforced repository access checks via helper utilities, and aligned template routes with FastAPI dependency injection patterns. - Secured routers with RBAC.

View File

@@ -1,5 +1,3 @@
version: "3.8"
services: services:
app: app:
build: build:

2
run_docker.ps1 Normal file
View File

@@ -0,0 +1,2 @@
docker run -d --name calminer-app --env-file .env -p 8003:8003 -v "${PWD}\logs:/app/logs" --restart unless-stopped calminer:latest
docker logs -f calminer-app

View File

@@ -1,53 +0,0 @@
// Navigation chevron buttons logic
document.addEventListener("DOMContentLoaded", function () {
const navPrev = document.getElementById("nav-prev");
const navNext = document.getElementById("nav-next");
if (!navPrev || !navNext) return;
// Define the navigation order (main pages)
const navPages = [
window.NAVIGATION_URLS.dashboard,
window.NAVIGATION_URLS.projects,
window.NAVIGATION_URLS.imports,
window.NAVIGATION_URLS.simulations,
window.NAVIGATION_URLS.reporting,
window.NAVIGATION_URLS.settings,
];
const currentPath = window.location.pathname;
// Find current index
let currentIndex = -1;
for (let i = 0; i < navPages.length; i++) {
if (currentPath.startsWith(navPages[i])) {
currentIndex = i;
break;
}
}
// If not found, disable both
if (currentIndex === -1) {
navPrev.disabled = true;
navNext.disabled = true;
return;
}
// Set up prev button
if (currentIndex > 0) {
navPrev.addEventListener("click", function () {
window.location.href = navPages[currentIndex - 1];
});
} else {
navPrev.disabled = true;
}
// Set up next button
if (currentIndex < navPages.length - 1) {
navNext.addEventListener("click", function () {
window.location.href = navPages[currentIndex + 1];
});
} else {
navNext.disabled = true;
}
});

View File

@@ -3,6 +3,148 @@
const SIDEBAR_SELECTOR = ".sidebar-nav"; const SIDEBAR_SELECTOR = ".sidebar-nav";
const DATA_SOURCE_ATTR = "navigationSource"; const DATA_SOURCE_ATTR = "navigationSource";
const ROLE_ATTR = "navigationRoles"; const ROLE_ATTR = "navigationRoles";
const NAV_PREV_ID = "nav-prev";
const NAV_NEXT_ID = "nav-next";
const CACHE_KEY = "calminer:navigation:sidebar";
const CACHE_VERSION = 1;
const CACHE_TTL_MS = 2 * 60 * 1000;
function hasStorage() {
try {
return typeof window.localStorage !== "undefined";
} catch (error) {
return false;
}
}
function loadCacheRoot() {
if (!hasStorage()) {
return null;
}
let raw;
try {
raw = window.localStorage.getItem(CACHE_KEY);
} catch (error) {
return null;
}
if (!raw) {
return { version: CACHE_VERSION, entries: {} };
}
try {
const parsed = JSON.parse(raw);
if (
!parsed ||
typeof parsed !== "object" ||
parsed.version !== CACHE_VERSION ||
typeof parsed.entries !== "object"
) {
return { version: CACHE_VERSION, entries: {} };
}
return parsed;
} catch (error) {
clearCache();
return { version: CACHE_VERSION, entries: {} };
}
}
function persistCache(root) {
if (!hasStorage()) {
return;
}
try {
window.localStorage.setItem(CACHE_KEY, JSON.stringify(root));
} catch (error) {
/* ignore storage write failures */
}
}
function clearCache() {
if (!hasStorage()) {
return;
}
try {
window.localStorage.removeItem(CACHE_KEY);
} catch (error) {
/* ignore */
}
}
function normaliseRoles(roles) {
if (!Array.isArray(roles)) {
return [];
}
const seen = new Set();
const cleaned = [];
for (const value of roles) {
const role = typeof value === "string" ? value.trim() : "";
if (!role || seen.has(role)) {
continue;
}
seen.add(role);
cleaned.push(role);
}
cleaned.sort();
return cleaned;
}
function serialiseRoles(roles) {
const cleaned = normaliseRoles(roles);
if (cleaned.length === 0) {
return "anonymous";
}
return cleaned.join("|");
}
function getCurrentRoles(navContainer) {
const attr = navContainer.dataset[ROLE_ATTR];
if (!attr) {
return null;
}
const roles = attr
.split(",")
.map((role) => role.trim())
.filter(Boolean);
if (roles.length === 0) {
return null;
}
return roles;
}
function readCache(rolesKey) {
if (!rolesKey) {
return null;
}
const root = loadCacheRoot();
if (!root || !root.entries || typeof root.entries !== "object") {
return null;
}
const entry = root.entries[rolesKey];
if (!entry || !entry.payload) {
return null;
}
const cachedAt = typeof entry.cachedAt === "number" ? entry.cachedAt : 0;
const expired = Date.now() - cachedAt > CACHE_TTL_MS;
return { payload: entry.payload, expired };
}
function saveCache(rolesKey, payload) {
if (!rolesKey || !payload) {
return;
}
const root = loadCacheRoot();
if (!root) {
return;
}
if (!root.entries || typeof root.entries !== "object") {
root.entries = {};
}
root.entries[rolesKey] = {
cachedAt: Date.now(),
payload,
};
root.version = CACHE_VERSION;
persistCache(root);
}
function onReady(callback) { function onReady(callback) {
if (document.readyState === "loading") { if (document.readyState === "loading") {
@@ -160,6 +302,102 @@
return section; return section;
} }
function resolvePath(input) {
if (!input) {
return null;
}
try {
return new URL(input, window.location.origin).pathname;
} catch (error) {
if (input.startsWith("/")) {
return input;
}
return `/${input}`;
}
}
function flattenNavigation(groups) {
const sequence = [];
for (const group of groups) {
if (!group || !Array.isArray(group.links)) {
continue;
}
for (const link of group.links) {
if (!link || !link.href) {
continue;
}
const isExternal = Boolean(link.is_external ?? link.isExternal);
if (!isExternal) {
sequence.push({
href: link.href,
matchPrefix: link.match_prefix || link.matchPrefix || link.href,
});
}
const children = Array.isArray(link.children) ? link.children : [];
for (const child of children) {
if (!child || !child.href) {
continue;
}
const childExternal = Boolean(child.is_external ?? child.isExternal);
if (childExternal) {
continue;
}
sequence.push({
href: child.href,
matchPrefix: child.match_prefix || child.matchPrefix || child.href,
});
}
}
}
return sequence;
}
function configureChevronButtons(sequence) {
const prevButton = document.getElementById(NAV_PREV_ID);
const nextButton = document.getElementById(NAV_NEXT_ID);
if (!prevButton || !nextButton) {
return;
}
const pathname = window.location.pathname;
const normalised = sequence
.map((item) => ({
href: item.href,
matchPrefix: item.matchPrefix,
path: resolvePath(item.matchPrefix || item.href),
}))
.filter((item) => Boolean(item.path));
const currentIndex = normalised.findIndex((item) =>
isActivePath(pathname, item.matchPrefix || item.path)
);
prevButton.disabled = true;
prevButton.onclick = null;
nextButton.disabled = true;
nextButton.onclick = null;
if (currentIndex === -1) {
return;
}
if (currentIndex > 0) {
const target = normalised[currentIndex - 1].href;
prevButton.disabled = false;
prevButton.onclick = () => {
window.location.href = target;
};
}
if (currentIndex < normalised.length - 1) {
const target = normalised[currentIndex + 1].href;
nextButton.disabled = false;
nextButton.onclick = () => {
window.location.href = target;
};
}
}
function renderSidebar(navContainer, payload) { function renderSidebar(navContainer, payload) {
const pathname = window.location.pathname; const pathname = window.location.pathname;
const groups = Array.isArray(payload?.groups) ? payload.groups : []; const groups = Array.isArray(payload?.groups) ? payload.groups : [];
@@ -177,6 +415,7 @@
navContainer.appendChild(buildEmptyState()); navContainer.appendChild(buildEmptyState());
navContainer.dataset[DATA_SOURCE_ATTR] = "client-empty"; navContainer.dataset[DATA_SOURCE_ATTR] = "client-empty";
delete navContainer.dataset[ROLE_ATTR]; delete navContainer.dataset[ROLE_ATTR];
configureChevronButtons([]);
return; return;
} }
@@ -191,9 +430,22 @@
} else { } else {
delete navContainer.dataset[ROLE_ATTR]; delete navContainer.dataset[ROLE_ATTR];
} }
configureChevronButtons(flattenNavigation(groups));
} }
async function hydrateSidebar(navContainer) { async function hydrateSidebar(navContainer) {
const roles = getCurrentRoles(navContainer);
const rolesKey = roles ? serialiseRoles(roles) : null;
const cached = readCache(rolesKey);
if (cached && cached.payload) {
renderSidebar(navContainer, cached.payload);
if (!cached.expired) {
return;
}
}
try { try {
const response = await fetch(NAV_ENDPOINT, { const response = await fetch(NAV_ENDPOINT, {
method: "GET", method: "GET",
@@ -204,6 +456,9 @@
}); });
if (!response.ok) { if (!response.ok) {
if (!cached || !cached.payload) {
configureChevronButtons([]);
}
if (response.status !== 401 && response.status !== 403) { if (response.status !== 401 && response.status !== 403) {
console.warn( console.warn(
"Navigation sidebar hydration failed with status", "Navigation sidebar hydration failed with status",
@@ -215,14 +470,22 @@
const payload = await response.json(); const payload = await response.json();
renderSidebar(navContainer, payload); renderSidebar(navContainer, payload);
const payloadRoles = Array.isArray(payload?.roles)
? payload.roles
: roles || [];
saveCache(serialiseRoles(payloadRoles), payload);
} catch (error) { } catch (error) {
console.warn("Navigation sidebar hydration failed", error); console.warn("Navigation sidebar hydration failed", error);
if (!cached || !cached.payload) {
configureChevronButtons([]);
}
} }
} }
onReady(() => { onReady(() => {
const navContainer = document.querySelector(SIDEBAR_SELECTOR); const navContainer = document.querySelector(SIDEBAR_SELECTOR);
if (!navContainer) { if (!navContainer) {
configureChevronButtons([]);
return; return;
} }
hydrateSidebar(navContainer); hydrateSidebar(navContainer);

View File

@@ -44,7 +44,6 @@
<script src="/static/js/imports.js" defer></script> <script src="/static/js/imports.js" defer></script>
<script src="/static/js/notifications.js" defer></script> <script src="/static/js/notifications.js" defer></script>
<script src="/static/js/navigation_sidebar.js" defer></script> <script src="/static/js/navigation_sidebar.js" defer></script>
<script src="/static/js/navigation.js" defer></script>
<script src="/static/js/theme.js"></script> <script src="/static/js/theme.js"></script>
</body> </body>
</html> </html>

View File

@@ -1,5 +1,4 @@
{% extends "base.html" %} {% block title %}Dashboard · CalMiner{% endblock %} {% {% extends "base.html" %} {% block title %}Dashboard · CalMiner{% endblock %} {% block head_extra %}
block head_extra %}
<link rel="stylesheet" href="/static/css/dashboard.css" /> <link rel="stylesheet" href="/static/css/dashboard.css" />
{% endblock %} {% block content %} {% endblock %} {% block content %}
<section class="page-header dashboard-header"> <section class="page-header dashboard-header">
@@ -165,12 +164,12 @@ block head_extra %}
</header> </header>
<ul class="links-list"> <ul class="links-list">
<li> <li>
<a href="https://github.com/" target="_blank">CalMiner Repository</a> <a href="https://git.allucanget.biz/allucanget/calminer" target="_blank">CalMiner Repository</a>
</li> </li>
<li> <li>
<a href="https://example.com/docs" target="_blank">Documentation</a> <a href="https://git.allucanget.biz/allucanget/calminer-docs" target="_blank">Documentation</a>
</li> </li>
<li><a href="mailto:support@example.com">Contact Support</a></li> <li><a href="mailto:calminer@allucanget.biz">Contact Support</a></li>
</ul> </ul>
</div> </div>
</aside> </aside>

View File

@@ -1,4 +1,5 @@
{% set sidebar_nav = get_sidebar_navigation(request) %} {% set sidebar_nav = get_sidebar_navigation(request) %}
{% set nav_roles = sidebar_nav.roles if sidebar_nav and sidebar_nav.roles else [] %}
{% set nav_groups = sidebar_nav.groups if sidebar_nav else [] %} {% set nav_groups = sidebar_nav.groups if sidebar_nav else [] %}
{% set current_path = request.url.path if request else '' %} {% set current_path = request.url.path if request else '' %}
@@ -6,6 +7,7 @@
class="sidebar-nav" class="sidebar-nav"
aria-label="Primary navigation" aria-label="Primary navigation"
data-navigation-source="{{ 'server' if sidebar_nav else 'fallback' }}" data-navigation-source="{{ 'server' if sidebar_nav else 'fallback' }}"
data-navigation-roles="{{ nav_roles | join(',') }}"
> >
<div class="sidebar-nav-controls"> <div class="sidebar-nav-controls">
<button id="nav-prev" class="nav-chevron nav-chevron-prev" aria-label="Previous page"></button> <button id="nav-prev" class="nav-chevron nav-chevron-prev" aria-label="Previous page"></button>