|
| 1 | +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +/** |
| 4 | + * [#27735] The Pipeline nav entry is offered only to a member who can read |
| 5 | + * what the dashboard shows (ruling 6512784198, letter G). |
| 6 | + * |
| 7 | + * The entry carries a `visible` predicate, `current_user.can(OBJECT, 'read')`, |
| 8 | + * which the console's nav guard answers from the member's permissions payload. |
| 9 | + * It hides; it refuses nothing. The refusal stays where it already is: the |
| 10 | + * dataset query of every widget answers 403 to a caller who cannot read the |
| 11 | + * dataset's object (ADR-0066 D4: `visibleWhen` hides, `requiredPermissions` |
| 12 | + * refuses). So the one thing that can go wrong here is the predicate naming |
| 13 | + * an object other than the one the widgets read, and that is what is pinned, |
| 14 | + * off the parsed stack rather than the source constants. |
| 15 | + */ |
| 16 | + |
| 17 | +import { describe, expect, it } from 'vitest'; |
| 18 | +import stack from '../objectstack.config.js'; |
| 19 | + |
| 20 | +type NavEntry = { |
| 21 | + id?: string; |
| 22 | + type?: string; |
| 23 | + dashboardName?: string; |
| 24 | + visible?: { dialect?: string; source?: string }; |
| 25 | + children?: NavEntry[]; |
| 26 | +}; |
| 27 | + |
| 28 | +function findNav(entries: NavEntry[] | undefined, id: string): NavEntry | undefined { |
| 29 | + for (const entry of entries ?? []) { |
| 30 | + if (entry.id === id) return entry; |
| 31 | + const hit = findNav(entry.children, id); |
| 32 | + if (hit) return hit; |
| 33 | + } |
| 34 | + return undefined; |
| 35 | +} |
| 36 | + |
| 37 | +const READ_PREDICATE = /^current_user\.can\('([a-z0-9_]+)', 'read'\)$/; |
| 38 | + |
| 39 | +const app = (stack.apps ?? []).find((a) => a.name === 'crm_app'); |
| 40 | +const navEntry = findNav(app?.navigation as NavEntry[] | undefined, 'nav_pipeline_dashboard'); |
| 41 | +const dashboard = (stack.dashboards ?? []).find((d) => d.name === 'pipeline_dashboard'); |
| 42 | +// The stack parse normalises an authored CEL string to `{ dialect, source }`. |
| 43 | +const predicate = navEntry?.visible; |
| 44 | + |
| 45 | +describe('Pipeline nav entry audience (#27735)', () => { |
| 46 | + it('carries a read predicate on one object', () => { |
| 47 | + expect(navEntry).toMatchObject({ type: 'dashboard', dashboardName: 'pipeline_dashboard' }); |
| 48 | + expect(predicate?.dialect).toBe('cel'); |
| 49 | + expect(predicate?.source).toMatch(READ_PREDICATE); |
| 50 | + }); |
| 51 | + |
| 52 | + it('names the object of the dataset every pipeline_dashboard widget reads', () => { |
| 53 | + const named = predicate?.source?.match(READ_PREDICATE)?.[1]; |
| 54 | + expect(named).toBeDefined(); |
| 55 | + const widgets = (dashboard?.widgets ?? []) as Array<{ dataset?: string }>; |
| 56 | + expect(widgets.length).toBeGreaterThan(0); |
| 57 | + const objects = new Set( |
| 58 | + widgets.map((w) => (stack.datasets ?? []).find((d) => d.name === w.dataset)?.object), |
| 59 | + ); |
| 60 | + expect([...objects]).toEqual([named]); |
| 61 | + }); |
| 62 | +}); |
0 commit comments