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(packing): anyone on the trip can be put down as the bringer of a shared item, and taken off again (#3098)
Maurice7bbb5a9f71b1
diff --git a/client/src/api/client.ts b/client/src/api/client.tsindex 91aac58fa..056b13662 100644--- a/client/src/api/client.ts+++ b/client/src/api/client.ts@@ -520,7 +520,7 @@ export const packingApi = {reorder: (tripId: number | string, orderedIds: number[]) => apiClient.put(`/trips/${tripId}/packing/reorder`, { orderedIds } satisfies PackingReorderRequest).then(r => r.data),setSharing: (tripId: number | string, id: number, data: PackingSetSharingRequest) => apiClient.put(`/trips/${tripId}/packing/${id}/sharing`, data).then(r => r.data),clone: (tripId: number | string, id: number) => apiClient.post(`/trips/${tripId}/packing/${id}/clone`).then(r => r.data),- addContributor: (tripId: number | string, id: number) => apiClient.post(`/trips/${tripId}/packing/${id}/contributors`).then(r => r.data),+ addContributor: (tripId: number | string, id: number, userId?: number) => apiClient.post(`/trips/${tripId}/packing/${id}/contributors`, userId == null ? undefined : { user_id: userId }).then(r => r.data),removeContributor: (tripId: number | string, id: number, userId: number) => apiClient.delete(`/trips/${tripId}/packing/${id}/contributors/${userId}`).then(r => r.data),getCategoryAssignees: (tripId: number | string) => apiClient.get(`/trips/${tripId}/packing/category-assignees`).then(r => r.data),setCategoryAssignees: (tripId: number | string, categoryName: string, userIds: number[]) => apiClient.put(`/trips/${tripId}/packing/category-assignees/${encodeURIComponent(categoryName)}`, { user_ids: userIds } satisfies PackingCategoryAssigneesRequest).then(r => r.data),diff --git a/client/src/components/Packing/PackingListPanelCategoryGroup.tsx b/client/src/components/Packing/PackingListPanelCategoryGroup.tsxindex 9776fd419..d8f87996a 100644--- a/client/src/components/Packing/PackingListPanelCategoryGroup.tsx+++ b/client/src/components/Packing/PackingListPanelCategoryGroup.tsx@@ -52,7 +52,7 @@ interface KategorieGruppeProps {currentUserId?: numberonSetSharing?: (id: number, visibility: 'common' | 'personal' | 'shared', recipientIds: number[]) => voidonClone?: (id: number) => void- onJoin?: (id: number) => void+ onJoin?: (id: number, userId?: number) => voidonLeave?: (id: number, userId: number) => void// Opens the choice of one sharing tier for the whole list (#2961).onShareCategory?: () => voiddiff --git a/client/src/components/Packing/PackingListPanelItemRow.test.tsx b/client/src/components/Packing/PackingListPanelItemRow.test.tsxindex d231cc5a0..fb9730ba1 100644--- a/client/src/components/Packing/PackingListPanelItemRow.test.tsx+++ b/client/src/components/Packing/PackingListPanelItemRow.test.tsx@@ -1,4 +1,4 @@-// FE-W5ROW-001 to FE-W5ROW-056+// FE-W5ROW-001 to FE-W5ROW-059import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'import type { ComponentProps } from 'react'import { http, HttpResponse } from 'msw'@@ -1084,3 +1084,54 @@ describe('ArtikelZeile — overflow menu', () => {expect(danger.style.background).toBe('rgba(239, 68, 68, 0.1)')})})++describe('ArtikelZeile — who brings a common item (#3098)', () => {+ const handlers = () => ({ onSetSharing: vi.fn(), onClone: vi.fn(), onJoin: vi.fn(), onLeave: vi.fn() })++ it('FE-W5ROW-057: the item menu lists every member and ticks one on as a bringer', () => {+ const h = handlers()+ const { container } = setup({ currentUserId: 1, tripMembers: MEMBERS, ...h })++ fireEvent.click(overflowTrigger(container))+ fireEvent.click(menuButton(container, 'Brought by'))+ fireEvent.click(menuButton(container, 'alice'))++ expect(h.onJoin).toHaveBeenCalledWith(1, 2)+ expect(h.onLeave).not.toHaveBeenCalled()+ })++ it('FE-W5ROW-058: a ticked bringer, the owner included, comes off again', () => {+ const h = handlers()+ const { container } = setup({+ item: buildPackingItem({+ id: 1, name: 'Stove', is_private: 0, owner_id: 1, owner_username: 'owner',+ contributors: [{ user_id: 2, username: 'alice' }],+ } as unknown as Partial<PackingItem>),+ currentUserId: 1, tripMembers: MEMBERS, ...h,+ })++ fireEvent.click(overflowTrigger(container))+ fireEvent.click(menuButton(container, 'Brought by'))+ fireEvent.click(menuButton(container, 'owner'))+ fireEvent.click(menuButton(container, 'alice'))++ expect(h.onLeave).toHaveBeenNthCalledWith(1, 1, 1)+ expect(h.onLeave).toHaveBeenNthCalledWith(2, 1, 2)+ expect(h.onJoin).not.toHaveBeenCalled()+ })++ it('FE-W5ROW-059: a click on the faces opens the menu at the bringers, also when only co-bringers are left', () => {+ const { container } = setup({+ item: buildPackingItem({+ id: 1, name: 'Stove', is_private: 0, owner_id: null, owner_username: null,+ contributors: [{ user_id: 2, username: 'alice' }],+ } as unknown as Partial<PackingItem>),+ currentUserId: 1, tripMembers: MEMBERS, ...handlers(),+ })++ fireEvent.click(screen.getByRole('button', { name: 'brought by alice' }))++ expect(menuButton(container, 'alice')).toBeInTheDocument()+ expect(menuButton(container, 'owner')).toBeInTheDocument()+ })+})diff --git a/client/src/components/Packing/PackingListPanelItemRow.tsx b/client/src/components/Packing/PackingListPanelItemRow.tsxindex bba12331b..06ac9cc09 100644--- a/client/src/components/Packing/PackingListPanelItemRow.tsx+++ b/client/src/components/Packing/PackingListPanelItemRow.tsx@@ -39,7 +39,7 @@ interface ArtikelZeileProps {currentUserId?: numberonSetSharing?: (id: number, visibility: 'common' | 'personal' | 'shared', recipientIds: number[]) => voidonClone?: (id: number) => void- onJoin?: (id: number) => void+ onJoin?: (id: number, userId?: number) => voidonLeave?: (id: number, userId: number) => void/** Draws the hairline above the row; the category group leaves it off its first row. */divider?: boolean@@ -68,6 +68,7 @@ export function ArtikelZeile({ item, tripId, categories, onCategoryChange: _onCaconst bagBox = useAnchoredPosition(bagBtnRef, showBagPicker, { estimatedHeight: 260, offset: 6 })const [showItemMenu, setShowItemMenu] = useState(false)const [showMenuCategories, setShowMenuCategories] = useState(false)+ const [showMenuBringers, setShowMenuBringers] = useState(false)const [bagInlineCreate, setBagInlineCreate] = useState(false)const [bagInlineName, setBagInlineName] = useState('')const itemMenuBtnRef = useRef<HTMLButtonElement>(null)@@ -79,8 +80,13 @@ export function ArtikelZeile({ item, tripId, categories, onCategoryChange: _onCaconst sharedToMe = !!item.is_private && item.owner_id != null && item.owner_id !== currentUserIdconst recipients = item.recipients || []const sharedByMe = !!item.is_private && item.owner_id === currentUserId && recipients.length > 0- const broughtBy = !item.is_private && item.owner_username ? item.owner_username : nullconst canShare = canEdit && !isPlaceholder && !!onSetSharing+ // Who brings a Common item is anyone's call on the trip, not just a pledge for+ // yourself: the menu lists every member to tick on or off (#3098).+ const canPickBringers = canEdit && !isPlaceholder && !item.is_private && tripMembers.length > 0 && !!onJoin && !!onLeave+ const isBringer = (userId: number) => item.owner_id === userId || (item.contributors || []).some(c => c.user_id === userId)+ const toggleBringer = (userId: number) => (isBringer(userId) ? onLeave!(item.id, userId) : onJoin!(item.id, userId))+ const closeItemMenu = () => { setShowItemMenu(false); setShowMenuCategories(false); setShowMenuBringers(false) }const handleToggle = () => togglePackingItem(tripId, item.id, !item.checked)@@ -234,13 +240,23 @@ export function ArtikelZeile({ item, tripId, categories, onCategoryChange: _onCa</span></Tooltip>)}- {!isPlaceholder && broughtBy && (+ {!isPlaceholder && !item.is_private && bringers.length > 0 && (<Tooltip label={t('packing.broughtBy', { name: packingBringerNames(item) })} content={<BringersCard bringers={bringers} />}>- <span className="packing-row-badge" aria-label={t('packing.broughtBy', { name: packingBringerNames(item) })}- style={{ display: 'inline-flex', alignItems: 'center', flexShrink: 0 }}>- <BringerAvatar bringer={bringers[0]} />- {bringers.length > 1 && <MoreBringers count={bringers.length - 1} />}- </span>+ {/* A click on the faces opens the menu right at the bringers (#3098). */}+ {canPickBringers ? (+ <button type="button" className="packing-row-badge" aria-label={t('packing.broughtBy', { name: packingBringerNames(item) })}+ onClick={() => { setShowItemMenu(true); setShowMenuBringers(true) }}+ style={{ display: 'inline-flex', alignItems: 'center', flexShrink: 0, border: 'none', background: 'none', padding: 0, cursor: 'pointer' }}>+ <BringerAvatar bringer={bringers[0]} />+ {bringers.length > 1 && <MoreBringers count={bringers.length - 1} />}+ </button>+ ) : (+ <span className="packing-row-badge" aria-label={t('packing.broughtBy', { name: packingBringerNames(item) })}+ style={{ display: 'inline-flex', alignItems: 'center', flexShrink: 0 }}>+ <BringerAvatar bringer={bringers[0]} />+ {bringers.length > 1 && <MoreBringers count={bringers.length - 1} />}+ </span>+ )}</Tooltip>)}@@ -340,7 +356,7 @@ export function ArtikelZeile({ item, tripId, categories, onCategoryChange: _onCa<div className="packing-row-overflow" style={{ display: 'flex', flexShrink: 0, position: 'relative', ...reveal(active) }}><button type="button"ref={itemMenuBtnRef}- onClick={() => setShowItemMenu(m => !m)}+ onClick={() => (showItemMenu ? closeItemMenu() : setShowItemMenu(true))}title={t('common.showMore')}aria-label={t('common.showMore')} aria-expanded={showItemMenu}style={{ width: 26, height: 26, borderRadius: 7, border: 'none', background: showItemMenu ? 'var(--bg-tertiary)' : 'transparent', cursor: 'pointer', display: 'flex', alignItems: 'center', justifyContent: 'center', color: 'var(--text-faint)', padding: 0 }}@@ -351,7 +367,7 @@ export function ArtikelZeile({ item, tripId, categories, onCategoryChange: _onCaconst rect = itemMenuBtnRef.current?.getBoundingClientRect()return (<>- <div role="presentation" style={{ position: 'fixed', inset: 0, zIndex: 1098 }} onClick={() => { setShowItemMenu(false); setShowMenuCategories(false) }} />+ <div role="presentation" style={{ position: 'fixed', inset: 0, zIndex: 1098 }} onClick={closeItemMenu} /><div className="trek-menu-enter" style={{...POPOVER,position: 'fixed',@@ -407,6 +423,20 @@ export function ArtikelZeile({ item, tripId, categories, onCategoryChange: _onCa</div>)}+ {canPickBringers && (+ <>+ <PopoverItem icon={<HandHelping size={13} />} label={t('packing.bringersTitle')} onClick={() => setShowMenuBringers(v => !v)}+ trailing={showMenuBringers ? <ChevronDown size={13} style={{ color: 'var(--text-faint)', flexShrink: 0 }} /> : <ChevronRight size={13} style={{ color: 'var(--text-faint)', flexShrink: 0 }} />} />+ {showMenuBringers && (+ <div style={{ marginBlock: '2px 4px', marginInlineStart: 18, paddingInlineStart: 6, borderInlineStart: '1px solid var(--border-faint)' }}>+ {tripMembers.map(m => (+ <PopoverItem key={m.id} icon={<BringerAvatar bringer={{ name: m.username, avatar: m.avatar_url ?? m.avatar ?? null }} />} label={m.username} active={isBringer(m.id)} onClick={() => toggleBringer(m.id)} />+ ))}+ </div>+ )}+ </>+ )}+{canShare && onClone && onJoin && onLeave && (<PackingShareControlvariant="menu"diff --git a/client/src/components/Packing/usePackingListPanel.ts b/client/src/components/Packing/usePackingListPanel.tsindex b829c5734..1ed11588f 100644--- a/client/src/components/Packing/usePackingListPanel.ts+++ b/client/src/components/Packing/usePackingListPanel.ts@@ -222,7 +222,7 @@ export function usePackingList({ tripId, items, openImportSignal = 0, addCategorconst handleSetSharing = (id: number, visibility: 'common' | 'personal' | 'shared', recipientIds: number[]) =>setPackingItemSharing(tripId, id, visibility, recipientIds)const handleCloneItem = (id: number) => clonePackingItem(tripId, id)- const handleJoinItem = (id: number) => addPackingContributor(tripId, id)+ const handleJoinItem = (id: number, userId?: number) => addPackingContributor(tripId, id, userId)const handleLeaveItem = (id: number, userId: number) => removePackingContributor(tripId, id, userId)// A whole list at once (#2961), through the same per-item write as above.const categorySharing = usePackingCategorySharing({diff --git a/client/src/store/slices/packingSlice.ts b/client/src/store/slices/packingSlice.tsindex cd0c1c556..3ffc92c84 100644--- a/client/src/store/slices/packingSlice.ts+++ b/client/src/store/slices/packingSlice.ts@@ -21,7 +21,8 @@ export interface PackingSlice {// Three-tier sharing (#858)setPackingItemSharing: (tripId: number | string, id: number, visibility: 'common' | 'personal' | 'shared', recipientIds: number[]) => Promise<void>clonePackingItem: (tripId: number | string, id: number) => Promise<void>- addPackingContributor: (tripId: number | string, id: number) => Promise<void>+ /** Without a userId the caller pledges themselves; with one, that member is put down as a bringer (#3098). */+ addPackingContributor: (tripId: number | string, id: number, userId?: number) => Promise<void>removePackingContributor: (tripId: number | string, id: number, userId: number) => Promise<void>}@@ -141,9 +142,9 @@ export const createPackingSlice = (set: SetState, get: GetState): PackingSlice =}},- addPackingContributor: async (tripId, id) => {+ addPackingContributor: async (tripId, id, userId) => {try {- const result = await packingApi.addContributor(tripId, id)+ const result = await packingApi.addContributor(tripId, id, userId)set(state => ({ packingItems: state.packingItems.map(i => i.id === id ? result.item : i) }))} catch (err: unknown) {notify(getApiErrorMessage(err, 'Error joining item'), 'error')diff --git a/server/src/db/repositories/PackingItems.repository.ts b/server/src/db/repositories/PackingItems.repository.tsindex be9d799f7..e5a179f0a 100644--- a/server/src/db/repositories/PackingItems.repository.ts+++ b/server/src/db/repositories/PackingItems.repository.ts@@ -407,6 +407,12 @@ export class PackingItemsRepository extends TrekRepository<PackingItems> {await this.nativeUpdate({ id }, { is_private, ...data, updated_at: currentTimestamp(platform) });}+ /** `removeContributor` on a Common item's owner (#3098): the item stays on the list, nobody's in particular. */+ async clearOwner(id: number): Promise<void> {+ const platform = this.getEntityManager().getPlatform();+ await this.nativeUpdate({ id }, { owner: null, updated_at: currentTimestamp(platform) });+ }+/** PK16 (`setItemSharing`'s replace-all) — `DELETE FROM packing_item_recipients WHERE item_id = ?`. */async deleteRecipientsForItem(item_id: number): Promise<void> {await this.db().deleteFrom('packing_item_recipients').where('item_id', '=', item_id).execute();diff --git a/server/src/nest/packing/packing.controller.ts b/server/src/nest/packing/packing.controller.tsindex ee5f96100..f4d5767c3 100644--- a/server/src/nest/packing/packing.controller.ts+++ b/server/src/nest/packing/packing.controller.ts@@ -14,6 +14,7 @@ import {PackingReorderDto,PackingSaveTemplateDto,PackingSetSharingDto,+ PackingAddContributorDto,PackingUpdateBagDto,PackingUpdateItemDto,} from './packing.dto';@@ -248,6 +249,7 @@ export class PackingController {@Param('tripId') tripId: string,@Param('id') id: string,@Headers('x-socket-id') socketId?: string,+ @Body() body?: PackingAddContributorDto,) {// Plan 4 Task 8b (U6) — :id parsed ONCE here (toRowId). #858's// contributors/sharing routes are native Nest code with no pre-ORM@@ -258,7 +260,8 @@ export class PackingController {if (itemId === null) {throw new HttpException({ error: 'Item not found or not a shared list item' }, 404);}- const item = await this.packing.addContributor(tripId, itemId, user.id);+ // No body is the caller's own pledge; a user_id puts someone else down (#3098).+ const item = await this.packing.addContributor(tripId, itemId, body?.user_id ?? user.id, user.id);if (!item) {throw new HttpException({ error: 'Item not found or not a shared list item' }, 404);}@@ -286,7 +289,7 @@ export class PackingController {throw new HttpException({ error: 'Item not found' }, 404);}// You can drop your own pledge; the owner can remove anyone's.- const item = await this.packing.removeContributor(tripId, itemId, target);+ const item = await this.packing.removeContributor(tripId, itemId, target, user.id);if (!item) {throw new HttpException({ error: 'Item not found' }, 404);}diff --git a/server/src/nest/packing/packing.dto.ts b/server/src/nest/packing/packing.dto.tsindex c3882ef6d..a45e841dd 100644--- a/server/src/nest/packing/packing.dto.ts+++ b/server/src/nest/packing/packing.dto.ts@@ -3,6 +3,7 @@ import {packingCreateItemRequestSchema,packingUpdateItemRequestSchema,packingSetSharingRequestSchema,+ packingAddContributorRequestSchema,packingImportRequestSchema,packingReorderRequestSchema,packingCreateBagRequestSchema,@@ -24,6 +25,7 @@ import { createZodDto } from 'nestjs-zod';export class PackingCreateItemDto extends createZodDto(packingCreateItemRequestSchema) {}export class PackingUpdateItemDto extends createZodDto(packingUpdateItemRequestSchema) {}export class PackingSetSharingDto extends createZodDto(packingSetSharingRequestSchema) {}+export class PackingAddContributorDto extends createZodDto(packingAddContributorRequestSchema) {}export class PackingImportDto extends createZodDto(packingImportRequestSchema) {}export class PackingReorderDto extends createZodDto(packingReorderRequestSchema) {}export class PackingCreateBagDto extends createZodDto(packingCreateBagRequestSchema) {}diff --git a/server/src/nest/packing/packing.service.ts b/server/src/nest/packing/packing.service.tsindex 232a6af5a..16cc4b57d 100644--- a/server/src/nest/packing/packing.service.ts+++ b/server/src/nest/packing/packing.service.ts@@ -406,18 +406,23 @@ export class PackingService {* getItemPrivacy} (`PackingController.addContributor`, native Nest code* with no pre-ORM Express precedent — #858 landed post-migration).*/- async addContributor(tripId: string | number, id: number, userId: number) {- const item = await this.itemsRepo.findVisibleInTrip(id, tripId, userId);+ async addContributor(tripId: string | number, id: number, userId: number, actingUserId: number = userId) {+ const item = await this.itemsRepo.findVisibleInTrip(id, tripId, actingUserId);if (!item || item.is_private !== 0) return null; // co-contribution is a Common-list conceptif (item.owner_id === userId) return null; // the bringer is already covering it+ // Putting someone else down as a bringer (#3098) only reaches people on the trip.+ if (userId !== actingUserId && !(await this.tripRosterIds(tripId)).has(userId)) return null;await this.contributorsRepo.insertIgnore(id, userId);return (await this.enrichItems([await this.itemsRepo.findById(id)]))[0];}/** `id: number` — same Plan 4 Task 8b (U6) narrowing as {@link addContributor}; `userId` here is the target being removed, not the acting viewer (`PackingController.removeContributor` now parses both `:id`/`:userId` via `toRowId` instead of a bare `Number.parseInt`). */- async removeContributor(tripId: string | number, id: number, userId: number) {- const item = await this.itemsRepo.findVisibleInTrip(id, tripId, userId);+ async removeContributor(tripId: string | number, id: number, userId: number, actingUserId: number = userId) {+ const item = await this.itemsRepo.findVisibleInTrip(id, tripId, actingUserId);if (!item) return null;+ // On a Common item the owner is its first bringer, so taking them off the+ // item has to clear the owner too; otherwise their avatar stuck for good (#3098).+ if (item.is_private === 0 && item.owner_id === userId) await this.itemsRepo.clearOwner(id);await this.contributorsRepo.deleteOne(id, userId);return (await this.enrichItems([await this.itemsRepo.findById(id)]))[0];}diff --git a/server/tests/integration/packing.test.ts b/server/tests/integration/packing.test.tsindex cf36cd370..1eb5df26d 100644--- a/server/tests/integration/packing.test.ts+++ b/server/tests/integration/packing.test.ts@@ -245,6 +245,49 @@ describe('Three-tier packing sharing (#858)', () => {expect(res.body.item.contributors.map((c: any) => c.user_id)).toContain(helper.id);});+ it('PACK-3T-004b — a member puts someone else down as the bringer, and takes the owner off again (#3098)', async () => {+ const { user: owner } = createUser(testDb);+ const { user: helper } = createUser(testDb);+ const { user: stranger } = createUser(testDb);+ const trip = createTrip(testDb, owner.id);+ addTripMember(testDb, trip.id, helper.id);+ const created = await request(app)+ .post(`/api/trips/${trip.id}/packing`)+ .set('Cookie', authCookie(owner.id))+ .send({ name: 'Stove', visibility: 'personal' });+ const id = created.body.item.id;+ await request(app)+ .put(`/api/trips/${trip.id}/packing/${id}/sharing`)+ .set('Cookie', authCookie(owner.id))+ .send({ visibility: 'common' });++ const assigned = await request(app)+ .post(`/api/trips/${trip.id}/packing/${id}/contributors`)+ .set('Cookie', authCookie(owner.id))+ .send({ user_id: helper.id });+ expect(assigned.status).toBe(201);+ expect(assigned.body.item.contributors.map((c: any) => c.user_id)).toEqual([helper.id]);++ const outsider = await request(app)+ .post(`/api/trips/${trip.id}/packing/${id}/contributors`)+ .set('Cookie', authCookie(owner.id))+ .send({ user_id: stranger.id });+ expect(outsider.status).toBe(404);++ const bad = await request(app)+ .post(`/api/trips/${trip.id}/packing/${id}/contributors`)+ .set('Cookie', authCookie(owner.id))+ .send({ user_id: 'x' });+ expect(bad.status).toBe(400);++ const ownerOff = await request(app)+ .delete(`/api/trips/${trip.id}/packing/${id}/contributors/${owner.id}`)+ .set('Cookie', authCookie(helper.id));+ expect(ownerOff.status).toBe(200);+ expect(ownerOff.body.item.owner_id).toBeNull();+ expect(ownerOff.body.item.contributors.map((c: any) => c.user_id)).toEqual([helper.id]);+ });+it('PACK-3T-005 — sharing can only be changed by the owner', async () => {const { user: owner } = createUser(testDb);const { user: member } = createUser(testDb);diff --git a/server/tests/unit/db/repositories/PackingItems.repository.test.ts b/server/tests/unit/db/repositories/PackingItems.repository.test.tsindex eaad5ea97..8a1c9efcc 100644--- a/server/tests/unit/db/repositories/PackingItems.repository.test.ts+++ b/server/tests/unit/db/repositories/PackingItems.repository.test.ts@@ -112,3 +112,22 @@ describe('PackingItemsRepository — share.service.ts SH13 read', () => {expect(await packingItemsRepo.listPublicForShare(trip.id)).toEqual([]);});});++describe('PackingItemsRepository — clearOwner (#3098)', () => {+ it('drops the owner of one item, keeps its tier and leaves the other items alone', async () => {+ const { user: owner } = createUser(testDb);+ const trip = createTrip(testDb, owner.id);+ const item = createPackingItem(testDb, trip.id, { name: 'Stove' });+ const other = createPackingItem(testDb, trip.id, { name: 'Pot' });+ await updateRows(t, PackingItems, { id: item.id }, { is_private: 0, owner: owner.id, updated_at: null });+ await updateRows(t, PackingItems, { id: other.id }, { is_private: 0, owner: owner.id });++ await packingItemsRepo.clearOwner(item.id);++ const row = await packingItemsRepo.findById(item.id);+ expect(row?.owner_id).toBeNull();+ expect(row?.is_private).toBe(0);+ expect(row?.updated_at).not.toBeNull();+ expect((await packingItemsRepo.findById(other.id))?.owner_id).toBe(owner.id);+ });+});diff --git a/server/tests/unit/nest/packing.controller.test.ts b/server/tests/unit/nest/packing.controller.test.tsindex c576f86bc..81c0d6800 100644--- a/server/tests/unit/nest/packing.controller.test.ts+++ b/server/tests/unit/nest/packing.controller.test.ts@@ -498,10 +498,18 @@ describe('PackingController (parity with the legacy /api/trips/:tripId/packing rconst svc = makeService({ addContributor, broadcast } as Partial<PackingService>);await new PackingController(svc).addContributor(user, '5', '9', 'sock');// Plan 4 Task 8b (U6) — :id is now parsed ONCE at the controller gate (toRowId).- expect(addContributor).toHaveBeenCalledWith('5', 9, user.id);+ expect(addContributor).toHaveBeenCalledWith('5', 9, user.id, user.id);expect(broadcast).toHaveBeenCalledWith('5', 'packing:updated', { item }, 'sock');});+ it('POST /:id/contributors with a user_id puts that person down as a bringer (#3098)', async () => {+ const item = { id: 9, is_private: 0, contributors: [{ user_id: 7 }] };+ const addContributor = vi.fn().mockReturnValue(item);+ const svc = makeService({ addContributor, broadcast: vi.fn() } as Partial<PackingService>);+ await new PackingController(svc).addContributor(user, '5', '9', 'sock', { user_id: 7 });+ expect(addContributor).toHaveBeenCalledWith('5', 9, 7, user.id);+ });+it('DELETE /:id/contributors/:userId removes the contributor + broadcasts', async () => {const item = { id: 9, is_private: 0, contributors: [] };const removeContributor = vi.fn().mockReturnValue(item);@@ -509,7 +517,7 @@ describe('PackingController (parity with the legacy /api/trips/:tripId/packing rconst svc = makeService({ removeContributor, broadcast } as Partial<PackingService>);await new PackingController(svc).removeContributor(user, '5', '9', '2', 'sock');// Plan 4 Task 8b (U6) — :id/:userId are now parsed ONCE at the controller gate (toRowId).- expect(removeContributor).toHaveBeenCalledWith('5', 9, 2);+ expect(removeContributor).toHaveBeenCalledWith('5', 9, 2, user.id);expect(broadcast).toHaveBeenCalledWith('5', 'packing:updated', { item }, 'sock');});diff --git a/server/tests/unit/nest/packing.service.test.ts b/server/tests/unit/nest/packing.service.test.tsindex 974a53c31..471a297b4 100644--- a/server/tests/unit/nest/packing.service.test.ts+++ b/server/tests/unit/nest/packing.service.test.ts@@ -728,6 +728,37 @@ describe('three-tier packing sharing (#858)', () => {expect(cleared.contributors).toEqual([]);});+ it('PACK-SVC-044b: anyone on the trip can be put down as the bringer of a Common item, nobody else (#3098)', async () => {+ const { user: owner } = createUser(testDb);+ const { user: friend } = createUser(testDb);+ const { user: stranger } = createUser(testDb);+ const trip = createTrip(testDb, owner.id);+ addTripMember(testDb, trip.id, friend.id);+ const common = (await svc.createItem(trip.id, { name: 'Tent', visibility: 'common' }, owner.id)) as any;++ const assigned = (await svc.addContributor(trip.id, common.id, friend.id, owner.id)) as any;+ expect(assigned.contributors.map((c: any) => c.user_id)).toEqual([friend.id]);+ expect(await svc.addContributor(trip.id, common.id, stranger.id, owner.id)).toBeNull();+ });++ it('PACK-SVC-044c: taking the owner off a Common item clears them as its bringer and leaves the others (#3098)', async () => {+ const { user: owner } = createUser(testDb);+ const { user: friend } = createUser(testDb);+ const trip = createTrip(testDb, owner.id);+ addTripMember(testDb, trip.id, friend.id);+ // Personal first, then back to the shared list: the owner stays on as its bringer.+ const item = (await svc.createItem(trip.id, { name: 'Stove', visibility: 'personal' }, owner.id)) as any;+ await svc.setItemSharing(trip.id, item.id, owner.id, 'common', []);+ await svc.addContributor(trip.id, item.id, friend.id, friend.id);+ expect((await itemRow(item.id)).owner_id).toBe(owner.id);++ const after = (await svc.removeContributor(trip.id, item.id, owner.id, friend.id)) as any;+ expect(after.owner_id).toBeNull();+ expect(after.owner_username).toBeNull();+ expect(after.contributors.map((c: any) => c.user_id)).toEqual([friend.id]);+ expect(after.is_private).toBe(0);+ });+it("PACK-SVC-045: cloneItem copies an item onto the cloner's personal list", async () => {const { user: owner } = createUser(testDb);const { user: cloner } = createUser(testDb);@@ -1436,30 +1467,13 @@ describe('packing item object-level authorization', () => {expect((await itemRow(personal.id)).owner_id).toBe(owner.id);});- it("U3 HOLE — contributor removal checks the path user's visibility, not the caller's: an intruder who cannot see a Personal item still gets it back by naming the owner as :userId", async () => {- // PRE-EXISTING on base (packing.controller.ts ~250 → packing.service.ts- // removeContributor; base carries the identical shape). The controller- // passes the PATH `:userId` — not `user.id`, the caller — as the third- // argument to `PackingService.removeContributor`, which uses that same- // id both to run the visibility check AND as the contributor row to- // delete. An intruder who cannot see `owner`'s Personal item at all can- // still name `owner` as `:userId`: the visibility check passes because- // OWNERS can always see their own item, and the full enriched item comes- // back in the response — an IDOR read of content the intruder has no- // business seeing, RIGHTS-gated only by `packing_edit`, not by the- // three-tier privacy model. Deliberately NOT fixed here (controller- // ruling U3, pinned so it cannot be "fixed" silently); the one-line fix- // is in the fix-wave report for the user: check `findVisibleInTrip` for- // the CALLER, and additionally require `userId === callerId ||- // item.owner_id === callerId`.- // The intruder is the caller in the real route (RequirePermission checks- // only packing_edit, never visibility) — but the service signature never- // receives the caller's id at all, only the path :userId. That gap is- // the bug, so there is nothing of the intruder's identity to pass here.- const { owner, trip, personal } = await restrictedTrip();- const leaked = await svc.removeContributor(trip.id, personal.id, owner.id);- expect(leaked).not.toBeNull();- expect(leaked.name).toBe('Diary');+ it("U3: contributor removal checks the caller's visibility, so naming the owner as :userId no longer hands an intruder their Personal item", async () => {+ // The route used to pass only the path :userId, which ran the visibility+ // check as the owner and returned the item to whoever asked. The caller now+ // rides along (#3098 needed it to take the owner off a Common item).+ const { owner, intruder, trip, personal } = await restrictedTrip();+ expect(await svc.removeContributor(trip.id, personal.id, owner.id, intruder.id)).toBeNull();+ expect((await itemRow(personal.id)).owner_id).toBe(owner.id);});it('PACK-SVC-105b: a visible item the caller does not own still reports forbidden, not missing', async () => {diff --git a/shared/src/packing/packing.schema.ts b/shared/src/packing/packing.schema.tsindex 7849b9139..2d5586180 100644--- a/shared/src/packing/packing.schema.ts+++ b/shared/src/packing/packing.schema.ts@@ -121,6 +121,13 @@ export const packingSetSharingRequestSchema = z.object({});export type PackingSetSharingRequest = z.infer<typeof packingSetSharingRequestSchema>;+// Who brings a Common item (#3098): without a body the caller pledges themselves,+// with user_id anyone on the trip can be put down as a bringer.+export const packingAddContributorRequestSchema = z.object({+ user_id: z.number().int().positive().optional(),+});+export type PackingAddContributorRequest = z.infer<typeof packingAddContributorRequestSchema>;+export const packingUpdateItemRequestSchema = z.object({name: z.string().optional(),// The legacy route accepted both boolean and 0/1 for checked — both stay valid.