mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-25 22:27:32 +00:00
fix(addons): give a member who joins a trip with an opened addon a new MCP session
A trip that switched on an addon the instance has off ended the MCP sessions of the members it had then, but somebody added later, or joining through the invite link, kept a session without that addon's tools. Joining now ends it too.
This commit is contained in:
@@ -110,6 +110,15 @@ export class TripAddonsService {
|
||||
for (const userId of new Set([...(ownerId === null ? [] : [ownerId]), ...memberIds])) revokeUserSessions(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Somebody joined the trip. While it has an addon on that the instance has off, their MCP
|
||||
* session attached its tools without that addon's, so it is ended the same way.
|
||||
*/
|
||||
async reattachJoinedMember(tripId: number, userId: number): Promise<void> {
|
||||
const opened = (await this.effectiveTripAddons(tripId)).some((addon) => addon.enabled && !addon.instanceEnabled);
|
||||
if (opened) revokeUserSessions(userId);
|
||||
}
|
||||
|
||||
/** A copied trip keeps the choices of the trip it came from. Runs inside the copy's transaction. */
|
||||
async copyOverrides(fromTripId: number, toTripId: number): Promise<void> {
|
||||
await this.overrides.copyForTrip(fromTripId, toTripId);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { TripInviteTokens } from '../../db/entities/TripInviteTokens.entity';
|
||||
import { Trips } from '../../db/entities/Trips.entity';
|
||||
import { AddonsModule } from '../addons/addons.module';
|
||||
import { AppConfigModule } from '../app-config/app-config.module';
|
||||
import { AuditModule } from '../audit/audit.module';
|
||||
import { DemoModule } from '../common/demo.module';
|
||||
@@ -32,6 +33,7 @@ import { Module } from '@nestjs/common';
|
||||
AppConfigModule,
|
||||
RealtimeModule,
|
||||
DemoModule,
|
||||
AddonsModule,
|
||||
MikroOrmModule.forFeature([TripInviteTokens, Trips]),
|
||||
],
|
||||
controllers: [TripInviteLinkController, TripInviteController],
|
||||
|
||||
@@ -2,6 +2,7 @@ import { TripInviteTokens } from '../../db/entities/TripInviteTokens.entity';
|
||||
import type { TripInviteTokensRepository } from '../../db/repositories/TripInviteTokens.repository';
|
||||
import type { TripAccess } from '../../db/repositories/Trips.repository';
|
||||
import type { User } from '../../types';
|
||||
import { TripAddonsService } from '../addons/trip-addons.service';
|
||||
import { forbidden } from '../common/domain-error';
|
||||
import { UnitOfWork } from '../database/unit-of-work';
|
||||
import { PermissionsService } from '../permissions/permissions.service';
|
||||
@@ -49,6 +50,7 @@ export class TripInviteService {
|
||||
private readonly membership: TripMembershipService,
|
||||
private readonly uow: UnitOfWork,
|
||||
@InjectRepository(TripInviteTokens) private readonly tripInviteTokens: TripInviteTokensRepository,
|
||||
private readonly tripAddons: TripAddonsService,
|
||||
) {}
|
||||
|
||||
async verifyTripAccess(tripId: string, userId: number) {
|
||||
@@ -137,6 +139,8 @@ export class TripInviteService {
|
||||
/** Join the resolved trip as the current (authenticated, non-guest) user.
|
||||
* invited_by is null — they joined via a link, not a personal invite. */
|
||||
async join(tripId: number, userId: number) {
|
||||
return await this.membership.joinTripAsMember(tripId, userId, null);
|
||||
const result = await this.membership.joinTripAsMember(tripId, userId, null);
|
||||
if (result.joined) await this.tripAddons.reattachJoinedMember(tripId, userId);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Users } from '../../db/entities/Users.entity';
|
||||
import type { UsersRepository } from '../../db/repositories/Users.repository';
|
||||
import type { User } from '../../types';
|
||||
import { AddonsService } from '../addons/addons.service';
|
||||
import { TripAddonsService } from '../addons/trip-addons.service';
|
||||
import { BudgetService } from '../budget/budget.service';
|
||||
import { restTripWriter, type TripWriter } from '../common/trip-writer';
|
||||
import { RealtimeService } from '../realtime/realtime.service';
|
||||
@@ -30,6 +31,7 @@ export class TripMemberWritesService {
|
||||
private readonly realtime: RealtimeService,
|
||||
@InjectRepository(Users) private readonly users: UsersRepository,
|
||||
private readonly addons: AddonsService,
|
||||
private readonly tripAddons: TripAddonsService,
|
||||
) {}
|
||||
|
||||
/** REST's writer for a roster change: the room minus the tab that sent the request. */
|
||||
@@ -41,6 +43,7 @@ export class TripMemberWritesService {
|
||||
async addMember(tripId: string | number, identifier: string, tripOwnerId: number, writer: TripWriter) {
|
||||
const result = await this.roster.addMember(tripId, identifier, tripOwnerId, writer.userId);
|
||||
writer.events.emit('member:added', { member: result.member });
|
||||
await this.tripAddons.reattachJoinedMember(Number(tripId), result.targetUserId);
|
||||
// The invitation names who sent it by name, as the route does with its session user.
|
||||
const actor = { id: writer.userId, username: (await this.users.findById(writer.userId))?.username ?? '' };
|
||||
this.roster.notifyInvite(String(tripId), actor, result.targetUserId, result.tripTitle, result.member.email);
|
||||
|
||||
Reference in New Issue
Block a user