diff --git a/.gitea/workflows/continuous_integration.yaml b/.gitea/workflows/continuous_integration.yaml index d12b106..def921b 100644 --- a/.gitea/workflows/continuous_integration.yaml +++ b/.gitea/workflows/continuous_integration.yaml @@ -3,12 +3,12 @@ name: Continuous Integration on: workflow_dispatch: inputs: - deploy_test: - description: 'Deploy to Test' + deploy_sls_test: + description: 'Deploy SLS test (SlpSoftware)' type: boolean default: false - deploy_production: - description: 'Deploy to Production' + deploy_sls_production: + description: 'Deploy SLS production (SlpSoftware)' type: boolean default: false deploy_asf_test: @@ -22,7 +22,7 @@ on: # A new push to the same PR does not cancel an already-running CI attempt by default (each # `synchronize` event starts an independent run) — this opts in to cancelling the superseded one, -# but ONLY for pull_request events. `deploy-test`/`deploy-production` never run on a pull_request +# but ONLY for pull_request events. `deploy-sls-test`/`deploy-sls-production` never run on a pull_request # (they require a push to master or a workflow_dispatch, see those jobs' `if:` conditions), so # scoping cancel-in-progress to pull_request here can never abort a live deploy mid-flight. concurrency: @@ -31,17 +31,17 @@ concurrency: # Reusable settings for this workflow. Change these in one place if the .NET/Node/pnpm version, # artifact names, or deploy destinations change. The env context is NOT available inside a called -# reusable workflow's `with:` inputs (see the `config` job below, which works around this by passing -# these values through as job outputs to the `deploy-test` / `deploy-production` jobs). +# reusable workflow's `with:` inputs (see the `config-sls` job below, which works around this by passing +# these values through as job outputs to the `deploy-sls-test` / `deploy-sls-production` jobs). env: DOTNET_VERSION: '10.0.x' NODE_VERSION: '20' PNPM_VERSION: '9' PUBLISH_RID: linux-arm64 - ARTIFACT_NAME_TEST: app-test - ARTIFACT_NAME_PRODUCTION: app-production - DEPLOY_ENVIRONMENT_TEST: test - DEPLOY_ENVIRONMENT_PRODUCTION: production + ARTIFACT_NAME_SLS_TEST: app-sls-test + ARTIFACT_NAME_SLS_PRODUCTION: app-sls-production + DEPLOY_ENVIRONMENT_SLS_TEST: test + DEPLOY_ENVIRONMENT_SLS_PRODUCTION: production DEPLOY_PATH_TEST: ${{ vars.DEPLOY_PATH_TEST }} DEPLOY_PATH_PRODUCTION: ${{ vars.DEPLOY_PATH_PRODUCTION }} SERVICE_NAME_TEST: ${{ vars.SERVICE_NAME_TEST }} @@ -51,40 +51,56 @@ env: jobs: # Passes the env: values above through as job outputs, since the env context is unavailable in - # the `with:` block of a job that calls a reusable workflow (see deploy-test / deploy-production). - config: - runs-on: ubuntu-latest + # the `with:` block of a job that calls a reusable workflow (see deploy-sls-test / deploy-sls-production). + config-sls: + runs-on: linux outputs: - artifact_name_test: ${{ steps.set.outputs.artifact_name_test }} - artifact_name_production: ${{ steps.set.outputs.artifact_name_production }} - deploy_environment_test: ${{ steps.set.outputs.deploy_environment_test }} - deploy_environment_production: ${{ steps.set.outputs.deploy_environment_production }} - deploy_path_test: ${{ steps.set.outputs.deploy_path_test }} - deploy_path_production: ${{ steps.set.outputs.deploy_path_production }} - service_name_test: ${{ steps.set.outputs.service_name_test }} - service_name_production: ${{ steps.set.outputs.service_name_production }} - health_check_url_test: ${{ steps.set.outputs.health_check_url_test }} - health_check_url_production: ${{ steps.set.outputs.health_check_url_production }} + artifact_name_sls_test: ${{ steps.set.outputs.artifact_name_sls_test }} + artifact_name_sls_production: ${{ steps.set.outputs.artifact_name_sls_production }} + deploy_environment_sls_test: ${{ steps.set.outputs.deploy_environment_sls_test }} + deploy_environment_sls_production: ${{ steps.set.outputs.deploy_environment_sls_production }} + deploy_path_sls_test: ${{ steps.set.outputs.deploy_path_sls_test }} + deploy_path_sls_production: ${{ steps.set.outputs.deploy_path_sls_production }} + service_name_sls_test: ${{ steps.set.outputs.service_name_sls_test }} + service_name_sls_production: ${{ steps.set.outputs.service_name_sls_production }} + health_check_url_sls_test: ${{ steps.set.outputs.health_check_url_sls_test }} + health_check_url_sls_production: ${{ steps.set.outputs.health_check_url_sls_production }} steps: # Gitea has no reliable way to see a past run's workflow_dispatch input values from the UI, so # this logs them explicitly — the only durable record of what was actually checked for a run. - name: Log dispatch inputs if: github.event_name == 'workflow_dispatch' run: | - echo "Deploy to Test: ${{ github.event.inputs.deploy_test }}" - echo "Deploy to Production: ${{ github.event.inputs.deploy_production }}" + echo "Deploy SLS test: ${{ github.event.inputs.deploy_sls_test }}" + echo "Deploy SLS production: ${{ github.event.inputs.deploy_sls_production }}" + # The Gitea variables are read at STEP level (like config-asf), not through the workflow-level env block: on the PC + # runner the workflow-level `${{ vars.* }}` values came through empty (deploy path "" -> mkdir /releases), while + # step-level env works on both runners. The test trio must be set, otherwise fail here instead of in the deploy. - id: set + env: + DEPLOY_PATH_TEST: ${{ vars.DEPLOY_PATH_TEST }} + DEPLOY_PATH_PRODUCTION: ${{ vars.DEPLOY_PATH_PRODUCTION }} + SERVICE_NAME_TEST: ${{ vars.SERVICE_NAME_TEST }} + SERVICE_NAME_PRODUCTION: ${{ vars.SERVICE_NAME_PRODUCTION }} + HEALTH_CHECK_URL_TEST: ${{ vars.HEALTH_CHECK_URL_TEST }} + HEALTH_CHECK_URL_PRODUCTION: ${{ vars.HEALTH_CHECK_URL_PRODUCTION }} run: | - echo "artifact_name_test=${{ env.ARTIFACT_NAME_TEST }}" >> "$GITHUB_OUTPUT" - echo "artifact_name_production=${{ env.ARTIFACT_NAME_PRODUCTION }}" >> "$GITHUB_OUTPUT" - echo "deploy_environment_test=${{ env.DEPLOY_ENVIRONMENT_TEST }}" >> "$GITHUB_OUTPUT" - echo "deploy_environment_production=${{ env.DEPLOY_ENVIRONMENT_PRODUCTION }}" >> "$GITHUB_OUTPUT" - echo "deploy_path_test=${{ env.DEPLOY_PATH_TEST }}" >> "$GITHUB_OUTPUT" - echo "deploy_path_production=${{ env.DEPLOY_PATH_PRODUCTION }}" >> "$GITHUB_OUTPUT" - echo "service_name_test=${{ env.SERVICE_NAME_TEST }}" >> "$GITHUB_OUTPUT" - echo "service_name_production=${{ env.SERVICE_NAME_PRODUCTION }}" >> "$GITHUB_OUTPUT" - echo "health_check_url_test=${{ env.HEALTH_CHECK_URL_TEST }}" >> "$GITHUB_OUTPUT" - echo "health_check_url_production=${{ env.HEALTH_CHECK_URL_PRODUCTION }}" >> "$GITHUB_OUTPUT" + for v in DEPLOY_PATH_TEST SERVICE_NAME_TEST HEALTH_CHECK_URL_TEST; do + if [ -z "${!v}" ]; then + echo "The Gitea variable $v is empty or not set on this runner; the deploy would use an empty path." + exit 1 + fi + done + echo "artifact_name_sls_test=${{ env.ARTIFACT_NAME_SLS_TEST }}" >> "$GITHUB_OUTPUT" + echo "artifact_name_sls_production=${{ env.ARTIFACT_NAME_SLS_PRODUCTION }}" >> "$GITHUB_OUTPUT" + echo "deploy_environment_sls_test=${{ env.DEPLOY_ENVIRONMENT_SLS_TEST }}" >> "$GITHUB_OUTPUT" + echo "deploy_environment_sls_production=${{ env.DEPLOY_ENVIRONMENT_SLS_PRODUCTION }}" >> "$GITHUB_OUTPUT" + echo "deploy_path_sls_test=$DEPLOY_PATH_TEST" >> "$GITHUB_OUTPUT" + echo "deploy_path_sls_production=$DEPLOY_PATH_PRODUCTION" >> "$GITHUB_OUTPUT" + echo "service_name_sls_test=$SERVICE_NAME_TEST" >> "$GITHUB_OUTPUT" + echo "service_name_sls_production=$SERVICE_NAME_PRODUCTION" >> "$GITHUB_OUTPUT" + echo "health_check_url_sls_test=$HEALTH_CHECK_URL_TEST" >> "$GITHUB_OUTPUT" + echo "health_check_url_sls_production=$HEALTH_CHECK_URL_PRODUCTION" >> "$GITHUB_OUTPUT" # Path-based skip: keeps the pipeline short when a change only touches one side of the repo. # fetch-depth: 0 gives paths-filter full local git history to diff against, rather than relying @@ -94,7 +110,7 @@ jobs: # workflow_dispatch run has no `before` commit to diff against and is always an explicit request # to run everything, so it force-reports both sides as changed rather than trusting the filter. changes: - runs-on: ubuntu-latest + runs-on: linux outputs: backend: ${{ github.event_name == 'workflow_dispatch' || steps.filter.outputs.backend == 'true' }} frontend: ${{ github.event_name == 'workflow_dispatch' || steps.filter.outputs.frontend == 'true' }} @@ -118,6 +134,7 @@ jobs: - 'src/**' - 'tests/**' - '*.sln' + - '*.slnf' - '**/*.csproj' frontend: - *workflow @@ -127,20 +144,44 @@ jobs: backend-build: needs: changes if: needs.changes.outputs.backend == 'true' - runs-on: ubuntu-latest + runs-on: linux steps: - uses: actions/checkout@v4 - uses: actions/setup-dotnet@v4 with: dotnet-version: ${{ env.DOTNET_VERSION }} + # The CI builds and tests the master CMS only (SlpModularCms.Api with every module, Core and all test + # projects), listed in SlpModularCms.Ci.slnf. The site projects (Api.SlpSoftware, Api.AndreaSlopFotografie, + # Api.Slave) are thin compositions: they are compiled by compile-sites below and built/published only when a + # deploy needs them. Their behaviour is covered by the tests on the master host (see SiteContractTests). - name: Restore and build (Release) - run: dotnet build SlpModularCms.sln -c Release + run: dotnet build SlpModularCms.Ci.slnf -c Release + + # --- Not required: the thin site projects still compile --- + # Compile only (no tests, a few seconds): catches a broken reference or a renamed type in a site project on the + # pull request instead of at deploy time. Deliberately not a required check; the smoke tests after the test + # deploys catch composition errors that compile fine. + compile-sites: + needs: changes + if: needs.changes.outputs.backend == 'true' + runs-on: linux + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-dotnet@v4 + with: + dotnet-version: ${{ env.DOTNET_VERSION }} + - name: Compile the site projects (Release) + run: | + for project in SlpSoftware AndreaSlopFotografie Slave; do + echo "== SlpModularCms.Api.$project" + dotnet build "src/SlpModularCms.Api.$project/SlpModularCms.Api.$project.csproj" -c Release + done # --- Gate 2: backend tests --- backend-test: needs: [changes, backend-build] if: needs.changes.outputs.backend == 'true' - runs-on: ubuntu-latest + runs-on: linux # Added for SlpModularCms.Api.Tests (slpsoftware-api feature, NFR-CS-01): its pipeline # regression tests boot the real Api host via WebApplicationFactory, which unconditionally # runs CmsHost.ConfigurePipeline's startup migration (MigrateCoreDatabase) -- unlike every @@ -148,56 +189,54 @@ jobs: # database. Without a real, reachable MariaDB, those tests fail on the connection itself # before any assertion runs. # - # A `services:` block was tried first and rejected: this runner uses host networking for - # job AND service containers ("--network and --net in the options will be ignored" in the - # job log), so the `ports:` mapping was silently ignored, and the mariadb:11 service ended - # up sharing the host's network namespace directly on port 3306 -- which something else on - # this runner already answers on (root auth was rejected by a server that was clearly NOT - # the freshly-initialized container: "Access denied ... using password: YES" against a - # password nothing but this job ever set). An explicitly `docker run` container below, - # published on host port 3307 instead of 3306, avoids that collision entirely. + # The database is a job-level `services:` container, so the job needs no container-engine socket (the PC + # runner has no /var/run/docker.sock in its job containers; a manual `docker run` failed there). The server + # listens on 3308 (MYSQL_TCP_PORT) instead of 3306: on the Pi runner job and service containers share the + # host's network namespace (host networking), where the host's own database already answers on 3306 -- the + # reason the first `services:` attempt there failed. On a runner with a separate job network the service is + # reached by its name `mariadb`; with host networking it is reached on 127.0.0.1 (resolved in the test step). + services: + mariadb: + image: mariadb:11 + env: + MARIADB_ROOT_PASSWORD: ci_test_password + MARIADB_DATABASE: SlpModularCms + MYSQL_TCP_PORT: '3308' + options: >- + --health-cmd="mariadb-admin ping -uroot -pci_test_password --silent" + --health-interval=3s --health-timeout=3s --health-retries=40 steps: - uses: actions/checkout@v4 - uses: actions/setup-dotnet@v4 with: dotnet-version: ${{ env.DOTNET_VERSION }} - - name: Start MariaDB for SlpModularCms.Api.Tests + - name: Test (Release) + shell: bash + # ConnectionStrings__DefaultConnection overrides the placeholder in appsettings.Development.json for this CI + # run only (environment variables are applied after appsettings.*.json), so it reaches + # SlpModularCms.Api.Tests' WebApplicationFactory without touching a committed appsettings file. run: | - docker run -d --name ci-mariadb \ - -e MARIADB_ROOT_PASSWORD=ci_test_password \ - -e MARIADB_DATABASE=SlpModularCms \ - -p 3307:3306 \ - mariadb:11 - for i in $(seq 1 30); do - # mariadb:11 does not provide a `mysqladmin` alias -- verified locally against this - # exact image; the correct binary here is `mariadb-admin`. - if docker exec ci-mariadb mariadb-admin ping -uroot -pci_test_password --silent 2>/dev/null; then - echo "MariaDB is ready." - break - fi - echo "Waiting for MariaDB... ($i/30)" + HOST=127.0.0.1 + if getent hosts mariadb >/dev/null 2>&1; then HOST=mariadb; fi + echo "Waiting for MariaDB on $HOST:3308" + for i in $(seq 1 60); do + if (echo > "/dev/tcp/$HOST/3308") 2>/dev/null; then echo "MariaDB is accepting connections."; break; fi sleep 2 done - - name: Test (Release) - env: - # Overrides the placeholder in SlpModularCms.Api/appsettings.Development.json for this - # CI run only -- ASP.NET Core's configuration layering applies environment variables - # after appsettings.*.json, so this reaches SlpModularCms.Api.Tests' WebApplicationFactory - # without touching any committed appsettings file. Port 3307, not 3306 -- see above. - ConnectionStrings__DefaultConnection: "Server=127.0.0.1;Port=3307;Database=SlpModularCms;Uid=root;Pwd=ci_test_password" - run: dotnet test SlpModularCms.sln -c Release - - name: Stop MariaDB for SlpModularCms.Api.Tests - if: always() - run: docker rm -f ci-mariadb || true + export ConnectionStrings__DefaultConnection="Server=$HOST;Port=3308;Database=SlpModularCms;Uid=root;Pwd=ci_test_password" + dotnet test SlpModularCms.Ci.slnf -c Release # --- Gate 3: vulnerability scan --- # `dotnet list package --vulnerable` always exits 0, even when it reports vulnerabilities, so the # step greps its own output and fails deliberately (FR-22, D-12, OPEN-03 — closed by pinning # Microsoft.OpenApi and System.Security.Cryptography.Xml in the relevant .csproj files). - # Runner labels: `ubuntu-latest` exists only on the Pi (linux-arm64). The independent jobs below (vulnerability-scan, - # frontend-*) use `linux`, which the Pi and the desktop runner (x64) both carry, so they can run in parallel. They need no - # arm64 artefact and each does its own `pnpm install`. NOT moved: backend-test (docker mariadb), publish-* (linux-arm64 - # artefacts for the Pi) and deploy-* (reusable deploy workflow). + # Runner labels: a job runs on a runner that has ALL of its runs-on labels. + # Pi runner: linux-arm64, ubuntu-latest, global, linux, arm64, podman, raspberry-pi + # PC runner: global, linux, x64, podman, bryan-desktop + # Every job uses `linux` so that any runner (PC, Pi, future ones) can pick it up; no job assumes the host + # architecture or a specific user: publish-* cross-publishes with an explicit `-r linux-arm64`, deploy-scp.yaml only + # installs missing tools and only uses sudo when needed, backend-test uses a services: container (no engine socket needed). + # Use `raspberry-pi` only for a job that demonstrably cannot run elsewhere, and say why in a comment. vulnerability-scan: needs: changes if: needs.changes.outputs.backend == 'true' @@ -244,7 +283,7 @@ jobs: # --- Gate 4: frontend build --- # Validates the frontend compiles on its own, independent of any environment. The actual # per-environment deployable artifact is produced later by each publish job's own "Build admin - # frontend" step (publish-test / publish-production, below), which builds frontend/ again with + # frontend" step (publish-sls-test / publish-sls-production, below), which builds frontend/ again with # that environment's Vite variables set and copies the result into wwwroot/admin before # `dotnet publish` runs — see that step's comment for why this isn't an MSBuild target instead. frontend-build: @@ -342,7 +381,7 @@ jobs: # kept in sync with the host's real SecurityHeaders__AllowedScriptOrigins__0 env var (D-16). This # gate cannot see the actual runtime CSP configuration; it only catches drift between the frontend # build and what this variable claims the CSP allows. - publish-test: + publish-sls-test: needs: [changes, backend-build, backend-test, vulnerability-scan, frontend-build, frontend-test, frontend-lint] # always() bypasses the automatic skip-cascade from a gate job that was itself skipped (because # its side of the repo didn't change). Gitea Actions only implements always() from the GitHub @@ -350,9 +389,9 @@ jobs: # gate's outcome is checked explicitly via needs..result instead: a skipped gate is fine, # but a gate that actually ran and failed or was cancelled still blocks the publish. The # changes.outputs check makes sure there's something to publish at all: a run that touched - # neither backend nor frontend has nothing new to deploy. The final line skips this build on a - # manual workflow_dispatch run that didn't check deploy_test — building and uploading a test - # artifact nobody is going to deploy is wasted work; push/PR runs are unaffected. + # neither backend nor frontend has nothing new to deploy. The last two lines build this site only when a + # deploy will use it: never on a pull_request (the pull request builds and tests the master CMS only) and, on a + # manual workflow_dispatch run, only when deploy_sls_test is checked. if: | always() && needs.changes.result == 'success' && @@ -363,8 +402,9 @@ jobs: needs.frontend-test.result != 'failure' && needs.frontend-test.result != 'cancelled' && needs.frontend-lint.result != 'failure' && needs.frontend-lint.result != 'cancelled' && (needs.changes.outputs.backend == 'true' || needs.changes.outputs.frontend == 'true') && - (github.event_name != 'workflow_dispatch' || github.event.inputs.deploy_test == 'true') - runs-on: ubuntu-latest + github.event_name != 'pull_request' && + (github.event_name != 'workflow_dispatch' || github.event.inputs.deploy_sls_test == 'true') + runs-on: linux steps: - uses: actions/checkout@v4 - uses: actions/setup-dotnet@v4 @@ -399,6 +439,8 @@ jobs: working-directory: frontend env: VITE_APP_ENV: test + VITE_APP_TITLE: SLP Software + VITE_THEME: slpsoftware VITE_UMAMI_SCRIPT_URL: ${{ vars.VITE_UMAMI_SCRIPT_URL }} VITE_UMAMI_WEBSITE_ID: ${{ vars.VITE_UMAMI_WEBSITE_ID_TEST }} VITE_SENTRY_DSN: ${{ vars.VITE_SENTRY_DSN }} @@ -412,21 +454,21 @@ jobs: working-directory: src/SlpModularCms.Api.SlpSoftware run: > dotnet publish -c Release -r ${{ env.PUBLISH_RID }} --self-contained false - -o ${{ github.workspace }}/${{ env.ARTIFACT_NAME_TEST }} + -o ${{ github.workspace }}/${{ env.ARTIFACT_NAME_SLS_TEST }} - name: Upload publish artifact uses: actions/upload-artifact@v3 with: - name: ${{ env.ARTIFACT_NAME_TEST }} - path: ${{ env.ARTIFACT_NAME_TEST }} + name: ${{ env.ARTIFACT_NAME_SLS_TEST }} + path: ${{ env.ARTIFACT_NAME_SLS_TEST }} retention-days: 1 - # Same as publish-test, but only for a manual workflow_dispatch run with deploy_production set — - # a distinct job rather than a parameterized reuse of publish-test, because VITE_APP_ENV is a + # Same as publish-sls-test, but only for a manual workflow_dispatch run with deploy_sls_production set — + # a distinct job rather than a parameterized reuse of publish-sls-test, because VITE_APP_ENV is a # Vite build-time value: one dist/ bundle cannot be tagged as both 'test' and 'production' (FR-05). - publish-production: + publish-sls-production: needs: [changes, backend-build, backend-test, vulnerability-scan, frontend-build, frontend-test, frontend-lint] - # See publish-test's comment above on why this checks needs..result explicitly instead of + # See publish-sls-test's comment above on why this checks needs..result explicitly instead of # failure()/cancelled(), which Gitea Actions doesn't support. if: | always() && @@ -437,9 +479,9 @@ jobs: needs.frontend-build.result != 'failure' && needs.frontend-build.result != 'cancelled' && needs.frontend-test.result != 'failure' && needs.frontend-test.result != 'cancelled' && needs.frontend-lint.result != 'failure' && needs.frontend-lint.result != 'cancelled' && - github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_production == 'true' && + github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_sls_production == 'true' && (needs.changes.outputs.backend == 'true' || needs.changes.outputs.frontend == 'true') - runs-on: ubuntu-latest + runs-on: linux steps: - uses: actions/checkout@v4 - uses: actions/setup-dotnet@v4 @@ -462,12 +504,14 @@ jobs: exit 1 fi - # See publish-test's "Build admin frontend" step for why this runs as its own step ahead of + # See publish-sls-test's "Build admin frontend" step for why this runs as its own step ahead of # dotnet publish rather than an MSBuild target. - name: Build admin frontend working-directory: frontend env: VITE_APP_ENV: production + VITE_APP_TITLE: SLP Software + VITE_THEME: slpsoftware VITE_UMAMI_SCRIPT_URL: ${{ vars.VITE_UMAMI_SCRIPT_URL }} VITE_UMAMI_WEBSITE_ID: ${{ vars.VITE_UMAMI_WEBSITE_ID_PRODUCTION }} VITE_SENTRY_DSN: ${{ vars.VITE_SENTRY_DSN }} @@ -481,46 +525,50 @@ jobs: working-directory: src/SlpModularCms.Api.SlpSoftware run: > dotnet publish -c Release -r ${{ env.PUBLISH_RID }} --self-contained false - -o ${{ github.workspace }}/${{ env.ARTIFACT_NAME_PRODUCTION }} + -o ${{ github.workspace }}/${{ env.ARTIFACT_NAME_SLS_PRODUCTION }} - name: Upload publish artifact uses: actions/upload-artifact@v3 with: - name: ${{ env.ARTIFACT_NAME_PRODUCTION }} - path: ${{ env.ARTIFACT_NAME_PRODUCTION }} + name: ${{ env.ARTIFACT_NAME_SLS_PRODUCTION }} + path: ${{ env.ARTIFACT_NAME_SLS_PRODUCTION }} retention-days: 1 # Automatic test deploy on every push to master (unchanged — a merge should reach test without - # extra steps). A manual workflow_dispatch run only deploys to test when deploy_test is checked, + # extra steps). A manual workflow_dispatch run only deploys to test when deploy_sls_test is checked, # since a dispatch run is often just re-running CI/production, not a new test build (FR-03, D-01, # D-09). - deploy-test: - needs: [publish-test, config] - if: (github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_test == 'true') || (github.event_name == 'push' && github.ref == 'refs/heads/master') + # deploy_path / service_name / health_check_url come straight from the Gitea variables, NOT from the `config-sls` job + # outputs: a job output whose value contains a secret value (here most likely the deploy account name inside the + # path) is dropped by the runner, so the reusable workflow received an empty deploy_path ("/releases"). The + # `config-sls` outputs are still used for the artifact and environment names. + deploy-sls-test: + needs: [publish-sls-test, config-sls] + if: (github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_sls_test == 'true') || (github.event_name == 'push' && github.ref == 'refs/heads/master') uses: ./.gitea/workflows/deploy-scp.yaml secrets: inherit with: - artifact_name: ${{ needs.config.outputs.artifact_name_test }} - environment: ${{ needs.config.outputs.deploy_environment_test }} - deploy_path: ${{ needs.config.outputs.deploy_path_test }} - service_name: ${{ needs.config.outputs.service_name_test }} - health_check_url: ${{ needs.config.outputs.health_check_url_test }} + artifact_name: ${{ needs.config-sls.outputs.artifact_name_sls_test }} + environment: ${{ needs.config-sls.outputs.deploy_environment_sls_test }} + deploy_path: ${{ vars.DEPLOY_PATH_TEST }} + service_name: ${{ vars.SERVICE_NAME_TEST }} + health_check_url: ${{ vars.HEALTH_CHECK_URL_TEST }} run_db_backup: false - # Production deploy ONLY on an explicit workflow_dispatch run with deploy_production checked + # Production deploy ONLY on an explicit workflow_dispatch run with deploy_sls_production checked # (FR-04, D-09) — never reachable from a plain push to master, so pushing cannot deploy production # under any circumstance. - deploy-production: - needs: [publish-production, config] - if: github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_production == 'true' + deploy-sls-production: + needs: [publish-sls-production, config-sls] + if: github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_sls_production == 'true' uses: ./.gitea/workflows/deploy-scp.yaml secrets: inherit with: - artifact_name: ${{ needs.config.outputs.artifact_name_production }} - environment: ${{ needs.config.outputs.deploy_environment_production }} - deploy_path: ${{ needs.config.outputs.deploy_path_production }} - service_name: ${{ needs.config.outputs.service_name_production }} - health_check_url: ${{ needs.config.outputs.health_check_url_production }} + artifact_name: ${{ needs.config-sls.outputs.artifact_name_sls_production }} + environment: ${{ needs.config-sls.outputs.deploy_environment_sls_production }} + deploy_path: ${{ vars.DEPLOY_PATH_PRODUCTION }} + service_name: ${{ vars.SERVICE_NAME_PRODUCTION }} + health_check_url: ${{ vars.HEALTH_CHECK_URL_PRODUCTION }} run_db_backup: true # ========================================================================================== @@ -537,7 +585,7 @@ jobs: # ========================================================================================== config-asf: if: ${{ vars.ASF_TEST_DEPLOY_ENABLED == 'true' }} - runs-on: ubuntu-latest + runs-on: linux outputs: deploy_path: ${{ steps.set.outputs.deploy_path }} service_name: ${{ steps.set.outputs.service_name }} @@ -561,7 +609,7 @@ jobs: publish-asf-test: needs: [changes, backend-build, backend-test, vulnerability-scan, frontend-build, frontend-test, frontend-lint] - # Same gate handling as publish-test (see there for why always() and explicit results), plus the + # Same gate handling as publish-sls-test (see there for why always() and explicit results), plus the # ASF switch, and built only when it will actually be deployed. if: | always() && @@ -576,7 +624,7 @@ jobs: (needs.changes.outputs.backend == 'true' || needs.changes.outputs.frontend == 'true') && ((github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_asf_test == 'true') || (github.event_name == 'push' && github.ref == 'refs/heads/master')) - runs-on: ubuntu-latest + runs-on: linux steps: - uses: actions/checkout@v4 - uses: actions/setup-dotnet@v4 @@ -590,7 +638,7 @@ jobs: version: ${{ env.PNPM_VERSION }} # Admin SPA with the ASF theme and Dutch as the default language. Lands in wwwroot/admin - # BEFORE dotnet publish, for the same reason as in publish-test. No Umami for the admin. + # BEFORE dotnet publish, for the same reason as in publish-sls-test. No Umami for the admin. - name: Build admin frontend (ASF theme) working-directory: frontend env: @@ -618,6 +666,8 @@ jobs: path: app-asf-test retention-days: 1 + # Path/service/health straight from the Gitea variables, like deploy-sls-test (a job output containing a secret value, + # here the deploy account name in the path, arrives empty). config-asf still validates that they are set. deploy-asf-test: needs: [publish-asf-test, config-asf] if: vars.ASF_TEST_DEPLOY_ENABLED == 'true' && ((github.event_name == 'workflow_dispatch' && github.event.inputs.deploy_asf_test == 'true') || (github.event_name == 'push' && github.ref == 'refs/heads/master')) @@ -626,7 +676,32 @@ jobs: with: artifact_name: app-asf-test environment: test - deploy_path: ${{ needs.config-asf.outputs.deploy_path }} - service_name: ${{ needs.config-asf.outputs.service_name }} - health_check_url: ${{ needs.config-asf.outputs.health_check_url }} + deploy_path: ${{ vars.DEPLOY_PATH_ASF_TEST }} + service_name: ${{ vars.SERVICE_NAME_ASF_TEST }} + health_check_url: ${{ vars.HEALTH_CHECK_URL_ASF_TEST }} run_db_backup: false + + # --- Smoke tests of the deployed compositions (anonymous requests, see scripts/smoke-site.sh) --- + # The CI tests the master CMS; this is the check that the composition of each site that was just deployed to test + # is the intended one (modules, website mode, noindex, protected admin routes). A failing smoke test fails the run. + smoke-sls-test: + needs: [deploy-sls-test] + if: always() && needs.deploy-sls-test.result == 'success' + runs-on: linux + steps: + - uses: actions/checkout@v4 + - name: Smoke test SLS test + env: + HEALTH_URL: ${{ vars.HEALTH_CHECK_URL_TEST }} + run: bash scripts/smoke-site.sh "$HEALTH_URL" sls-test + + smoke-asf-test: + needs: [deploy-asf-test] + if: always() && needs.deploy-asf-test.result == 'success' + runs-on: linux + steps: + - uses: actions/checkout@v4 + - name: Smoke test ASF test + env: + HEALTH_URL: ${{ vars.HEALTH_CHECK_URL_ASF_TEST }} + run: bash scripts/smoke-site.sh "$HEALTH_URL" asf-test diff --git a/.gitea/workflows/deploy-scp.yaml b/.gitea/workflows/deploy-scp.yaml index d46c5e0..2db2680 100644 --- a/.gitea/workflows/deploy-scp.yaml +++ b/.gitea/workflows/deploy-scp.yaml @@ -40,8 +40,75 @@ on: jobs: deploy: - runs-on: ubuntu-latest + runs-on: linux steps: + # Runner-independent: only installs what is missing, and only uses sudo when not already root and sudo exists + # (a container on the PC runner has neither sudo nor a need for it; the Pi runner may need it). + # + # Authentication: the Pi-Main host only allows password login from the Pi runner's address, so every runner other + # than that one needs a key. If the secret PI_MAIN_SSH_KEY (private key of the deploy account) is set and works, + # the wrappers `rssh` / `rscp` below use it (-i, IdentitiesOnly, BatchMode); otherwise they fall back to sshpass + # with the password, which keeps working from the Pi runner. The key lives in a temp directory that is removed + # at the end of the job; it is never printed. + - name: Ensure ssh tooling and authentication + env: + SSH_USER: ${{ secrets.PI_MAIN_USERNAME }} + SSH_PASS: ${{ secrets.PI_MAIN_PASSWORD }} + SSH_PORT: ${{ secrets.PI_MAIN_PORT }} + SSH_HOST: ${{ secrets.PI_MAIN_ADDRESS }} + SSH_KEY: ${{ secrets.PI_MAIN_SSH_KEY }} + IN_DEPLOY_PATH: ${{ inputs.deploy_path }} + IN_SERVICE_NAME: ${{ inputs.service_name }} + IN_HEALTH_URL: ${{ inputs.health_check_url }} + run: | + # Inputs are not secret: print them so an empty one is visible, and stop before anything touches the host. + echo "Inputs: deploy_path='$IN_DEPLOY_PATH' service_name='$IN_SERVICE_NAME' health_check_url='$IN_HEALTH_URL'" + for v in IN_DEPLOY_PATH IN_SERVICE_NAME IN_HEALTH_URL; do + if [ -z "${!v}" ]; then echo "Input $v is empty; refusing to deploy."; exit 1; fi + done + SUDO="" + if [ "$(id -u)" != "0" ] && command -v sudo >/dev/null 2>&1; then SUDO="sudo"; fi + if ! command -v sshpass >/dev/null 2>&1 || ! command -v ssh >/dev/null 2>&1 || ! command -v scp >/dev/null 2>&1; then + $SUDO apt-get update && $SUDO apt-get install -y sshpass openssh-client + fi + + D=$(mktemp -d) + mkdir -p "$D/bin" + echo "DEPLOY_TMP=$D" >> "$GITHUB_ENV" + echo "$D/bin" >> "$GITHUB_PATH" + + if [ -n "$SSH_KEY" ]; then + printf '%s\n' "$SSH_KEY" > "$D/key" + chmod 600 "$D/key" + if ssh -i "$D/key" -o IdentitiesOnly=yes -o BatchMode=yes -o StrictHostKeyChecking=no -o ConnectTimeout=15 \ + -p "$SSH_PORT" "$SSH_USER@$SSH_HOST" true; then + touch "$D/key_ok" + echo "Authentication: deploy key" + else + echo "Deploy key rejected or host unreachable with it; falling back to password" + fi + else + echo "No deploy key set; using password" + fi + + cat > "$D/bin/rssh" <<'WRAP' + #!/bin/sh + D="$(dirname "$0")/.." + if [ -f "$D/key_ok" ]; then + exec ssh -i "$D/key" -o IdentitiesOnly=yes -o BatchMode=yes -o StrictHostKeyChecking=no -p "$SSH_PORT" "$SSH_USER@$SSH_HOST" "$@" + fi + exec sshpass -p "$SSH_PASS" ssh -o StrictHostKeyChecking=no -p "$SSH_PORT" "$SSH_USER@$SSH_HOST" "$@" + WRAP + cat > "$D/bin/rscp" <<'WRAP' + #!/bin/sh + D="$(dirname "$0")/.." + if [ -f "$D/key_ok" ]; then + exec scp -i "$D/key" -o IdentitiesOnly=yes -o BatchMode=yes -o StrictHostKeyChecking=no -P "$SSH_PORT" "$@" + fi + exec sshpass -p "$SSH_PASS" scp -o StrictHostKeyChecking=no -P "$SSH_PORT" "$@" + WRAP + chmod +x "$D/bin/rssh" "$D/bin/rscp" + - name: Compute release timestamp id: release run: echo "timestamp=$(date -u +%Y%m%d%H%M%S)" >> "$GITHUB_OUTPUT" @@ -68,11 +135,7 @@ jobs: SSH_HOST: ${{ secrets.PI_MAIN_ADDRESS }} run: | echo "Environment: ${{ inputs.environment }}" - sudo apt-get update && sudo apt-get install -y sshpass - sshpass -p "$SSH_PASS" ssh \ - -p "$SSH_PORT" \ - -o StrictHostKeyChecking=no \ - "$SSH_USER@$SSH_HOST" \ + rssh \ "bash ~/scripts/backup-slpsoftware-db.sh ${{ inputs.environment }}" # Uploads the published output to a fresh, timestamped release directory rather than @@ -92,16 +155,10 @@ jobs: SSH_HOST: ${{ secrets.PI_MAIN_ADDRESS }} run: | echo "Environment: ${{ inputs.environment }}, transport: ${{ inputs.transport }}" - sudo apt-get update && sudo apt-get install -y sshpass RELEASE_DIR="${{ inputs.deploy_path }}/releases/${{ steps.release.outputs.timestamp }}" - sshpass -p "$SSH_PASS" ssh \ - -p "$SSH_PORT" \ - -o StrictHostKeyChecking=no \ - "$SSH_USER@$SSH_HOST" \ + rssh \ "mkdir -p $RELEASE_DIR" - sshpass -p "$SSH_PASS" scp \ - -P "$SSH_PORT" \ - -o StrictHostKeyChecking=no \ + rscp \ -r ${{ inputs.artifact_name }}/* \ "$SSH_USER@$SSH_HOST:$RELEASE_DIR/" @@ -123,10 +180,7 @@ jobs: SSH_HOST: ${{ secrets.PI_MAIN_ADDRESS }} run: | RELEASE_DIR="${{ inputs.deploy_path }}/releases/${{ steps.release.outputs.timestamp }}" - sshpass -p "$SSH_PASS" ssh \ - -p "$SSH_PORT" \ - -o StrictHostKeyChecking=no \ - "$SSH_USER@$SSH_HOST" \ + rssh \ "mkdir -p ${{ inputs.deploy_path }}/shared/wwwroot-web && \ mkdir -p $RELEASE_DIR/wwwroot && \ rm -rf $RELEASE_DIR/wwwroot/web && \ @@ -150,10 +204,7 @@ jobs: SSH_HOST: ${{ secrets.PI_MAIN_ADDRESS }} run: | RELEASE_DIR="${{ inputs.deploy_path }}/releases/${{ steps.release.outputs.timestamp }}" - sshpass -p "$SSH_PASS" ssh \ - -p "$SSH_PORT" \ - -o StrictHostKeyChecking=no \ - "$SSH_USER@$SSH_HOST" \ + rssh \ "mkdir -p ${{ inputs.deploy_path }}/shared/modules && \ ls ${{ inputs.deploy_path }}/shared/modules/*.dll 2>/dev/null | while read -r f; do \ name=\$(basename \"\$f\"); \ @@ -172,10 +223,7 @@ jobs: SSH_HOST: ${{ secrets.PI_MAIN_ADDRESS }} run: | RELEASE_DIR="${{ inputs.deploy_path }}/releases/${{ steps.release.outputs.timestamp }}" - sshpass -p "$SSH_PASS" ssh \ - -p "$SSH_PORT" \ - -o StrictHostKeyChecking=no \ - "$SSH_USER@$SSH_HOST" \ + rssh \ "ln -sfn $RELEASE_DIR ${{ inputs.deploy_path }}/current && \ systemctl --user restart ${{ inputs.service_name }}" @@ -206,8 +254,9 @@ jobs: SSH_PORT: ${{ secrets.PI_MAIN_PORT }} SSH_HOST: ${{ secrets.PI_MAIN_ADDRESS }} run: | - sshpass -p "$SSH_PASS" ssh \ - -p "$SSH_PORT" \ - -o StrictHostKeyChecking=no \ - "$SSH_USER@$SSH_HOST" \ + rssh \ "cd ${{ inputs.deploy_path }}/releases && ls -1t | tail -n +3 | xargs -r rm -rf" + + - name: Remove deploy key + if: always() + run: rm -rf "${DEPLOY_TMP:-/nonexistent}" diff --git a/README.md b/README.md index a7b2831..f6f8165 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,8 @@ Een modulaire monolith CMS gebouwd met .NET 10. ## Projectstructuur - `src/SlpModularCms.Api`: De host applicatie en API shell (lokale ontwikkeling / dev-host). -- `src/SlpModularCms.Api.SlpSoftware`: Tweede Client-project, de daadwerkelijk gedeployde API voor `test.slpsoftware.nl`/`slpsoftware.nl` (CI/CD-cutover vanaf `SlpModularCms.Api`). Host dezelfde modules als `SlpModularCms.Api` via dezelfde gedeelde `CmsHost`-compositie (zie hieronder), plus de `Offerings`-module. Heeft een eigen, geïsoleerde lokale ontwikkeldatabase — zie `appsettings.Development.json` in dat project. -- `src/SlpModularCms.Api.AndreaSlopFotografie`: Derde Client-project voor Andrea Slop Fotografie (testomgeving `test.andreaslop.nl`). Host alleen de modules `Identity` en `Availability` (geen `Master`, geen `Offerings`) en serveert de voorgerenderde website uit `wwwroot/web/` (`WebsiteMode.PrerenderedPages`) plus de admin met het thema `asf` op `/admin`. Lokaal op poort `5200`, eigen database (`appsettings.Development.json`). Bijbehorende tests: `SlpModularCms.Api.AndreaSlopFotografie.Tests` (de pipelinetests daarin hebben net als `Api.Tests` een bereikbare MariaDB nodig). +- `src/SlpModularCms.Api.SlpSoftware`: Tweede Client-project, de daadwerkelijk gedeployde API voor `test.slpsoftware.nl`/`slpsoftware.nl` (CI/CD-cutover vanaf `SlpModularCms.Api`). Host dezelfde modules als `SlpModularCms.Api` via dezelfde gedeelde `CmsHost`-compositie (zie hieronder), plus de `Offerings`- en `Contact`-module. Heeft een eigen, geïsoleerde lokale ontwikkeldatabase — zie `appsettings.Development.json` in dat project. +- `src/SlpModularCms.Api.AndreaSlopFotografie`: Derde Client-project voor Andrea Slop Fotografie (testomgeving `test.andreaslop.nl`). Host de modules `Identity`, `Availability`, `Offerings` en `Contact` (geen `Master`) en serveert de voorgerenderde website uit `wwwroot/web/` (`Website:Mode=PrerenderedPages`) plus de admin met het thema `asf` op `/admin`. Lokaal op poort `5200`, eigen database (`appsettings.Development.json`). Geen eigen testproject: het gedrag zit in Core en de modules en wordt getest op de master-`SlpModularCms.Api` (alle modules); de samenstelling en standaardwaarden van deze site worden getest in `SlpModularCms.Api.Tests` (`SiteContractTests`, `AsfVariantPipelineTests`) en `SlpModularCms.Modules.Contact.Tests` (`SiteVariantContactTests`). `Website:Mode=PrerenderedPages` staat in de eigen `appsettings.json`. - `src/SlpModularCms.Core`: Kern functionaliteiten, data modellen en interfaces. Bevat ook `Core/Hosting/CmsHost.cs` — de gedeelde service- en pipeline-compositie die elk Client-project (`Api`, `Api.SlpSoftware`) vanuit zijn eigen dunne `Program.cs` aanroept, zodat beide projecten niet uit elkaar kunnen groeien. - `src/SlpModularCms.Modules.*`: Onafhankelijke functionele modules. - `frontend/`: De CMS admin web-UI (Vite + React + TypeScript). Bewust buiten `src/` gehouden om de .NET solution schoon te houden. @@ -105,7 +105,7 @@ De frontend leest de API-basis-URL uit een environment-variabele (zie `frontend/ ``` VITE_API_BASE_URL=http://localhost:5000 ``` -Per site kan de admin bij het bouwen een thema en standaardtaal krijgen: `VITE_THEME=asf` kiest `frontend/themes/asf/theme.css` (alleen CSS-variabelen, zelf gehoste lettertypen via `@fontsource`, plus een eigen favicon; een onbekende themanaam laat de build falen, leeg of afwezig = het standaardthema) en `VITE_DEFAULT_LANGUAGE=nl` (of `en`) bepaalt de taal zolang de gebruiker nog niets koos; een opgeslagen keuze wint altijd. +Per site kan de admin bij het bouwen een thema en standaardtaal krijgen (beschikbare thema's: `asf` en `slpsoftware`, zie [docs/cms-themas.md](docs/cms-themas.md)): `VITE_THEME=asf` kiest `frontend/themes/asf/theme.css` (alleen CSS-variabelen, zelf gehoste lettertypen via `@fontsource`, plus een eigen favicon; een onbekende themanaam laat de build falen, leeg of afwezig = het standaardthema) en `VITE_DEFAULT_LANGUAGE=nl` (of `en`) bepaalt de taal zolang de gebruiker nog niets koos; een opgeslagen keuze wint altijd. Kopieer `.env.example` naar `.env.local` en pas de waarde aan indien nodig. Optioneel kan met `VITE_ENABLE_MSW=true` de MSW-mockbackend in de browser worden ingeschakeld voor frontend-ontwikkeling zonder draaiende API. @@ -250,6 +250,37 @@ Zolang de master-gate een slave op `NotAvailable` heeft gezet (via push of pull) - Een lokale poging om de status alsnog te wijzigen (bijv. via een directe API-call) wordt door de backend geweigerd met `409 Conflict` (`MasterControlledAvailabilityException` in `PersistentAvailabilityService.UpdateStatusAsync`) — de master-gate kan dus niet per ongeluk of expres lokaal worden omzeild. - `GET /api/v1/Availability/status` geeft dit door via het veld `isMasterControlled`. +## Offerings: aanbiedingen en banner + +De module `SlpModularCms.Modules.Offerings` (gehost door `Api.SlpSoftware` en `Api.AndreaSlopFotografie`) beheert de aanbiedingen (pakketten, met categorieën) en de banner van de website. Hieronder alleen de banner; details en beslissingen staan in `aidlc-docs/features/offering-banners/overview.md`. + +Een banner heeft een **positie**: `top` (smalle balk boven de pagina, één regel) of `bottom` (grote banner; bestaande banners zijn via migratie `20261114100000_AddOfferingBannerPosition` `bottom` geworden). + +**Publiek:** `GET /api/v1/offerings/banner?position=top|bottom` +- Zonder `position` geldt `bottom`; een andere waarde geeft `400`. +- `204` zonder actieve banner; anders `200` met `title`, `text`, `linkLabel`, `linkUrl`, `position` (geen planning). +- Anoniem, rate limit `offerings-public` (standaard 120 per 60 s per clientadres, `RateLimiting:OfferingsPublic`), antwoord met `Cache-Control: public, max-age=60`. + +**Beheer:** `/api/v1/offerings/banners` (`GET`, `POST`, `PUT {id}`, `DELETE {id}`), alleen voor beheerders (`AdminOnly`). + +**Velden en validatie:** `top`: tekst max 120 tekens, titel optioneel. `bottom`: titel verplicht (max 100), tekst max 300. Knoptekst (max 50) en link (max 500) alleen samen; een link is `https://…` of een pad dat met één `/` begint. `endsAt` moet na `startsAt` liggen. `isActive` en de planning (`startsAt`/`endsAt`) bepalen of een banner meetelt. + +**"Maximaal één per positie"** geldt bij het uitlezen: je kunt meer banners opslaan en aanzetten; per positie wint de laatst gewijzigde actieve banner die binnen zijn van/tot valt. Een boven- en een onderbanner kunnen dus tegelijk getoond worden. + +**Admin** (tabblad Banner bij Aanbiedingen): één lijst met een badge Locatie (Boven/Onder), de status (Actief, Gepland, Verlopen, Uit), de markeringen "Live" (wordt getoond) en "Wordt niet getoond" (actief, maar een nieuwere banner op dezelfde locatie wint), en een aan/uit-knop per rij. Het formulier heeft een keuzeveld Locatie dat de tekstlimiet en de titelplicht aanpast. + +## Contactformulier-module + +De module `SlpModularCms.Modules.Contact` (gehost door `Api.SlpSoftware` en `Api.AndreaSlopFotografie`; tests in `SlpModularCms.Modules.Contact.Tests`) ontvangt berichten van het contactformulier van een website, slaat ze op, mailt een melding naar de eigenaar en laat beheerders ze in de admin (Berichten) beheren. Plan en beslissingen: `aidlc-docs/features/contact-forms-module/`. Welke gegevens worden bewaard, hoe lang en wat in logs en Sentry terechtkomt: [`docs/privacy-gegevens-contactformulier.md`](docs/privacy-gegevens-contactformulier.md). + +- **Uit tenzij beide schakelaars aan staan:** de hostschakelaar `Contact:Enabled` (standaard `false` in beide `appsettings.json`) én de CMS-schakelaar bij Berichten. Is het formulier niet open, dan bestaan de publieke routes niet (404). De migraties van de module worden pas bij het opstarten toegepast als `Contact:Enabled` aan staat. +- **Publiek:** `GET /api/v1/contact-messages/token` (tijdtoken, plus eventuele captcha-gegevens) en `POST /api/v1/contact-messages` (JSON, header `Idempotency-Key` met een GUID; antwoord `202`; fouten `400` in `ProblemDetails`-vorm met veldcodes `required`, `tooLong`, `invalid`, `expired`). +- **Beheer** (`AdminOnly`): `GET /api/v1/contact-messages`, `GET`/`PATCH`/`DELETE …/{id}`, `POST …/{id}/resend`, en `GET`/`PUT /api/v1/contact-settings` (schakelaar) met `PUT …/contact-settings/recipient` (ontvangstadres). +- **Anti-spam:** honeypot, minimumtijd tussen token en verzenden, optioneel Friendly Captcha, rate limiting per clientadres (`RateLimiting:ContactForm`, `ContactToken`, `ContactResend`). Achter een reverse proxy moet `ForwardedHeaders__KnownProxies__0` gezet zijn, anders delen alle bezoekers één limiet. +- **Configuratie (sectie `Contact`):** `Enabled`, `SiteId`, `MinSeconds` (3), `TokenLifetimeMinutes` (120), `RetentionMonths` (12), `SpamRetentionDays` (30), `MaxSpamRowsPerDay` (200), `MaxBodyBytes` (16384), `ProblemTypeBase`, `RecipientEmail` (alleen via omgevingsvariabele `Contact__RecipientEmail`), `Mail:SweepSeconds`/`MaxAttempts`/`BackoffMinutes`/`ClaimMinutes`/`BatchSize`, en `Captcha:Enabled`/`Provider` (`friendlycaptcha`)/`SiteKey`/`Secret` (alleen via `Contact__Captcha__Secret`)/`Region` (`global` of `eu`)/`VerifyUrl`/`TimeoutSeconds`. Een aangezet captcha met ontbrekende of ongeldige instellingen laat de host bij opstarten falen. +- **Opschonen:** een dagelijkse achtergrondtaak verwijdert berichten na hun bewaartermijn en idempotentie-gegevens na 24 uur. +- **Mail:** vereist werkende e-mailconfiguratie (zie "E-mail" hierboven) en een ontvangstadres; anders blijft het bericht bewaard met de reden bij het bericht. + ## Lokaal Master + Slave Draaien (Dev) Om de master↔slave-connectie (zie "Master CMS Module" hierboven) lokaal te kunnen testen, kun je twee backend-instanties tegelijk draaien: een volledige "master" (met de `SlpModularCms.Modules.Master`-module) en een "slave"-instantie zonder die module. Dit is puur een lokale ontwikkel-/testopstelling — er is geen nieuwe functionaliteit aan de master/slave-protocol zelf toegevoegd. @@ -324,7 +355,7 @@ Ontbreekt `wwwroot/web/` nog (een verse deployment vóórdat een website-workspa Voor lokale ontwikkeling verandert er niets: `pnpm dev` blijft op `http://localhost:5173` draaien zonder `/admin`-prefix. ### 1. Build & Publish -Publiceren gebeurt via de Gitea Actions-pipeline (`.gitea/workflows/continuous_integration.yaml` → `deploy-scp.yaml`), niet met een losse handmatige `dotnet publish`-stap: elke push naar `master` deployt automatisch naar test, productie alleen via een expliciete `workflow_dispatch` met de `deploy_production`-vlag aan. De pipeline publiceert framework-dependent voor `linux-arm64` en bouwt daarbij automatisch ook de admin-frontend mee naar `wwwroot/admin/`. +Publiceren gebeurt via de Gitea Actions-pipeline (`.gitea/workflows/continuous_integration.yaml` → `deploy-scp.yaml`), niet met een losse handmatige `dotnet publish`-stap: elke push naar `master` deployt automatisch naar de SlpSoftware-testomgeving (en naar de ASF-testomgeving als de Gitea-variabele `ASF_TEST_DEPLOY_ENABLED` op `true` staat), productie alleen via een expliciete `workflow_dispatch` met de `deploy_production`-vlag aan. Een branch naar test deployen kan met een handmatige run (`deploy_test` en/of `deploy_asf_test`). Zie [`docs/deploy-en-testomgevingen.md`](docs/deploy-en-testomgevingen.md) voor invoer, testhosts, vereiste variabelen en secrets (alleen namen) en rollback. De pipeline publiceert framework-dependent voor `linux-arm64` en bouwt daarbij automatisch ook de admin-frontend mee naar `wwwroot/admin/`. Elke deploy plaatst de nieuwe release in een verse map en wisselt pas daarna atomisch over naar `current` — er is dus nooit een moment waarop de applicatie een halfklare release serveert, en `wwwroot/web/` (de klantsite) staat structureel buiten die verwisselde map, zodat een deploy hem nooit kan raken. Volledige host-setup, rollback-procedure en de exacte deploy-stappen staan in de Operations-documentatie van deze feature, niet hier — dit README beschrijft alleen wat er gebouwd is, niet hoe je het voor het eerst inricht. @@ -345,7 +376,7 @@ In productie moeten gevoelige instellingen worden doorgegeven via Environment Va - `Observability__SentryDsn` — leeg is een normale, ondersteunde staat: Sentry wordt dan overgeslagen en alleen console-logging blijft actief - `SecurityHeaders__AllowedScriptOrigins__0`, `SecurityHeaders__AllowedConnectOrigins__0`, ... — externe origins die de CSP van `/admin` en `/api/v1` mag toestaan (bijv. de Umami-scripthost en Sentry's ingest-endpoint). Zie `appsettings.json → SecurityHeaders` voor de volledige optiesvorm; een onbekende `PathPolicies`-policy-naam laat de applicatie bij **opstarten** falen, niet pas bij de eerste request -- **Voorgerenderde website (`WebsiteMode.PrerenderedPages`)** — een client kiest dit in zijn `Program.cs` via `CmsHostOptions` (standaard `SpaFallback`: alles blijft zoals het was). Instellingen voor deze modus: `Website__NoIndex=true` (testinstantie: `X-Robots-Tag` plus `robots.txt` met `Disallow: /`), `SecurityHeaders__DefaultPolicy=StrictSite` met `SecurityHeaders__AllowedSiteScriptOrigins__0`, `SecurityHeaders__AllowedSiteConnectOrigins__0`, ... (alleen gebruikt door `StrictSite`). Logging van de website (301's en 404's op `Information`) gaat via de logger-categorie `SlpModularCms.Website`: zet per omgeving `Website__LogLevel` (test `Information`, standaard en productie `Warning`; leeg = `Logging:LogLevel` beslist). Gebruik niet `Logging__LogLevel__SlpModularCms.Website` in een systemd-`EnvironmentFile`: een variabelenaam met een punt wordt daar genegeerd. Gedrag per pad staat in [`WEBSITE_WORKSPACE.md`](WEBSITE_WORKSPACE.md). +- **Voorgerenderde website (`Website:Mode=PrerenderedPages`)** — een client kiest dit in zijn `Program.cs` via `CmsHostOptions` (standaard `SpaFallback`: alles blijft zoals het was). Instellingen voor deze modus: `Website__NoIndex=true` (testinstantie: `X-Robots-Tag` plus `robots.txt` met `Disallow: /`), `SecurityHeaders__DefaultPolicy=StrictSite` met `SecurityHeaders__AllowedSiteScriptOrigins__0`, `SecurityHeaders__AllowedSiteConnectOrigins__0`, ... (alleen gebruikt door `StrictSite`). Logging van de website (301's en 404's op `Information`) gaat via de logger-categorie `SlpModularCms.Website`: zet per omgeving `Website__LogLevel` (test `Information`, standaard en productie `Warning`; leeg = `Logging:LogLevel` beslist). Gebruik niet `Logging__LogLevel__SlpModularCms.Website` in een systemd-`EnvironmentFile`: een variabelenaam met een punt wordt daar genegeerd. Gedrag per pad staat in [`WEBSITE_WORKSPACE.md`](WEBSITE_WORKSPACE.md). ### 2a. Data Protection key ring (Master CMS Module) De API keys van geregistreerde slaves worden versleuteld opgeslagen met ASP.NET Core Data Protection. De key ring wordt **automatisch** persistent opgeslagen in de database (`PersistKeysToDbContext`, met een expliciete, stabiele applicatie-discriminator) — dit hoeft niet meer apart geconfigureerd te worden. Dit is bewust zo gebouwd omdat de atomische release-switch (zie hierboven) bij elke deploy een nieuwe content-root-map gebruikt: zonder een database-backed key ring zou dat elke keer de key ring weggooien en alle opgeslagen slave-API-keys onleesbaar maken. diff --git a/SlpModularCms.Ci.slnf b/SlpModularCms.Ci.slnf new file mode 100644 index 0000000..a5045cf --- /dev/null +++ b/SlpModularCms.Ci.slnf @@ -0,0 +1,21 @@ +{ + "solution": { + "path": "SlpModularCms.sln", + "projects": [ + "src\\SlpModularCms.Api\\SlpModularCms.Api.csproj", + "src\\SlpModularCms.Core\\SlpModularCms.Core.csproj", + "src\\SlpModularCms.Core.Tests\\SlpModularCms.Core.Tests.csproj", + "src\\SlpModularCms.Modules.Availability\\SlpModularCms.Modules.Availability.csproj", + "src\\SlpModularCms.Modules.Availability.Tests\\SlpModularCms.Modules.Availability.Tests.csproj", + "src\\SlpModularCms.Modules.Identity\\SlpModularCms.Modules.Identity.csproj", + "src\\SlpModularCms.Modules.Identity.Tests\\SlpModularCms.Modules.Identity.Tests.csproj", + "src\\SlpModularCms.Modules.Master\\SlpModularCms.Modules.Master.csproj", + "src\\SlpModularCms.Modules.Master.Tests\\SlpModularCms.Modules.Master.Tests.csproj", + "src\\SlpModularCms.Api.Tests\\SlpModularCms.Api.Tests.csproj", + "src\\SlpModularCms.Modules.Offerings\\SlpModularCms.Modules.Offerings.csproj", + "src\\SlpModularCms.Modules.Offerings.Tests\\SlpModularCms.Modules.Offerings.Tests.csproj", + "src\\SlpModularCms.Modules.Contact\\SlpModularCms.Modules.Contact.csproj", + "src\\SlpModularCms.Modules.Contact.Tests\\SlpModularCms.Modules.Contact.Tests.csproj" + ] + } +} diff --git a/SlpModularCms.sln b/SlpModularCms.sln index aa999db..6576ff6 100644 --- a/SlpModularCms.sln +++ b/SlpModularCms.sln @@ -40,7 +40,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlpModularCms.Modules.Offer EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlpModularCms.Api.AndreaSlopFotografie", "src\SlpModularCms.Api.AndreaSlopFotografie\SlpModularCms.Api.AndreaSlopFotografie.csproj", "{759EE53D-EECA-4054-A17F-4172B0EC2015}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlpModularCms.Api.AndreaSlopFotografie.Tests", "src\SlpModularCms.Api.AndreaSlopFotografie.Tests\SlpModularCms.Api.AndreaSlopFotografie.Tests.csproj", "{DF0FDCFD-2601-4D60-A7F5-198D39DBE57B}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlpModularCms.Modules.Contact", "src\SlpModularCms.Modules.Contact\SlpModularCms.Modules.Contact.csproj", "{59F64DD2-DF30-4F78-A3B7-2AB6A769ED6C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlpModularCms.Modules.Contact.Tests", "src\SlpModularCms.Modules.Contact.Tests\SlpModularCms.Modules.Contact.Tests.csproj", "{06C25AF5-D63F-4007-8796-C4BA27940EBA}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -232,18 +234,30 @@ Global {759EE53D-EECA-4054-A17F-4172B0EC2015}.Release|x64.Build.0 = Release|Any CPU {759EE53D-EECA-4054-A17F-4172B0EC2015}.Release|x86.ActiveCfg = Release|Any CPU {759EE53D-EECA-4054-A17F-4172B0EC2015}.Release|x86.Build.0 = Release|Any CPU - {DF0FDCFD-2601-4D60-A7F5-198D39DBE57B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {DF0FDCFD-2601-4D60-A7F5-198D39DBE57B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {DF0FDCFD-2601-4D60-A7F5-198D39DBE57B}.Debug|x64.ActiveCfg = Debug|Any CPU - {DF0FDCFD-2601-4D60-A7F5-198D39DBE57B}.Debug|x64.Build.0 = Debug|Any CPU - {DF0FDCFD-2601-4D60-A7F5-198D39DBE57B}.Debug|x86.ActiveCfg = Debug|Any CPU - {DF0FDCFD-2601-4D60-A7F5-198D39DBE57B}.Debug|x86.Build.0 = Debug|Any CPU - {DF0FDCFD-2601-4D60-A7F5-198D39DBE57B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {DF0FDCFD-2601-4D60-A7F5-198D39DBE57B}.Release|Any CPU.Build.0 = Release|Any CPU - {DF0FDCFD-2601-4D60-A7F5-198D39DBE57B}.Release|x64.ActiveCfg = Release|Any CPU - {DF0FDCFD-2601-4D60-A7F5-198D39DBE57B}.Release|x64.Build.0 = Release|Any CPU - {DF0FDCFD-2601-4D60-A7F5-198D39DBE57B}.Release|x86.ActiveCfg = Release|Any CPU - {DF0FDCFD-2601-4D60-A7F5-198D39DBE57B}.Release|x86.Build.0 = Release|Any CPU + {59F64DD2-DF30-4F78-A3B7-2AB6A769ED6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {59F64DD2-DF30-4F78-A3B7-2AB6A769ED6C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {59F64DD2-DF30-4F78-A3B7-2AB6A769ED6C}.Debug|x64.ActiveCfg = Debug|Any CPU + {59F64DD2-DF30-4F78-A3B7-2AB6A769ED6C}.Debug|x64.Build.0 = Debug|Any CPU + {59F64DD2-DF30-4F78-A3B7-2AB6A769ED6C}.Debug|x86.ActiveCfg = Debug|Any CPU + {59F64DD2-DF30-4F78-A3B7-2AB6A769ED6C}.Debug|x86.Build.0 = Debug|Any CPU + {59F64DD2-DF30-4F78-A3B7-2AB6A769ED6C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {59F64DD2-DF30-4F78-A3B7-2AB6A769ED6C}.Release|Any CPU.Build.0 = Release|Any CPU + {59F64DD2-DF30-4F78-A3B7-2AB6A769ED6C}.Release|x64.ActiveCfg = Release|Any CPU + {59F64DD2-DF30-4F78-A3B7-2AB6A769ED6C}.Release|x64.Build.0 = Release|Any CPU + {59F64DD2-DF30-4F78-A3B7-2AB6A769ED6C}.Release|x86.ActiveCfg = Release|Any CPU + {59F64DD2-DF30-4F78-A3B7-2AB6A769ED6C}.Release|x86.Build.0 = Release|Any CPU + {06C25AF5-D63F-4007-8796-C4BA27940EBA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {06C25AF5-D63F-4007-8796-C4BA27940EBA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {06C25AF5-D63F-4007-8796-C4BA27940EBA}.Debug|x64.ActiveCfg = Debug|Any CPU + {06C25AF5-D63F-4007-8796-C4BA27940EBA}.Debug|x64.Build.0 = Debug|Any CPU + {06C25AF5-D63F-4007-8796-C4BA27940EBA}.Debug|x86.ActiveCfg = Debug|Any CPU + {06C25AF5-D63F-4007-8796-C4BA27940EBA}.Debug|x86.Build.0 = Debug|Any CPU + {06C25AF5-D63F-4007-8796-C4BA27940EBA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {06C25AF5-D63F-4007-8796-C4BA27940EBA}.Release|Any CPU.Build.0 = Release|Any CPU + {06C25AF5-D63F-4007-8796-C4BA27940EBA}.Release|x64.ActiveCfg = Release|Any CPU + {06C25AF5-D63F-4007-8796-C4BA27940EBA}.Release|x64.Build.0 = Release|Any CPU + {06C25AF5-D63F-4007-8796-C4BA27940EBA}.Release|x86.ActiveCfg = Release|Any CPU + {06C25AF5-D63F-4007-8796-C4BA27940EBA}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -266,6 +280,7 @@ Global {43DE02A5-DD13-42D1-9BF9-434E706B8500} = {30D8F44D-4B6E-4980-8D1F-29D1A64F438C} {BF1054BD-DBD7-4D78-B99A-73FDC1362EA5} = {77DF6642-7863-4D67-BAEE-217EC2D99894} {759EE53D-EECA-4054-A17F-4172B0EC2015} = {D72703E6-B021-4360-B1EE-0E99999B5899} - {DF0FDCFD-2601-4D60-A7F5-198D39DBE57B} = {2F43D186-C7D5-4AB1-B821-4D595CA2ECB3} + {59F64DD2-DF30-4F78-A3B7-2AB6A769ED6C} = {30D8F44D-4B6E-4980-8D1F-29D1A64F438C} + {06C25AF5-D63F-4007-8796-C4BA27940EBA} = {77DF6642-7863-4D67-BAEE-217EC2D99894} EndGlobalSection EndGlobal diff --git a/aidlc-docs/active-features.md b/aidlc-docs/active-features.md index 2f2020b..36736b6 100644 --- a/aidlc-docs/active-features.md +++ b/aidlc-docs/active-features.md @@ -3,11 +3,11 @@ | Type | Name | Status | Branch | Affected Components | Session Start | |------|------|--------|--------|---------------------|---------------| | Feature | SlpModularCms.Api Implementation (slp-modular-cms-api) | ✅ Complete | unknown | Core, Identity, Availability, Shell | 2026-06-07 | -| Feature | CMS Frontend (cms-frontend) | ✅ Complete | unknown | Frontend, Identity (Auth), Availability | 2026-06-16 | +| Feature | CMS Frontend (cms-frontend) | ✅ Complete (Build and Test en Operations gesloten 2026-11-16) | unknown | Frontend, Identity (Auth), Availability | 2026-06-16 | | Feature | Master CMS Module (master-cms-module) | ✅ Complete | unknown | Modules, Availability | 2026-06-26 | -| Feature | Tech Debt Backlog (tech-debt-backlog) | 🔵 Inception | unknown | Modules.Master, Frontend | 2026-07-01 | +| Feature | Tech Debt Backlog (tech-debt-backlog) | 🔵 Doorlopende backlog (bewust open) | unknown | Modules.Master, Frontend | 2026-07-01 | | Feature | Local Dev Master/Slave Setup (local-dev-master-slave-setup) | ✅ Complete | unknown | Modules.Master, Api, Frontend | 2026-07-02 | -| Feature | Gitea Deployment Workflow (gitea-deployment-workflow) | 🟡 Operations (wacht op CI-proef en eerste test-deploy) | feature/gitea-deployment-workflow | CI/CD, Api (hosting/config), Core, Modules, Frontend (build), Docs | 2026-07-27 | +| Feature | Gitea Deployment Workflow (gitea-deployment-workflow) | ✅ Complete (CI en test-deploys draaien; productiecontrole in de gezamenlijke checklist, 2026-11-16) | feature/gitea-deployment-workflow | CI/CD, Api (hosting/config), Core, Modules, Frontend (build), Docs | 2026-07-27 | | Feature | SlpSoftware Production API (slpsoftware-api) | ✅ Complete | feature/slpsoftware-api | Clients (new Api.SlpSoftware), Modules (new Offerings module + Tests), Core (CmsHost), CI/CD (retargeted to Api.SlpSoftware) | 2026-08-02 | | Feature | Andrea's site hosting (andreaslop-site-hosting) | ✅ Complete (gemerged naar master via PR #11, 2026-11-10; ASF-productie op IIS apart) | feature/andreaslop-site-hosting | Core (CmsHost, CSP, static content), Clients (new Api.AndreaSlopFotografie), Frontend (theme), CI/CD | 2026-11-06 | | Bug | [cms-admin-nine-points](bugs/cms-admin-nine-points/bug-fix.md) | ✅ Complete (gemerged via PR #11, 2026-11-10) | feature/andreaslop-site-hosting | Core (auth, invitations), Identity, Availability, Frontend | 2026-11-08 | @@ -16,3 +16,11 @@ | Bug | [owner-cannot-promote-requester-identity](bugs/owner-cannot-promote-requester-identity/bug-fix.md) | ✅ Complete (gemerged via PR #11, 2026-11-10) | feature/identity-email-notifications | Identity (UsersController) | 2026-11-08 | | Bug | [availability-gate-blocks-website-and-admin](bugs/availability-gate-blocks-website-and-admin/bug-fix.md) | ✅ Complete (gemerged via PR #11, 2026-11-10) | feature/identity-email-notifications | Availability (middleware) | 2026-11-09 | | Bug | [setup-page-after-failed-status-read](bugs/setup-page-after-failed-status-read/bug-fix.md) | ✅ Complete (gemerged via PR #11, 2026-11-10) | feature/identity-email-notifications | Frontend (router guard, login), Identity (Setup limiter) | 2026-11-09 | +| Feature | Contact Forms Module (contact-forms-module) | ✅ Afgesloten 2026-11-16 (U1 t/m U12 gebouwd, Build and Test gesloten, Operations in de [gezamenlijke productie-checklist](../docs/release-checklist-productie.md); contactformulier door Bryan op test geaccepteerd; productie wacht op Bryans go) | feature/contact-forms-module | Modules (new Contact + Tests, Offerings category), Core (OnRejected, availability gate marker), Frontend (admin Berichten) | 2026-11-09 | +| Feature | [Offering banners (offering-banners)](features/offering-banners/overview.md) | ✅ Afgesloten 2026-11-16 (op test; buiten AI-DLC gebouwd en achteraf gedocumenteerd) | feature/contact-forms-module | Modules.Offerings (banner met positie top/bottom), openapi, Frontend (admin Aanbiedingen > Banner) | 2026-11-12 | +| Feature | [Offering schedule (offering-schedule)](features/offering-schedule/overview.md) | ✅ Afgesloten 2026-11-16 (op test; buiten AI-DLC gebouwd en achteraf gedocumenteerd) | feature/contact-forms-module | Modules.Offerings (aan/uit en van/tot per pakket, `/offerings/all`), openapi, Frontend (admin pakketformulier en -lijst) | 2026-11-15 | +| Feature | [Website SEO (website-seo)](features/website-seo/overview.md) | ✅ Afgesloten 2026-11-16 (op SLP-test; productie vraagt `Website__NoIndex=false` en `Website__PublicBaseUrl`, zie de productie-checklist) | feature/contact-forms-module | Core (Hosting/Website), Modules.Offerings (index-markers), Api.SlpSoftware (appsettings) | 2026-11-11 | +| Feature | [CI bouwt en test alleen het master-CMS (ci-master-pipeline)](features/ci-master-pipeline/overview.md) | ✅ Afgesloten 2026-11-16 (buiten AI-DLC gebouwd en achteraf gedocumenteerd) | feature/contact-forms-module | CI/CD (workflow, slnf, rooktest), Core (Website:Mode), Api (alle modules), Tests (ASF-testproject opgeheven) | 2026-11-15 | +| Feature | [ASF: host injecteert in voorgerenderde pagina's (asf-host-injection)](features/asf-host-injection/plan.md) | ✅ Gebouwd en op test (afgesloten 2026-11-16; ASF-productie op IIS is een apart, later plan) | feature/contact-forms-module | Core (Hosting/Website), Modules.Offerings, docs | 2026-11-15 | +| Feature | [Vertaalbestanden backend (translation-files)](../docs/translation-files.md) | ✅ Afgesloten 2026-11-16 (stappen 1-8, docs; buiten AI-DLC gebouwd; goedgekeurd door Bryan via SLS-Main; productie via de checklist) | feature/contact-forms-module | Core (Texts, Email, Identity, Hosting), Modules.Availability, Modules.Offerings | 2026-11-15 | +| Bug | [theme-toggle-first-click](bugs/theme-toggle-first-click/bug-fix.md) | ✅ Complete (niet gecommit/gemerged; buiten AI-DLC gebouwd; oorzaak niet in een echte browser nagebootst) | feature/contact-forms-module | Frontend (useTheme, index.html) | 2026-11-15 | diff --git a/aidlc-docs/bugs/theme-toggle-first-click/bug-fix.md b/aidlc-docs/bugs/theme-toggle-first-click/bug-fix.md new file mode 100644 index 0000000..7906dc7 --- /dev/null +++ b/aidlc-docs/bugs/theme-toggle-first-click/bug-fix.md @@ -0,0 +1,43 @@ +# Bug Fix: the first click on the theme toggle does nothing + +- **Slug**: theme-toggle-first-click +- **Status**: Complete (pending deploy; built outside the AI-DLC flow, documented afterwards) +- **Issue**: None (reported by Bryan) +- **Branch**: feature/contact-forms-module +- **Started**: unknown +- **Documentation Language**: English +- **Conversation Language**: Dutch (user language) + +## Report + +In the admin, the first click on the light/dark toggle sometimes changed nothing visible; only the second click switched the theme. + +## Root Cause + +The `useTheme` hook (`frontend/src/hooks/useTheme.ts`) kept its own state, initialised from `localStorage` (`cms-theme`) or else from the OS preference (`prefers-color-scheme`). What is actually shown is decided by the class (`light` / `dark`) on ``, which the start script in `frontend/index.html` sets before React runs. The two were not the same source: when the hook's state and the class on `` differed, the first click flipped the hook's state and applied *that* theme, which could be the theme already shown, so nothing visible happened. + +Two ways they could differ, both visible in the old code: + +1. The start script in `index.html` took any stored value as a class name (`s ? s : ...`), while the hook only accepted `light` or `dark`. A stored value such as `system` put the class `system` on `` (no theme at all) while the hook fell back to the OS preference. +2. Every toggle (desktop sidebar, mobile overlay) called `useTheme()` and so had its own state; flipping one left the others stale, so the next click on another toggle could re-apply the theme already shown. + +**Not reproduced in a real browser.** The cause was derived from reading the old code; the only evidence is that the new tests fail against the old hook (reported by the developer; not re-run for this document). Which of the two cases (or another) happened in the browser session that was reported is not known. + +## The Fix + +- `useTheme.ts`: one source of truth, the class on ``, read through `useSyncExternalStore`. If the page carries neither class, the stored value or OS preference is applied right away, so the reported state and what is shown cannot differ. `toggleTheme` flips what is shown now, stores it (inside `try/catch`, since storage can be unavailable), applies it and notifies every subscriber, so all toggles on the page share one state. +- `index.html`: the start script accepts only `light` or `dark` from storage; anything else falls back to the OS preference. + +## Verification + +**Path used**: Automated test framework (`frontend/src/hooks/useTheme.test.ts`, new block `first click`, 4 tests): with the OS preferring light and with it preferring dark and nothing stored or applied, the first click flips the shown theme; an unusable stored value (`system`) with class `system` on `` still flips from what is shown; when the shown theme differs from the stored one the toggle follows the shown one and stores the new value; two toggles on one page stay in step. + +**Before the fix**: according to the developer, the new tests fail against the old hook. Not re-run for this document. **After the fix**: not re-run for this document either. + +**Not verified**: behaviour in a real browser (no manual reproduction before or after the fix). + +## Result + +- **PR(s)**: None +- **Commit(s)**: commit "CMS: één bannerlijst met Locatie, SLP-thema, thema-schakelaar" on feature/contact-forms-module (2026-11-15) +- **Completed**: 2026-11-15 (documentation) diff --git a/aidlc-docs/features/asf-host-injection/plan.md b/aidlc-docs/features/asf-host-injection/plan.md new file mode 100644 index 0000000..14697da --- /dev/null +++ b/aidlc-docs/features/asf-host-injection/plan.md @@ -0,0 +1,61 @@ +# Host injection into ASF's prerendered pages (asf-host-injection) + +- **Slug**: asf-host-injection +- **Type**: Feature, **proposal; not approved, build not started** +- **Status**: **Built** on `feature/contact-forms-module` (commits 7d66944, a136615, ef4fb9d, 4baadf3 and the one after it; tests green locally), **not yet deployed**: needs the website build with the markers and `Website__PublicBaseUrl=https://test.andreaslop.nl` in the ASF-test env file. Before: plan agreed with the ASF session (their counterpart: `AndreaSlopFotografie-packages/aidlc-docs/features/asf-cms-host-injection/plan.md`, section "Host contract"). Bryan accepted the approach (neutral list first, styled cards after hydration; the host writes the list HTML) on 2026-11-15 but said **not to start building yet**: he first reads the plan and finds out whether .NET 10 can run on the hosting package (hosting bundle or self-contained). +- **Affected components (planned)**: `SlpModularCms.Core` (`Hosting/Website`: generalise `IndexHtmlInjector`, hook in `PrerenderedSiteMiddleware`), `SlpModularCms.Modules.Offerings` (marker providers), `scripts/smoke-site.sh`, docs +- **Documented**: 2026-11-15 +- **Documentation Language**: English +- **Conversation Language**: Dutch (user language) + +## Why + +Bryan's hosting package has one entry per website: the CMS host is that entry and serves the website, the prerendered pages and `/admin`. So ASF in production also runs entirely through Kestrel (IIS passes every request on, serves no static files and caches no HTML). Packages, banners and (later) gallery data can therefore be written into the prerendered HTML by the host: visible to crawlers within about a minute of a CMS change, without a nightly build. A rebuild webhook stays an option only for build-processed gallery images. + +## Host contract (agreed with ASF) + +All markers are found in one pass; a page without markers and without the authored address is still served as a plain static file. **Fail-open everywhere**: missing marker = nothing; invalid data or a provider failure = the baked page is served. + +| Marker | Host behaviour | +|---|---| +| `…` | Replace the content between the markers by a simple crawlable list from the live offerings (C# template following ASF's "Neutral HTML spec" and their golden files; everything HTML-encoded). The markers stay. | +| `…`, `…` | Same, from the live banner of that position as `