mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 08:30:05 +00:00
feat(places): own place identities, duplicate merging and lists linked to a trip
- A user can group the uses of one place (trip places and saved places) into a place identity of their own (user_places, user_place_links). It is personal: it groups their "All places" and is never written into a shared trip or list row. An identity without a use they can still reach is not shown, and one left without links is pruned on their next write and nightly. - Possible duplicates are suggested server side (same provider id, or the same name at the same spot), each pair with what differs and whether the user may merge it. A merge joins two identities in one transaction and can be undone; a dismissed pair does not come back. No trip or list row is deleted or changed. - A trip can link lists (trip_collection_links, needs place_edit and access to the list). A member sees a linked list only with their own access to it; the map layer lists its places and whether each is already in the trip. tripCollections:changed tells the members to read their view again. - REST, MCP tools and client data layer for all of it; migrations on both engines, additive only. - CI: the stage 1 to 2 places-library helper types, and the await-in-loop and non-null counts it had raised.
This commit is contained in:
@@ -7,6 +7,7 @@ import { StorageService } from '../../../src/nest/storage/storage.service';
|
||||
import { makeDayAssignment } from '../../helpers/factories/itinerary';
|
||||
import { makeTag } from '../../helpers/factories/places';
|
||||
import { insertRow, updateRows } from '../../helpers/factories/rows';
|
||||
import { linkTripCollection } from '../../helpers/factories/user-places';
|
||||
import type { CaseGroup, Scene } from './types';
|
||||
import { MikroORM } from '@mikro-orm/core';
|
||||
import type { INestApplication } from '@nestjs/common';
|
||||
@@ -380,6 +381,28 @@ export const plan: CaseGroup = {
|
||||
},
|
||||
expect: ['place:created'],
|
||||
},
|
||||
{
|
||||
// PLC-15: content-free, so every member asks again with their own list rights.
|
||||
tool: 'link_collection_to_trip',
|
||||
needs: ['collection'],
|
||||
args: (s) => ({ tripId: s.trip.id, collection_id: s.collection.id }),
|
||||
rest: {
|
||||
method: 'post',
|
||||
path: (s) => `/api/trips/${s.trip.id}/collections`,
|
||||
body: (s) => ({ collection_id: s.collection.id }),
|
||||
},
|
||||
expect: ['tripCollections:changed'],
|
||||
},
|
||||
{
|
||||
tool: 'unlink_collection_from_trip',
|
||||
needs: ['collection'],
|
||||
setup: async (s, app) => {
|
||||
await linkTripCollection(app.get(MikroORM), s.trip.id, s.collection.id, s.owner.id);
|
||||
},
|
||||
args: (s) => ({ tripId: s.trip.id, collection_id: s.collection.id }),
|
||||
rest: { method: 'delete', path: (s) => `/api/trips/${s.trip.id}/collections/${s.collection.id}` },
|
||||
expect: ['tripCollections:changed'],
|
||||
},
|
||||
{
|
||||
tool: 'create_day_note',
|
||||
args: (s) => ({ tripId: s.trip.id, dayId: s.days[0].id, text: 'Bring the museum pass' }),
|
||||
|
||||
@@ -15,10 +15,12 @@ import { JourneyDomainService } from '../../../src/nest/journey/journey-domain.s
|
||||
import { JourneyRecordedDaysService } from '../../../src/nest/journey/journey-recorded-days.service';
|
||||
import { PhotoCaptureBackfillService } from '../../../src/nest/memories/photo-capture-backfill.service';
|
||||
import { NotificationsService } from '../../../src/nest/notifications/notifications.service';
|
||||
import { PlaceIdentitiesService } from '../../../src/nest/places-library/place-identities.service';
|
||||
import { addCollectionMember } from '../../helpers/factories/collections';
|
||||
import { inContext } from '../../helpers/factories/context';
|
||||
import { addJourneyContributor, linkTripToJourney, makeJourneyEntry } from '../../helpers/factories/journeys';
|
||||
import { createRow, insertRow, updateRows } from '../../helpers/factories/rows';
|
||||
import { linkUserPlace, makeUserPlace } from '../../helpers/factories/user-places';
|
||||
import { addVacayPlanMember } from '../../helpers/factories/vacay';
|
||||
import { holidayCode } from './harness';
|
||||
import type { CaseGroup, ParityCase, RestCall, Scene } from './types';
|
||||
@@ -35,6 +37,25 @@ import { vi } from 'vitest';
|
||||
* that asked, MCP none, so the tab the assistant runs in shows the change.
|
||||
*/
|
||||
const HOLIDAY_CATALOG = "the admin's school holiday catalog is global: no room, and the registry has no event for it";
|
||||
const OWN_PLACES =
|
||||
"changes only the caller's own grouping of All places (D5): no trip place or saved place is written and nobody else sees it, so there is nothing to send";
|
||||
const placeKeys = (s: Scene) => ({ a: `trip:${s.place.id}`, b: `trip:${s.place2.id}` });
|
||||
|
||||
/** The owner's own place holding the scene's first place, for the unlink. */
|
||||
async function ownPlace(s: Scene, app: INestApplication): Promise<void> {
|
||||
const own = await makeUserPlace(ormOf(app), s.owner.id);
|
||||
await linkUserPlace(ormOf(app), s.owner.id, own.id, { place: s.place.id });
|
||||
}
|
||||
|
||||
/** The scene's two places merged by the owner, for the undo. */
|
||||
async function mergedPlaces(s: Scene, app: INestApplication): Promise<void> {
|
||||
const merged = await withRequestContext(ormOf(app), () =>
|
||||
app
|
||||
.get(PlaceIdentitiesService)
|
||||
.merge({ id: s.owner.id, role: 'user' }, `trip:${s.place.id}`, `trip:${s.place2.id}`),
|
||||
);
|
||||
keep(s, 'merge', merged.merge_id);
|
||||
}
|
||||
const TOKEN_ONLY = 'manages a public link token: nothing on any screen follows it live, so there is nothing to send';
|
||||
const onJourney = (s: Scene) => ({ journeyId: s.journey.id });
|
||||
const WINTER = { name: 'Winter', startDate: '2027-02-01', endDate: '2027-02-12' };
|
||||
@@ -1305,6 +1326,38 @@ export const user: CaseGroup = {
|
||||
setup: recordStay,
|
||||
args: (s) => ({ suggestionId: kept(s, 'stay') }),
|
||||
},
|
||||
{
|
||||
tool: 'link_library_places',
|
||||
reason: OWN_PLACES,
|
||||
needs: ['place', 'place2'],
|
||||
args: (s) => ({
|
||||
uses: [
|
||||
{ kind: 'trip', id: s.place.id },
|
||||
{ kind: 'trip', id: s.place2.id },
|
||||
],
|
||||
}),
|
||||
},
|
||||
{
|
||||
tool: 'unlink_library_place',
|
||||
reason: OWN_PLACES,
|
||||
needs: ['place'],
|
||||
setup: ownPlace,
|
||||
args: (s) => ({ kind: 'trip', id: s.place.id }),
|
||||
},
|
||||
{ tool: 'dismiss_library_duplicate', reason: OWN_PLACES, needs: ['place', 'place2'], args: placeKeys },
|
||||
{
|
||||
tool: 'merge_library_places',
|
||||
reason: OWN_PLACES,
|
||||
needs: ['place', 'place2'],
|
||||
args: (s) => ({ leading: `trip:${s.place.id}`, other: `trip:${s.place2.id}` }),
|
||||
},
|
||||
{
|
||||
tool: 'undo_library_merge',
|
||||
reason: OWN_PLACES,
|
||||
needs: ['place', 'place2'],
|
||||
setup: mergedPlaces,
|
||||
args: (s) => ({ merge_id: kept(s, 'merge') }),
|
||||
},
|
||||
{
|
||||
tool: 'create_manual_school_holiday_country',
|
||||
reason: HOLIDAY_CATALOG,
|
||||
|
||||
Reference in New Issue
Block a user