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
refactor(auth): hand a deleted user's trip tags over through the maintenance repository
Maurice6e0c2b894d65
diff --git a/server/src/db/repositories/MaintenanceRepository.ts b/server/src/db/repositories/MaintenanceRepository.tsindex 311089770..e3615db17 100644--- a/server/src/db/repositories/MaintenanceRepository.ts+++ b/server/src/db/repositories/MaintenanceRepository.ts@@ -54,4 +54,21 @@ export class MaintenanceRepository {.execute(`DELETE FROM ${table} WHERE user_id = ?`, [userId], 'run', this.em.getTransactionContext());}}++ /**+ * Before a user is deleted: the trip tags they created pass to each trip's+ * owner, so a tag the whole trip uses keeps its place_tags. The user's+ * personal tags are left to the delete.+ */+ async handTripTagsToTripOwners(userId: number): Promise<void> {+ this.validateRequestContext();+ await this.em+ .getConnection()+ .execute(+ 'UPDATE tags SET user_id = (SELECT trips.user_id FROM trips WHERE trips.id = tags.trip_id) WHERE user_id = ? AND trip_id IS NOT NULL',+ [userId],+ 'run',+ this.em.getTransactionContext(),+ );+ }}diff --git a/server/src/db/repositories/Tags.repository.ts b/server/src/db/repositories/Tags.repository.tsindex a166bf469..777e558e5 100644--- a/server/src/db/repositories/Tags.repository.ts+++ b/server/src/db/repositories/Tags.repository.ts@@ -49,8 +49,6 @@ 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`@@ -241,22 +239,6 @@ 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 3893b2108..c4c7e1962 100644--- a/server/src/nest/auth/auth.module.ts+++ b/server/src/nest/auth/auth.module.ts@@ -31,7 +31,6 @@ 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';@@ -100,8 +99,6 @@ 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 4d78f8d7e..e22b0a79b 100644--- a/server/src/nest/auth/user-cleanup.service.ts+++ b/server/src/nest/auth/user-cleanup.service.ts@@ -29,7 +29,6 @@ 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';@@ -76,7 +75,6 @@ export class UserCleanupService {@InjectRepository(PluginUserErasureQueue)private readonly pluginUserErasureQueueRepo: PluginUserErasureQueueRepository,private readonly release: StorageReleaseService,- private readonly tripTags: TripTagsService,) {}/**@@ -175,7 +173,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.maintenance.handTripTagsToTripOwners(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 2f85686f9..f34e636b7 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, and the account deletion for TripTagsService).- exports: [TagsService, TripTagsService],+ // For in-container consumers (TagsRpc).+ exports: [TagsService],})export class TagsModule {}diff --git a/server/src/nest/tags/trip-tags.service.ts b/server/src/nest/tags/trip-tags.service.tsindex 3fec1c744..d9f4be09a 100644--- a/server/src/nest/tags/trip-tags.service.ts+++ b/server/src/nest/tags/trip-tags.service.ts@@ -47,11 +47,6 @@ 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 36ec2ec58..d240b26dc 100644--- a/server/tests/helpers/plugin-host.ts+++ b/server/tests/helpers/plugin-host.ts@@ -559,7 +559,6 @@ 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 308d72d94..41a39575c 100644--- a/server/tests/unit/db/repositories/Tags.repository.test.ts+++ b/server/tests/unit/db/repositories/Tags.repository.test.ts@@ -431,25 +431,6 @@ 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 502d757db..e17ad7f90 100644--- a/server/tests/unit/nest/admin.service.test.ts+++ b/server/tests/unit/nest/admin.service.test.ts@@ -174,7 +174,6 @@ 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 d477bcec9..6acef40ac 100644--- a/server/tests/unit/nest/admin.version-notification.test.ts+++ b/server/tests/unit/nest/admin.version-notification.test.ts@@ -137,7 +137,6 @@ 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 fedd02db4..f37a311b0 100644--- a/server/tests/unit/nest/auth.service.test.ts+++ b/server/tests/unit/nest/auth.service.test.ts@@ -162,7 +162,6 @@ 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 fb57311f1..d8de90f8c 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, { handToTripOwners: async () => {} } 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),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 690891e2d..d7dfb756b 100644--- a/server/tests/unit/nest/oidc.service.test.ts+++ b/server/tests/unit/nest/oidc.service.test.ts@@ -187,7 +187,6 @@ 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 92d5be07c..ebe7289a3 100644--- a/server/tests/unit/nest/passkey.service.test.ts+++ b/server/tests/unit/nest/passkey.service.test.ts@@ -163,7 +163,6 @@ 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 02ddc4ff6..6f7ddaf48 100644--- a/server/tests/unit/nest/trip-members.service.test.ts+++ b/server/tests/unit/nest/trip-members.service.test.ts@@ -140,7 +140,6 @@ 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 446bb65ba..4a12ab1c3 100644--- a/server/tests/unit/nest/trip-read-model.service.test.ts+++ b/server/tests/unit/nest/trip-read-model.service.test.ts@@ -257,7 +257,6 @@ 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 044c2f30e..7697c3cb4 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), {} as never, {} 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), 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 67e0f8d06..f6f6c0fad 100644--- a/server/tests/unit/nest/user-cleanup.service.test.ts+++ b/server/tests/unit/nest/user-cleanup.service.test.ts@@ -39,8 +39,6 @@ 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';@@ -61,7 +59,6 @@ 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,@@ -100,7 +97,6 @@ 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 () => {@@ -116,7 +112,6 @@ beforeAll(async () => {await createTestUnitOfWork(testDb),...(await budgetRepoArgs(testDb)),);- tagsModule = await createTestModule({ db: testDb, imports: [TagsModule] });svc = new UserCleanupService(new MaintenanceRepository(em),budget,@@ -137,7 +132,6 @@ beforeAll(async () => {await createTestPluginsRepo(testDb),await createTestPluginUserErasureQueueRepo(testDb),cleanupRelease,- tagsModule.get(TripTagsService),);});@@ -181,8 +175,7 @@ beforeEach(async () => {dataRootRef.value = path.join(os.tmpdir(), 'trek-user-cleanup-absent');});-afterAll(async () => {- await tagsModule.close();+afterAll(() => {testDb.close();});@@ -276,7 +269,6 @@ 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/);@@ -465,7 +457,6 @@ describe('deleteUserCompletely', () => {await createTestPluginsRepo(testDb),await createTestPluginUserErasureQueueRepo(testDb),cleanupRelease,- { handToTripOwners: async () => {} } as never,).deleteUserCompletely(victim.id),).rejects.toThrow('boom');