mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 21:11:14 +00:00
3f38621024
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.
54 lines
2.5 KiB
TypeScript
54 lines
2.5 KiB
TypeScript
import { Addons } from '../../../src/db/entities/Addons.entity';
|
|
import { AppSettings } from '../../../src/db/entities/AppSettings.entity';
|
|
import { Settings } from '../../../src/db/entities/Settings.entity';
|
|
import { TripAddonOverrides } from '../../../src/db/entities/TripAddonOverrides.entity';
|
|
import type { FactoryOrm } from './context';
|
|
import { findRow, upsertRow } from './rows';
|
|
|
|
/** Writes an instance-wide setting (`app_settings`), replacing any earlier value. */
|
|
export async function setAppSetting(orm: FactoryOrm, key: string, value: string): Promise<void> {
|
|
await upsertRow(orm, AppSettings, { key, value });
|
|
}
|
|
|
|
/** The instance-wide setting's value, or null when it is unset. */
|
|
export async function readAppSetting(orm: FactoryOrm, key: string): Promise<string | null> {
|
|
return (await findRow(orm, AppSettings, { key }))?.value ?? null;
|
|
}
|
|
|
|
/** Writes one of the user's own settings (`settings`, unique per user and key), replacing any earlier value. */
|
|
export async function setUserSetting(orm: FactoryOrm, userId: number, key: string, value: string): Promise<void> {
|
|
await upsertRow(orm, Settings, { user: userId, key, value });
|
|
}
|
|
|
|
/** The user's setting, or null when it is unset. */
|
|
export async function readUserSetting(orm: FactoryOrm, userId: number, key: string): Promise<string | null> {
|
|
return (await findRow(orm, Settings, { user: userId, key }))?.value ?? null;
|
|
}
|
|
|
|
/**
|
|
* Flips an addon the way the admin panel does. An addon the instance does not
|
|
* know yet is created as a global one named after its id; an existing one
|
|
* keeps its name, type and order and only changes `enabled`.
|
|
*/
|
|
export async function setAddonEnabled(orm: FactoryOrm, addonId: string, enabled: boolean): Promise<void> {
|
|
await upsertRow(orm, Addons, { id: addonId, name: addonId, type: 'global', enabled }, ['enabled']);
|
|
}
|
|
|
|
/**
|
|
* The trip owner's choice for one trip addon on one trip, the row
|
|
* `PUT /api/trips/:tripId/addons/:addonId` writes: on or off whatever the
|
|
* instance says.
|
|
*/
|
|
export async function setTripAddon(orm: FactoryOrm, tripId: number, addonId: string, enabled: boolean): Promise<void> {
|
|
await upsertRow(orm, TripAddonOverrides, { trip: tripId, addon: addonId, enabled: enabled ? 1 : 0 }, ['enabled']);
|
|
}
|
|
|
|
/** Collab's chat, notes, polls, links and next-up panels are opt-out app settings, not addon rows. */
|
|
export async function setCollabFeature(
|
|
orm: FactoryOrm,
|
|
feature: 'chat' | 'notes' | 'polls' | 'links' | 'whatsnext',
|
|
enabled: boolean,
|
|
): Promise<void> {
|
|
await setAppSetting(orm, `collab_${feature}_enabled`, enabled ? 'true' : 'false');
|
|
}
|