mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 02:14:05 +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:
@@ -8,6 +8,7 @@ import { Places } from '../../db/entities/Places.entity';
|
||||
import { Reservations } from '../../db/entities/Reservations.entity';
|
||||
import { ShareTokens } from '../../db/entities/ShareTokens.entity';
|
||||
import { Trips } from '../../db/entities/Trips.entity';
|
||||
import { AddonsModule } from '../addons/addons.module';
|
||||
import { McpSharedModule } from '../mcp-shared/mcp-shared.module';
|
||||
import { PermissionsModule } from '../permissions/permissions.module';
|
||||
import { PlacePhotosModule } from '../place-photos/place-photos.module';
|
||||
@@ -29,6 +30,8 @@ import { Module } from '@nestjs/common';
|
||||
// for the same reason).
|
||||
@Module({
|
||||
imports: [
|
||||
// The shared sections follow the trip's addons (ShareService.getSharedTripData).
|
||||
AddonsModule,
|
||||
McpSharedModule,
|
||||
SettingsModule,
|
||||
PermissionsModule,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { ADDON_IDS } from '../../addons';
|
||||
import { BudgetItems } from '../../db/entities/BudgetItems.entity';
|
||||
import { CollabMessages } from '../../db/entities/CollabMessages.entity';
|
||||
import { DayAssignments } from '../../db/entities/DayAssignments.entity';
|
||||
@@ -19,6 +20,7 @@ import type { ReservationsRepository } from '../../db/repositories/Reservations.
|
||||
import type { ShareTokensRepository } from '../../db/repositories/ShareTokens.repository';
|
||||
import type { TripsRepository, TripAccess } from '../../db/repositories/Trips.repository';
|
||||
import type { User } from '../../types';
|
||||
import { AddonsService } from '../addons/addons.service';
|
||||
import { UnitOfWork } from '../database/unit-of-work';
|
||||
import { PermissionsService } from '../permissions/permissions.service';
|
||||
import { PlacePhotoCacheService } from '../place-photos/place-photo-cache.service';
|
||||
@@ -214,6 +216,7 @@ export class ShareService {
|
||||
@InjectRepository(PackingItems) private readonly packingItems: PackingItemsRepository,
|
||||
@InjectRepository(BudgetItems) private readonly budgetItems: BudgetItemsRepository,
|
||||
@InjectRepository(CollabMessages) private readonly collabMessages: CollabMessagesRepository,
|
||||
private readonly addons: AddonsService,
|
||||
) {}
|
||||
|
||||
/** SH-AP1 — the same `TripsRepository.findAccessible` every other access-primitive call in this plan reuses. */
|
||||
@@ -346,12 +349,15 @@ export class ShareService {
|
||||
const trip = await this.trips.findPublicForShare(tripId);
|
||||
if (!trip) return null;
|
||||
|
||||
// A section whose addon is off for this trip is not shared, whatever the
|
||||
// link allows, and the page is told so through the same flags it reads.
|
||||
const on = async (addonId: string) => this.addons.isEnabledForTrip(tripId, addonId);
|
||||
const permissions = {
|
||||
share_map: !!shareRow.share_map,
|
||||
share_bookings: !!shareRow.share_bookings,
|
||||
share_packing: !!shareRow.share_packing,
|
||||
share_budget: !!shareRow.share_budget,
|
||||
share_collab: !!shareRow.share_collab,
|
||||
share_packing: !!shareRow.share_packing && (await on(ADDON_IDS.PACKING)),
|
||||
share_budget: !!shareRow.share_budget && (await on(ADDON_IDS.BUDGET)),
|
||||
share_collab: !!shareRow.share_collab && (await on(ADDON_IDS.COLLAB)),
|
||||
share_travel_only: !!shareRow.share_travel_only,
|
||||
share_hide_images: !!shareRow.share_hide_images,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user