Give three more admin surfaces back to the domains that own them

default-user-settings, notification-preferences and oidc leave AdminController.
The first two were pure pass-throughs on AdminService that did nothing but
forward and cast; the third had its SQL there for a domain that already had a
module of its own. AdminService loses SettingsService and
NotificationPreferencesService entirely.

Two things came out of the move rather than going into it.

The OIDC lockout guard now has tests. It refuses to clear the SSO config while
password login is disabled — otherwise the instance has no SSO to log in through
and no password form either — and nothing covered that branch before, because it
sat among admin tests that only exercised the happy path.

The admin e2e app had to learn about the split. It assembles AdminModule alone,
so the moved routes 404'd there while working in production; it now imports the
three domains too. That is the same failure mode the module-provider guards
catch for RPC classes, and it is worth knowing that an e2e app which builds a
subset will find it first.

Also fixes the audit route note: audit-log stays on AdminController on purpose.
AuthModule imports AuditModule, so an admin-gated controller in AuditModule
closes a cycle — the same trap the addons toggles hit.
This commit is contained in:
Maurice
2026-08-09 20:54:13 +02:00
committed by Maurice
parent d4a1601855
commit 8a09f55571
17 changed files with 393 additions and 179 deletions
+49 -1
View File
@@ -1,8 +1,15 @@
import { Controller, Get, Query, Req, Res } from '@nestjs/common';
import { Body, Controller, Get, HttpException, Put, Query, Req, Res, UseGuards } from '@nestjs/common';
import type { Request, Response } from 'express';
import { readEnv } from '../../app-config';
import { OidcService, OIDC_STATE_TTL_MS } from './oidc.service';
import { cookieOptions } from '../common/cookie';
import { AdminGuard } from '../auth/admin.guard';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
import { CurrentUser } from '../auth/current-user.decorator';
import type { User } from '../../types';
import { AuditService } from '../audit/audit.service';
import { getClientIp } from '../audit/client-ip';
import { AdminOidcUpdateDto } from '../admin/admin.dto';
const OIDC_STATE_COOKIE = 'trek_oidc_state';
@@ -165,3 +172,44 @@ export class OidcController {
res.json({ token: result.token });
}
}
/**
* /api/admin/oidc — the SSO configuration.
*
* Two routes that sat on AdminController with their SQL in AdminService, for a domain
* that already had a module. They read and write the same five app_settings keys the
* login flow next door consumes, so they belong here; the lockout guard that refuses
* to remove the config while password login is off lives with them in OidcService.
*
* The path, the {error,status} envelope and the audit action are unchanged.
*/
@Controller('api/admin/oidc')
@UseGuards(JwtAuthGuard, AdminGuard)
export class AdminOidcController {
constructor(
private readonly oidc: OidcService,
private readonly audit: AuditService,
) {}
@Get()
get() {
return this.oidc.getOidcSettings();
}
@Put()
update(@CurrentUser() user: User, @Body() body: AdminOidcUpdateDto, @Req() req: Request) {
const result = this.oidc.updateOidcSettings(body);
if (result.error) {
throw new HttpException({ error: result.error }, result.status || 400);
}
// Only whether an issuer was set, never the value: the details column is readable
// by every admin and the issuer identifies the customer's IdP tenant.
this.audit.writeAudit({
userId: user.id,
action: 'admin.oidc_update',
ip: getClientIp(req),
details: { issuer_set: !!body.issuer },
});
return { success: true };
}
}