Some checks failed
CD / Build and push images (push) Successful in 3m16s
CI / Lint, typecheck, test (push) Successful in 3m5s
CD / Deploy to Test (push) Successful in 13s
CD / Smoke tests against Test (push) Failing after 3m35s
CD / Promote to Int (push) Has been skipped
CI / Auth e2e pack (push) Successful in 5m6s
CI / Import/export fidelity gate (push) Successful in 43s
CI / Build container images (push) Has been skipped
When the api runs against a database without the setup.completedAt marker, a global SetupGuard answers every non-exempt route with 503 setup_required; only /setup/*, health probes, and the session routes stay reachable. The wizard steps (POST /setup/admin|instance|smtp| registration|complete) write straight to their production homes; the Site Admin step signs its creator in, later steps require that session. Completing sets the marker and locks every step permanently (410, also across restarts, and not reopenable via PATCH /admin/settings). SMTP entered in the wizard is verified with a live delivery test first (failure blocks the step with the transport error as detail) and then persisted to the new env-backed secret store: a mode-600 dotenv file on the new `secrets` volume (SECRETS_FILE). Explicit container env always wins over the store; empty compose-passed strings count as unset. The mail transport now resolves lazily through SmtpConfigService so wizard changes apply without a restart. SETUP_ADMIN_* env pre-seeds the whole wizard at boot for automated deploys; a backfill migration marks instances that already have a Site Admin as completed, and seed/vitest global-setup do the same for fixture databases. The setup e2e suite provisions its own fresh database (CREATE DATABASE + migrate deploy) per run. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EwZ4jR4KFAPvpjWevfUGX1
37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
|
|
import { PrismaService } from '../prisma/prisma.service';
|
|
|
|
/**
|
|
* Whether the instance still requires the first-run setup wizard
|
|
* (issue #80). Setup is pending until `setup.completedAt` is written —
|
|
* by the wizard's complete step, by env pre-seeding, by the fixture seed,
|
|
* or by the backfill migration for instances that predate the wizard.
|
|
*
|
|
* Reads the row directly instead of going through InstanceSettingsService:
|
|
* that service caches misses, and a request hitting a still-pending
|
|
* instance must not freeze the pending state past an external seed (the
|
|
* e2e stacks seed a running api). Completion is permanent, so a completed
|
|
* answer is remembered for the process lifetime and costs nothing per
|
|
* request; while pending, the instance serves almost no traffic anyway.
|
|
*/
|
|
@Injectable()
|
|
export class SetupStateService {
|
|
private completed = false;
|
|
|
|
constructor(private readonly prisma: PrismaService) {}
|
|
|
|
async isPending(): Promise<boolean> {
|
|
if (this.completed) return false;
|
|
const row = await this.prisma.instanceSetting.findUnique({
|
|
where: { key: 'setup.completedAt' },
|
|
select: { value: true },
|
|
});
|
|
if (typeof row?.value === 'string' && row.value) {
|
|
this.completed = true;
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
}
|