feat(server): let a trip owner switch trip addons for one trip

A trip can now turn a trip addon (lists, costs, documents, collab, road
trip, tours) on or off for itself, whatever the instance switch says. No
row in the new trip_addon_overrides table means the trip follows the
instance; a row is the owner's choice. Going back to the instance setting
deletes the row, and no addon data is touched either way.

- GET/PUT /api/trips/:tripId/addons[/:addonId] (every member reads, the
  owner writes) and the MCP tools get_trip_addons and set_trip_addon, on
  the shared tripAddons contract; tripAddons:changed tells the members.
- Every trip-scoped addon surface asks the trip: REST through
  TripAddonGuard, MCP through a per-call gate on the named or pinned trip,
  plugin RPC and events, the share link, the offline bundle, reminders,
  doc sync, the assistant (tools, keep_attached_file), booking costs, the
  trip summary prompt, and the cross-trip tour reads (library, Atlas
  stats, collection save).
- Routes without a trip open while the addon is on in any of the user's
  trips. Switching an addon on that the instance has off ends the members'
  MCP sessions so they reconnect with its tools.
- A copied trip takes its owner's choices along.

Behaviour changes: an anonymous call to an addon route that is off now
gets 401 instead of 404, and with an instance switch off the packing,
todo and files plugin RPC methods, the files MCP tools, todo reminder
mails, core plugin events, plugin view contributions, the share link's
lists, costs and chat sections and the offline bundle's lists follow it.
This commit is contained in:
Maurice
2026-11-21 13:23:02 +01:00
parent 2f7b8357ce
commit 3f38621024
203 changed files with 3710 additions and 498 deletions
@@ -2,6 +2,7 @@ import { ADDON_IDS } from '../../addons';
import type { User } from '../../types';
import { AddonGuard } from '../addons/addon.guard';
import { RequireAddon } from '../addons/require-addon.decorator';
import { TripAddonGuard } from '../addons/trip-addon.guard';
import { CurrentUser } from '../auth-core/current-user.decorator';
import { JwtAuthGuard } from '../auth-core/jwt-auth.guard';
import { rowId } from '../common/row-id.pipe';
@@ -64,7 +65,10 @@ import type { Request } from 'express';
* where their documents are going.
*/
@Controller('api/trips/:tripId/docsync')
@UseGuards(AddonGuard, JwtAuthGuard, TripAccessGuard)
// AddonGuard first, on the instance switch alone: the document providers stay bound to it, so a trip
// cannot open doc-sync while the instance has Documents off. TripAddonGuard then refuses a trip
// whose owner switched Documents off for it.
@UseGuards(AddonGuard, JwtAuthGuard, TripAccessGuard, TripAddonGuard)
@RequireAddon(ADDON_IDS.DOCUMENTS, 'Documents')
export class DocSyncController {
private readonly logger = new Logger(DocSyncController.name);
+4 -2
View File
@@ -9,7 +9,7 @@ import {
errorResult,
ok,
} from '../../nest-mcp';
import { addonGate } from '../addons/addon-gate';
import { instanceAddonGate } from '../addons/addon-gate';
import { AddonsService } from '../addons/addons.service';
import { FilesService } from '../files/files.service';
import { DocSyncConfigService } from './doc-sync-config.service';
@@ -19,7 +19,9 @@ import { idSchema } from '@trek/shared';
import { z } from 'zod';
const documentsAddonOn = addonGate(ADDON_IDS.DOCUMENTS);
// The document providers stay bound to the instance's Documents switch, so these tools follow it alone;
// each call still needs Documents on for the trip it names.
const documentsAddonOn = instanceAddonGate(ADDON_IDS.DOCUMENTS);
/**
* The MCP half of document sync, mirroring /api/trips/:tripId/docsync.
+7 -7
View File
@@ -129,16 +129,16 @@ export class DocSyncService {
}
/**
* Whether an admin has closed the door on this binding: the Documents addon
* is off, or the provider it runs against is.
* Whether the door on this binding is closed: Documents off for the instance
* or for the binding's trip, or its provider off (providers follow the instance).
*
* A kill switch, not a failure. Nothing about the binding is written while it
* is off, not its state and not its documents' attempt counters, so it
* resumes exactly where it stopped once the switch is back on. Public because
* a manual run has to refuse before it un-shelves anything.
* A kill switch, not a failure: nothing about the binding is written while it is off
* (not its state, not its documents' attempt counters), so it resumes where it stopped.
* Public because a manual run has to refuse before it un-shelves anything.
*/
async isSwitchedOff(link: Pick<LinkRow, 'provider_id'>): Promise<boolean> {
async isSwitchedOff(link: Pick<LinkRow, 'provider_id' | 'trip_id'>): Promise<boolean> {
if (!(await this.addons.isAddonEnabled(ADDON_IDS.DOCUMENTS))) return true;
if (!(await this.addons.isEnabledForTrip(link.trip_id, ADDON_IDS.DOCUMENTS))) return true;
return !(await this.config.enabledProviderIds()).includes(link.provider_id);
}