mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 02:34:21 +00:00
fix(planner): place edit and delete controls follow place_edit, not day_edit
With places set to "Trip owner" a member who may edit days still saw Edit and Delete on a place in the day plan's context menu, the inspector's action row, its inline rename and the phone timeline's edit circle, and every one of them ended in the server's 403. The day plan gates the two entries on place_edit (taking a place off the day stays a day right), the inspector drops its edit, delete and update handlers without the right the way the places pool already does, the phone timeline offers the pencil only with it, and openPlaceEditor and handleDeletePlace guard like their siblings. Closes #2446
This commit is contained in:
@@ -101,14 +101,15 @@ vi.mock('../shared/Toast', () => ({
|
||||
|
||||
// ── Permissions mock ────────────────────────────────────────────────────────
|
||||
|
||||
// Flipped per test to render the read-only variants of the day rows.
|
||||
const mockPermissions = vi.hoisted(() => ({ canEdit: true }))
|
||||
// Flipped per test to render the read-only variants of the day rows; `denied`
|
||||
// takes single actions away from an otherwise editing member.
|
||||
const mockPermissions = vi.hoisted(() => ({ canEdit: true, denied: new Set<string>() }))
|
||||
|
||||
vi.mock('../../store/permissionsStore', async (importOriginal) => {
|
||||
const actual = await importOriginal() as any
|
||||
return {
|
||||
...actual,
|
||||
useCanDo: () => () => mockPermissions.canEdit,
|
||||
useCanDo: () => (action: string) => mockPermissions.canEdit && !mockPermissions.denied.has(action),
|
||||
}
|
||||
})
|
||||
|
||||
@@ -182,6 +183,7 @@ beforeEach(() => {
|
||||
resetAllStores()
|
||||
vi.clearAllMocks()
|
||||
mockPermissions.canEdit = true
|
||||
mockPermissions.denied.clear()
|
||||
// clearAllMocks keeps implementations, so tests that swap the router out would
|
||||
// otherwise leak into the ones after them.
|
||||
vi.mocked(calculateRouteWithLegs).mockImplementation(waypoints => Promise.resolve({
|
||||
@@ -938,6 +940,18 @@ describe('DayPlanSidebar', () => {
|
||||
expect(onEditPlace).toHaveBeenCalledWith(place, assignment.id)
|
||||
})
|
||||
|
||||
it('FE-PLANNER-DAYPLAN-214: without place_edit the menu still removes from the day but neither edits nor deletes the place (#2446)', () => {
|
||||
mockPermissions.denied.add('place_edit')
|
||||
const place = buildPlace({ id: 42, name: 'Louvre Museum' })
|
||||
const day = buildDay({ id: 10, date: '2025-06-01', title: 'Day 1' })
|
||||
const assignment = buildAssignment({ id: 99, day_id: 10, order_index: 0, place })
|
||||
render(<DayPlanSidebar {...makeDefaultProps({ days: [day], places: [place], assignments: { '10': [assignment] } })} />)
|
||||
fireEvent.contextMenu(screen.getByText('Louvre Museum'))
|
||||
expect(screen.getByText(/Remove from day/i)).toBeInTheDocument()
|
||||
expect(screen.queryByText('Edit')).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('Delete')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
// ── Arrow reorder buttons ────────────────────────────────────────────────
|
||||
|
||||
it('FE-PLANNER-DAYPLAN-041: arrow down button reorders day assignments', async () => {
|
||||
|
||||
Reference in New Issue
Block a user