The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.
TypeScript budget-trackercollaborativedockeritinerarymcp-serveroffline-firstopen-sourceopenstreetmappacking-listpwareal-timeself-hostedselfhostedtraveltravel-apptravel-journaltravel-plannertripitwanderlog
fix(tags): keep a trip's tags when the member who created them deletes their account
Maurice22c3381044c9
diff --git a/server/src/db/repositories/Tags.repository.ts b/server/src/db/repositories/Tags.repository.tsindex 777e558e5..a166bf469 100644--- a/server/src/db/repositories/Tags.repository.ts+++ b/server/src/db/repositories/Tags.repository.ts@@ -49,6 +49,8 @@ type PlaceTagsKyselyDB = Pick<DB, 'place_tags'>;/** `tags` alone, for the reads that name their columns. */type TagsKyselyDB = Pick<DB, 'tags'>;+type TagsWithTripsKyselyDB = Pick<DB, 'tags' | 'trips'>;+/*** `place_tags` joined to `places` for TP46 (`trips.service.ts::copy`'s* place-tags read). The `trip_id` the caller passes stays `number | string`@@ -239,6 +241,22 @@ export class TagsRepository extends TrekRepository<Tags> {return tag ? (toRow(tag) as TagRow) : null;}+ /**+ * Hands the trip tags a user created to each trip's owner, so deleting the+ * user does not take a tag the whole trip uses (and its place_tags) with it.+ * The user's personal tags are left alone.+ */+ async handTripTagsToTripOwners(userId: number): Promise<void> {+ await this.kysely<TagsWithTripsKyselyDB>()+ .updateTable('tags')+ .set((eb) => ({+ user_id: eb.selectFrom('trips').select('trips.user_id').whereRef('trips.id', '=', 'tags.trip_id'),+ }))+ .where('user_id', '=', userId)+ .where('trip_id', 'is not', null)+ .execute();+ }+// ---------------------------------------------------------------------------// Plan 3c Task 4 (`PlacesService.create`/`applyUpdate`, PL5/PL12/PL13) —// `place_tags` writes. `PlaceTagsKyselyDB` above documents why Kysely.diff --git a/server/src/nest/auth/auth.module.ts b/server/src/nest/auth/auth.module.tsindex c4c7e1962..3893b2108 100644--- a/server/src/nest/auth/auth.module.ts+++ b/server/src/nest/auth/auth.module.ts@@ -31,6 +31,7 @@ import { SessionsModule } from '../sessions/sessions.module';import { buildStorageUploadOptions } from '../storage/storage-upload.factory';import { StorageModule } from '../storage/storage.module';import { StorageService } from '../storage/storage.service';+import { TagsModule } from '../tags/tags.module';import { TokensModule } from '../tokens/tokens.module';import { TripMembershipModule } from '../trip-membership/trip-membership.module';import { AuthPublicController } from './auth-public.controller';@@ -99,6 +100,8 @@ import { MulterModule } from '@nestjs/platform-express';AppConfigModule,TokensModule,BudgetModule,+ // TripTagsService: the trip tags of a deleted user stay with the trip.+ TagsModule,// MaintenanceRepository: UserCleanupService's UC1 plugin-table erasure.MaintenanceModule,// AppSettings/Users: AuthService/UserProfileService each pass their owndiff --git a/server/src/nest/auth/user-cleanup.service.ts b/server/src/nest/auth/user-cleanup.service.tsindex 0b3a6a30a..4d78f8d7e 100644--- a/server/src/nest/auth/user-cleanup.service.ts+++ b/server/src/nest/auth/user-cleanup.service.ts@@ -29,6 +29,7 @@ import { UnitOfWork } from '../database/unit-of-work';import { pluginsDataRoot } from '../plugins/paths';import { enqueueHookUserDataErasures } from '../plugins/user-erasure-enqueue';import { StorageReleaseService } from '../storage/storage-release.service';+import { TripTagsService } from '../tags/trip-tags.service';import { InjectRepository } from '@mikro-orm/nestjs';import { Injectable } from '@nestjs/common';@@ -75,6 +76,7 @@ export class UserCleanupService {@InjectRepository(PluginUserErasureQueue)private readonly pluginUserErasureQueueRepo: PluginUserErasureQueueRepository,private readonly release: StorageReleaseService,+ private readonly tripTags: TripTagsService,) {}/**@@ -173,6 +175,7 @@ export class UserCleanupService {await this.tripMembersRepo.clearInvitedBy(userId); // UC4 — converted (Plan 4 Task 1)await this.budgetItemsRepo.clearPaidByUser(userId); // UC5 — Plan 3e Task 2, converted.await this.settlementsRepo.clearCreatedBy(userId);+ await this.tripTags.handToTripOwners(userId);await this.budget.removeUserFromBudgetItems(userId);await this.shareTokensRepo.deleteByCreator(userId); // UC6 — converted (Plan 3h Task 6)await this.journeyShareTokensRepo.deleteByCreatedBy(userId); // UC7 — converted (Plan 3g Task 4)diff --git a/server/src/nest/tags/tags.module.ts b/server/src/nest/tags/tags.module.tsindex f34e636b7..2f85686f9 100644--- a/server/src/nest/tags/tags.module.ts+++ b/server/src/nest/tags/tags.module.ts@@ -41,7 +41,7 @@ import { Module } from '@nestjs/common';// PROVIDERS only, and a missing entry here would leave tags.* answering// PERMISSION_DENIED with no other symptom.providers: [TagsService, TagWritesService, TripTagsService, TagsMcp, TripTagsMcp, TagsRpc],- // For in-container consumers (TagsRpc).- exports: [TagsService],+ // For in-container consumers (TagsRpc, and the account deletion for TripTagsService).+ exports: [TagsService, TripTagsService],})export class TagsModule {}diff --git a/server/src/nest/tags/trip-tags.service.ts b/server/src/nest/tags/trip-tags.service.tsindex d9f4be09a..3fec1c744 100644--- a/server/src/nest/tags/trip-tags.service.ts+++ b/server/src/nest/tags/trip-tags.service.ts@@ -47,6 +47,11 @@ export class TripTagsService {private readonly uow: UnitOfWork,) {}+ /** Before a user is deleted: the trip tags they created stay with each trip, under its owner. */+ async handToTripOwners(userId: number): Promise<void> {+ await this.tags.handTripTagsToTripOwners(userId);+ }+/** The REST caller of a tag write: its event skips the socket that made the request. */restWriter(tripId: string, user: User, socketId: string | undefined): TripWriter {return restTripWriter(this.realtime, tripId, user, socketId);diff --git a/server/tests/helpers/plugin-host.ts b/server/tests/helpers/plugin-host.tsindex 6217fbefc..0c4d44597 100644--- a/server/tests/helpers/plugin-host.ts+++ b/server/tests/helpers/plugin-host.ts@@ -559,6 +559,7 @@ export async function createPluginRpcHostParts(await createTestPluginsRepo(db),await createTestPluginUserErasureQueueRepo(db),{ releaseValues: async () => [] } as never,+ { handToTripOwners: async () => {} } as never,),permissions,realtime,diff --git a/server/tests/unit/db/repositories/Tags.repository.test.ts b/server/tests/unit/db/repositories/Tags.repository.test.tsindex 41a39575c..308d72d94 100644--- a/server/tests/unit/db/repositories/Tags.repository.test.ts+++ b/server/tests/unit/db/repositories/Tags.repository.test.ts@@ -431,6 +431,25 @@ describe('TagsRepository: the tags a trip owns', () => {expect((await tags.listByUser(user.id)).map((row) => row.trip_id)).toEqual([null]);expect((await tags.findByIdAndUser(personal.id, user.id))?.trip_id).toBeNull();});++ it('TRIPTAGREPO-005: handTripTagsToTripOwners moves the user’s trip tags to each trip’s owner and leaves the rest', async () => {+ const { user: owner } = createUser(testDb);+ const { user: otherOwner } = createUser(testDb, { username: 'other_owner' });+ const { user: member } = createUser(testDb, { username: 'tag_member' });+ const trip = createTrip(testDb, owner.id);+ const other = createTrip(testDb, otherOwner.id);+ const onTrip = await makeTag(t, member.id, { trip: trip.id, name: 'Beach' });+ const onOther = await makeTag(t, member.id, { trip: other.id, name: 'Museum' });+ const ownersTag = await makeTag(t, owner.id, { trip: trip.id, name: 'Food' });+ const personal = createTag(testDb, member.id, { name: 'personal' });++ await tags.handTripTagsToTripOwners(member.id);++ expect((await tags.findByIdAndTrip(onTrip.id, trip.id))?.user_id).toBe(owner.id);+ expect((await tags.findByIdAndTrip(onOther.id, other.id))?.user_id).toBe(otherOwner.id);+ expect((await tags.findByIdAndTrip(ownersTag.id, trip.id))?.user_id).toBe(owner.id);+ expect(await tags.findByIdAndUser(personal.id, member.id)).toStrictEqual(rawTag(personal.id));+ });});describe('TagsRepository.findByIds (PL2)', () => {diff --git a/server/tests/unit/nest/admin.service.test.ts b/server/tests/unit/nest/admin.service.test.tsindex cc21fdc8b..fa7993cb9 100644--- a/server/tests/unit/nest/admin.service.test.ts+++ b/server/tests/unit/nest/admin.service.test.ts@@ -174,6 +174,7 @@ beforeAll(async () => {await createTestPluginsRepo(testDb),await createTestPluginUserErasureQueueRepo(testDb),{ releaseValues: async () => [] } as never,+ { handToTripOwners: async () => {} } as never,);auth = new AuthService(permissions,diff --git a/server/tests/unit/nest/admin.version-notification.test.ts b/server/tests/unit/nest/admin.version-notification.test.tsindex 6acef40ac..d477bcec9 100644--- a/server/tests/unit/nest/admin.version-notification.test.ts+++ b/server/tests/unit/nest/admin.version-notification.test.ts@@ -137,6 +137,7 @@ beforeAll(async () => {await createTestPluginsRepo(testDb),await createTestPluginUserErasureQueueRepo(testDb),{ releaseValues: async () => [] } as never,+ { handToTripOwners: async () => {} } as never,);auth = new AuthService(permissions,diff --git a/server/tests/unit/nest/auth.service.test.ts b/server/tests/unit/nest/auth.service.test.tsindex 410792bf4..55a5e1f25 100644--- a/server/tests/unit/nest/auth.service.test.ts+++ b/server/tests/unit/nest/auth.service.test.ts@@ -162,6 +162,7 @@ beforeAll(async () => {await createTestPluginsRepo(testDb),await createTestPluginUserErasureQueueRepo(testDb),{ releaseValues: async () => [] } as never,+ { handToTripOwners: async () => {} } as never,),mailerStub,new EphemeralTokenService(),diff --git a/server/tests/unit/nest/budget.service.db.test.ts b/server/tests/unit/nest/budget.service.db.test.tsindex d8de90f8c..fb57311f1 100644--- a/server/tests/unit/nest/budget.service.db.test.ts+++ b/server/tests/unit/nest/budget.service.db.test.ts@@ -155,7 +155,7 @@ beforeAll(async () => {);membersSvc = new TripMembersService(budget,- new UserCleanupService(new MaintenanceRepository(dbsEm!), budget, await createTestUnitOfWork(testDb), await createTestUsersRepo(testDb), await createTestTripMembersRepo(testDb), await createTestBudgetItemsRepo(testDb), await createTestBudgetSettlementsRepo(testDb), await createTestJourneyShareTokensRepo(testDb), await createTestJourneysRepo(testDb), await createTestJourneyEntriesRepo(testDb), await createTestJourneyContributorsRepo(testDb), await createTestShareTokensRepo(testDb), await createTestPluginsRepo(testDb), await createTestPluginUserErasureQueueRepo(testDb), { releaseValues: () => [] } as never),+ new UserCleanupService(new MaintenanceRepository(dbsEm!), budget, await createTestUnitOfWork(testDb), await createTestUsersRepo(testDb), await createTestTripMembersRepo(testDb), await createTestBudgetItemsRepo(testDb), await createTestBudgetSettlementsRepo(testDb), await createTestJourneyShareTokensRepo(testDb), await createTestJourneysRepo(testDb), await createTestJourneyEntriesRepo(testDb), await createTestJourneyContributorsRepo(testDb), await createTestShareTokensRepo(testDb), await createTestPluginsRepo(testDb), await createTestPluginUserErasureQueueRepo(testDb), { releaseValues: () => [] } as never, { handToTripOwners: async () => {} } as never),new PermissionsService(await createTestAppSettingsRepo(testDb), await createTestUnitOfWork(testDb)),new RealtimeService(),notificationsStub(),diff --git a/server/tests/unit/nest/oidc.service.test.ts b/server/tests/unit/nest/oidc.service.test.tsindex d7dfb756b..690891e2d 100644--- a/server/tests/unit/nest/oidc.service.test.ts+++ b/server/tests/unit/nest/oidc.service.test.ts@@ -187,6 +187,7 @@ beforeAll(async () => {await createTestPluginsRepo(testDb),await createTestPluginUserErasureQueueRepo(testDb),{ releaseValues: async () => [] } as never,+ { handToTripOwners: async () => {} } as never,),mailerStub,new EphemeralTokenService(),diff --git a/server/tests/unit/nest/passkey.service.test.ts b/server/tests/unit/nest/passkey.service.test.tsindex ebe7289a3..92d5be07c 100644--- a/server/tests/unit/nest/passkey.service.test.ts+++ b/server/tests/unit/nest/passkey.service.test.ts@@ -163,6 +163,7 @@ beforeAll(async () => {await createTestPluginsRepo(testDb),await createTestPluginUserErasureQueueRepo(testDb),{ releaseValues: async () => [] } as never,+ { handToTripOwners: async () => {} } as never,),mailerStub,new EphemeralTokenService(),diff --git a/server/tests/unit/nest/trip-members.service.test.ts b/server/tests/unit/nest/trip-members.service.test.tsindex 6f7ddaf48..02ddc4ff6 100644--- a/server/tests/unit/nest/trip-members.service.test.ts+++ b/server/tests/unit/nest/trip-members.service.test.ts@@ -140,6 +140,7 @@ beforeAll(async () => {await createTestPluginsRepo(testDb),await createTestPluginUserErasureQueueRepo(testDb),{ releaseValues: async () => [] } as never,+ { handToTripOwners: async () => {} } as never,),new PermissionsService(await createTestAppSettingsRepo(testDb), await createTestUnitOfWork(testDb)),realtime,diff --git a/server/tests/unit/nest/trip-read-model.service.test.ts b/server/tests/unit/nest/trip-read-model.service.test.tsindex 4a12ab1c3..446bb65ba 100644--- a/server/tests/unit/nest/trip-read-model.service.test.ts+++ b/server/tests/unit/nest/trip-read-model.service.test.ts@@ -257,6 +257,7 @@ beforeAll(async () => {await createTestPluginsRepo(testDb),await createTestPluginUserErasureQueueRepo(testDb),{ releaseValues: async () => [] } as never,+ { handToTripOwners: async () => {} } as never,),new PermissionsService(await createTestAppSettingsRepo(testDb), await createTestUnitOfWork(testDb)),realtime,diff --git a/server/tests/unit/nest/trips.service.test.ts b/server/tests/unit/nest/trips.service.test.tsindex 7697c3cb4..d8ce58dd0 100644--- a/server/tests/unit/nest/trips.service.test.ts+++ b/server/tests/unit/nest/trips.service.test.ts@@ -305,7 +305,7 @@ beforeAll(async () => {(await sharedTestOrm(testDb)).em,new SettingsService(await createTestUnitOfWork(testDb), await createTestAppSettingsRepo(testDb), await createTestSettingsRepo(testDb), membership.get(TripMembershipService)), { copyOverrides: async () => {} } as never,);- membersSvc = new TripMembersService(budgetSvc, new UserCleanupService(new MaintenanceRepository(dbsEm!), budgetSvc, await createTestUnitOfWork(testDb), await createTestUsersRepo(testDb), await createTestTripMembersRepo(testDb), await createTestBudgetItemsRepo(testDb), await createTestBudgetSettlementsRepo(testDb), await createTestJourneyShareTokensRepo(testDb), await createTestJourneysRepo(testDb), await createTestJourneyEntriesRepo(testDb), await createTestJourneyContributorsRepo(testDb), await createTestShareTokensRepo(testDb), await createTestPluginsRepo(testDb), await createTestPluginUserErasureQueueRepo(testDb), { releaseValues: async () => [] } as never), new PermissionsService(await createTestAppSettingsRepo(testDb), await createTestUnitOfWork(testDb)), realtime, notificationsStub(), await createTestUnitOfWork(testDb), await createTestTripsRepo(testDb), await createTestTripMembersRepo(testDb), await createTestUsersRepo(testDb));+ membersSvc = new TripMembersService(budgetSvc, new UserCleanupService(new MaintenanceRepository(dbsEm!), budgetSvc, await createTestUnitOfWork(testDb), await createTestUsersRepo(testDb), await createTestTripMembersRepo(testDb), await createTestBudgetItemsRepo(testDb), await createTestBudgetSettlementsRepo(testDb), await createTestJourneyShareTokensRepo(testDb), await createTestJourneysRepo(testDb), await createTestJourneyEntriesRepo(testDb), await createTestJourneyContributorsRepo(testDb), await createTestShareTokensRepo(testDb), await createTestPluginsRepo(testDb), await createTestPluginUserErasureQueueRepo(testDb), { releaseValues: async () => [] } as never, { handToTripOwners: async () => {} } as never), new PermissionsService(await createTestAppSettingsRepo(testDb), await createTestUnitOfWork(testDb)), realtime, notificationsStub(), await createTestUnitOfWork(testDb), await createTestTripsRepo(testDb), await createTestTripMembersRepo(testDb), await createTestUsersRepo(testDb));readModelSvc = new TripReadModelService(await createTestTripsRepo(testDb), membersSvc, daysSvc, accommodationsSvc, budgetSvc,new PackingService(diff --git a/server/tests/unit/nest/user-cleanup.service.test.ts b/server/tests/unit/nest/user-cleanup.service.test.tsindex 2b42f0082..67e0f8d06 100644--- a/server/tests/unit/nest/user-cleanup.service.test.ts+++ b/server/tests/unit/nest/user-cleanup.service.test.ts@@ -21,6 +21,7 @@ import { PluginUserConfig } from '../../../src/db/entities/PluginUserConfig.entiimport { PluginUserErasureQueue } from '../../../src/db/entities/PluginUserErasureQueue.entity';import { Plugins } from '../../../src/db/entities/Plugins.entity';import { ShareTokens } from '../../../src/db/entities/ShareTokens.entity';+import { Tags } from '../../../src/db/entities/Tags.entity';import { TrekPhotos } from '../../../src/db/entities/TrekPhotos.entity';import { TripMembers } from '../../../src/db/entities/TripMembers.entity';import { TripPhotos } from '../../../src/db/entities/TripPhotos.entity';@@ -38,9 +39,12 @@ import { BudgetService } from '../../../src/nest/budget/budget.service';import { ExchangeRatesService } from '../../../src/nest/budget/exchange-rates.service';import { PermissionsService } from '../../../src/nest/permissions/permissions.service';import { RealtimeService } from '../../../src/nest/realtime/realtime.service';+import { TagsModule } from '../../../src/nest/tags/tags.module';+import { TripTagsService } from '../../../src/nest/tags/trip-tags.service';import { budgetRepoArgs } from '../../helpers/budget-repos';import { createTestBudgetSettlementsRepo } from '../../helpers/budget-repos';import { createUser, createTrip } from '../../helpers/factories';+import { makePlace, makeTag, tagPlace } from '../../helpers/factories/places';import { countRows, deleteRows, findRow, findRows, insertRow, updateRows } from '../../helpers/factories/rows';import { makeShareToken } from '../../helpers/factories/trips';import { createTestBudgetItemsRepo } from '../../helpers/files-repos';@@ -57,6 +61,7 @@ import {} from '../../helpers/share-repos';import { releaseNothing } from '../../helpers/storage-release';import { resetTestDb } from '../../helpers/test-db';+import { createTestModule, type TestModule } from '../../helpers/test-module';import type { TestOrm } from '../../helpers/test-orm';import {createTestUnitOfWork,@@ -95,6 +100,7 @@ vi.mock('../../../src/nest/plugins/paths', () => ({ pluginsDataRoot: () => dataRlet em: EntityManager;let budget: BudgetService;let svc: UserCleanupService;+let tagsModule: TestModule;/** What a deletion hands on: the avatar, released by its own suites. */const cleanupRelease = releaseNothing();beforeAll(async () => {@@ -110,6 +116,7 @@ beforeAll(async () => {await createTestUnitOfWork(testDb),...(await budgetRepoArgs(testDb)),);+ tagsModule = await createTestModule({ db: testDb, imports: [TagsModule] });svc = new UserCleanupService(new MaintenanceRepository(em),budget,@@ -130,6 +137,7 @@ beforeAll(async () => {await createTestPluginsRepo(testDb),await createTestPluginUserErasureQueueRepo(testDb),cleanupRelease,+ tagsModule.get(TripTagsService),);});@@ -173,7 +181,8 @@ beforeEach(async () => {dataRootRef.value = path.join(os.tmpdir(), 'trek-user-cleanup-absent');});-afterAll(() => {+afterAll(async () => {+ await tagsModule.close();testDb.close();});@@ -267,6 +276,7 @@ describe('erasePluginUserData', () => {await createTestPluginsRepo(slim),await createTestPluginUserErasureQueueRepo(slim),{ releaseValues: async () => [] } as never,+ { handToTripOwners: async () => {} } as never,);await expect(slimSvc.erasePluginUserData(1)).rejects.toThrow(/no such table: plugin_user_config/);@@ -315,6 +325,23 @@ describe('deleteUserCompletely', () => {}).toEqual({ from_user_id: payer.id, to_user_id: owner.id, amount: 12.5, created_by_user_id: null });});+ it('USER-CLEANUP-013: deleting a member keeps the trip tags they created, on every place, under the trip owner', async () => {+ const { user: owner } = createUser(testDb);+ const { user: member } = createUser(testDb, { username: 'tagger' });+ const trip = createTrip(testDb, owner.id);+ await insertRow(orm, TripMembers, { trip: trip.id, user: member.id });+ const tripTag = await makeTag(orm, member.id, { trip: trip.id, name: 'Beach' });+ const personal = await makeTag(orm, member.id, { name: 'Mine' });+ const place = await makePlace(orm, trip.id);+ await tagPlace(orm, place.id, [tripTag.id]);++ await svc.deleteUserCompletely(member.id);++ expect((await findRow(orm, Tags, { id: tripTag.id }))?.user_id).toBe(owner.id);+ expect(await findRow(orm, Tags, { id: personal.id })).toBeNull();+ expect(await countRows(orm, Tags, { place_tags_inverse: place.id })).toBe(1);+ });+it('USER-CLEANUP-007: deletes their journeys and the entries they authored elsewhere', async () => {const { user: owner } = createUser(testDb);const { user: victim } = createUser(testDb, { username: 'victim' });@@ -438,6 +465,7 @@ describe('deleteUserCompletely', () => {await createTestPluginsRepo(testDb),await createTestPluginUserErasureQueueRepo(testDb),cleanupRelease,+ { handToTripOwners: async () => {} } as never,).deleteUserCompletely(victim.id),).rejects.toThrow('boom');