mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 15:17:30 +00:00
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:
@@ -1,3 +1,5 @@
|
||||
import { ADDON_IDS } from '../../../addons';
|
||||
import { AddonsService } from '../../addons/addons.service';
|
||||
import { JwtAuthGuard } from '../../auth-core/jwt-auth.guard';
|
||||
import { toRowId } from '../../common/row-id';
|
||||
import { TripAccessService } from '../../trip-membership/trip-access.service';
|
||||
@@ -55,6 +57,13 @@ const VIEWS: ReadonlySet<string> = new Set([
|
||||
'files',
|
||||
'todos',
|
||||
]);
|
||||
/** The views that belong to a trip addon: a trip that has it off gets no columns there. */
|
||||
const VIEW_ADDON: Readonly<Record<string, string>> = {
|
||||
costs: ADDON_IDS.BUDGET,
|
||||
packing: ADDON_IDS.PACKING,
|
||||
todos: ADDON_IDS.PACKING,
|
||||
files: ADDON_IDS.DOCUMENTS,
|
||||
};
|
||||
const TONES: ReadonlySet<string> = new Set(['default', 'success', 'warn', 'danger']);
|
||||
const MAX_COLUMNS = 20;
|
||||
const MAX_ACTIONS = 10;
|
||||
@@ -140,6 +149,7 @@ export class ViewContributionsController {
|
||||
constructor(
|
||||
private readonly hooks: PluginHooks,
|
||||
private readonly trips: TripAccessService,
|
||||
private readonly addons: AddonsService,
|
||||
) {}
|
||||
|
||||
@Get(':view/:tripId')
|
||||
@@ -153,6 +163,8 @@ export class ViewContributionsController {
|
||||
const userId = req.user?.id;
|
||||
if (tripId === null || userId == null || !(await this.trips.findAccessible(tripId, userId)))
|
||||
return { contributions: [] };
|
||||
const addonId = VIEW_ADDON[view];
|
||||
if (addonId && !(await this.addons.isEnabledForTrip(tripId, addonId))) return { contributions: [] };
|
||||
|
||||
const ids = this.hooks.providersOf('tableContributor');
|
||||
const perProvider = await Promise.all(
|
||||
|
||||
Reference in New Issue
Block a user