mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 13:10:29 +00:00
fix(server): the booked night settles in one pass, and the sibling paths seat it too
The audit over the 4.3.1 release found the seating rule reading a night by one value and its neighbours by another, so two nights on one day never agreed: the migration reported moves that changed nothing, flipped the pair on the next run and dropped the road drawn between them, and in the service every notes edit swapped them. One rule now lives in accommodations/night-seat.ts, measures every night by its own check-in, breaks a tie by the booking made first, and carries the vias; the service, the reseat migration and a trip date change all seat through it, the last of which used to append the night at the end of its day again. An account created by a first SSO login writes the user.register row the password path writes. Tests cover the equal and absent check-ins, the date change, the booking form path and a day that is nothing but its night.
This commit is contained in:
@@ -167,6 +167,18 @@ export class OidcController {
|
||||
|
||||
const result = this.oidc.findOrCreateUser(userInfo, config, pending.inviteToken);
|
||||
if ('error' in result) return f('/login?oidc_error=' + result.error);
|
||||
if (result.created) {
|
||||
// An account the callback just made is a registration, the way a password
|
||||
// signup is (auth-public.controller): the same row, plus the way in. Without
|
||||
// it an admin reading user.register for who got an account never sees the
|
||||
// SSO ones, and the log looks complete while it is not.
|
||||
this.audit.writeAudit({
|
||||
userId: result.user.id,
|
||||
action: 'user.register',
|
||||
ip: getClientIp(req),
|
||||
details: { username: result.user.username, email: result.user.email, role: result.user.role, method: 'oidc' },
|
||||
});
|
||||
}
|
||||
if (result.roleChange) {
|
||||
// The claim mapping changing someone's privileges is a security event, and
|
||||
// the row is written here because this is where the client IP is. The claim
|
||||
|
||||
@@ -611,7 +611,7 @@ export class OidcService implements OnModuleDestroy {
|
||||
userInfo: OidcUserInfo,
|
||||
config: OidcConfig,
|
||||
inviteToken?: string,
|
||||
): { user: User; roleChange?: OidcRoleChange } | { error: string } {
|
||||
): { user: User; roleChange?: OidcRoleChange; created?: true } | { error: string } {
|
||||
// Defense-in-depth for direct callers — the controller redirects on a
|
||||
// missing email before it ever calls this; the same code flows through its
|
||||
// `oidc_error=' + result.error` pass-through if reached here.
|
||||
@@ -752,7 +752,9 @@ export class OidcService implements OnModuleDestroy {
|
||||
// is_guest, created_at, …) instead of a hand-built partial — same shape
|
||||
// the existing-user branch returns.
|
||||
user = this.db.prepare('SELECT * FROM users WHERE id = ?').get(Number(result.lastInsertRowid)) as User;
|
||||
return { user };
|
||||
// The one branch that makes an account. The caller writes the registration row
|
||||
// off this, so it has to be set here and nowhere else.
|
||||
return { user, created: true };
|
||||
} catch (err) {
|
||||
if (err === inviteRaceError) {
|
||||
console.warn(`[OIDC] Invite token ${inviteToken?.slice(0, 8)}... exhausted — concurrent callback won the last slot`);
|
||||
|
||||
Reference in New Issue
Block a user