Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
feat(control-ui): show inherited access in folder share dialogs
Mc2edc4b96546
diff --git a/control-ui/components/GfsGrantPanel.tsx b/control-ui/components/GfsGrantPanel.tsxindex d66828aa3..7783c999c 100644--- a/control-ui/components/GfsGrantPanel.tsx+++ b/control-ui/components/GfsGrantPanel.tsx@@ -152,7 +152,6 @@ export function GfsGrantPanel({ resource }: GfsGrantPanelProps): React.JSX.Eleme| null>(null)const canIncludeDescendants = resource.kind === 'directory'- const resourceIsFile = resource.kind === 'file'const loadExistingAccess = useCallback(async () => {existingAccessController.current?.abort()@@ -220,17 +219,18 @@ export function GfsGrantPanel({ resource }: GfsGrantPanelProps): React.JSX.ElemeinheritedAccessController.current?.abort()const requestId = ++inheritedAccessRequest.currentsetInheritedAccessFailed(false)- if (!resourceIsFile || !resource.path) {- inheritedAccessController.current = null- setInheritedAccess([])- setInheritedAccessLoading(false)- return- }+ // Inherited access is derived for FILES AND FOLDERS: a folder dialog must+ // show the identities its ancestors grant, not an empty list. The walk+ // resolves the canonical path itself when the target carries none.const controller = new AbortController()inheritedAccessController.current = controllersetInheritedAccessLoading(true)try {- const items = await loadGfsInheritedAccess(resource.path, DRIVE, controller.signal)+ const items = await loadGfsInheritedAccess(+ { path: resource.path, gfsUri: resource.gfsUri },+ DRIVE,+ controller.signal+ )if (requestId !== inheritedAccessRequest.current) returnsetInheritedAccess(items)} catch {@@ -247,7 +247,7 @@ export function GfsGrantPanel({ resource }: GfsGrantPanelProps): React.JSX.ElemesetInheritedAccessLoading(false)}}- }, [resource.path, resourceIsFile])+ }, [resource.gfsUri, resource.path, resource.resourceId])useEffect(() => {void loadInheritedAccess()@@ -443,15 +443,11 @@ export function GfsGrantPanel({ resource }: GfsGrantPanelProps): React.JSX.Eleme[subjectLabel])- const sortedExistingAccess = useMemo(- () => [...existingAccess].sort(bySubjectLabel),- [bySubjectLabel, existingAccess]- )-- // File dialogs dedupe to exactly one row per member across direct grants- // and inherited ancestor grants; the effective role is the strongest.- const sortedFileAccessRows = useMemo<GfsFileAccessRow[]>(() => {- if (!resourceIsFile) return []+ // Every dialog — file AND folder — dedupes to exactly one row per member+ // across direct grants/shares and inherited ancestor rows; the effective+ // role is the strongest. Folders previously rendered direct-only, which hid+ // the identities their ancestors grant.+ const sortedAccessRows = useMemo<GfsFileAccessRow[]>(() => {const bySubjectRow = new Map<string, GfsFileAccessRow>()for (const direct of existingAccess) {bySubjectRow.set(subjectKey(direct.subject), {@@ -479,7 +475,7 @@ export function GfsGrantPanel({ resource }: GfsGrantPanelProps): React.JSX.Eleme}}return [...bySubjectRow.values()].sort(bySubjectLabel)- }, [bySubjectLabel, existingAccess, inheritedAccess, resourceIsFile])+ }, [bySubjectLabel, existingAccess, inheritedAccess])async function revokeAccess(item: GfsExistingAccessItem) {const label = subjectLabel(item)@@ -812,126 +808,72 @@ export function GfsGrantPanel({ resource }: GfsGrantPanelProps): React.JSX.Eleme<p className="cu-gfs-existing-access__empty">No one has access yet.</p>) : (<RecordList className="cu-gfs-existing-access__list" aria-label="Resource access">- {resourceIsFile- ? sortedFileAccessRows.map(row => {- const label = subjectLabel(row)- const kind = subjectKind(row)- const inherited = row.inherited !== null- return (- <RecordListRow- className="cu-gfs-existing-access__item"- data-testid={`gfs-access-row-${subjectKey(row.subject)}`}- data-access-id={row.direct?.grantId ?? row.direct?.shareIds[0]}- data-inherited={inherited ? 'true' : undefined}- key={`file:${subjectKey(row.subject)}`}- >- <span- aria-hidden="true"- className={`cu-gfs-existing-access__avatar cu-gfs-existing-access__avatar--${kind}`}- data-subject-kind={kind}- >- <AccessSubjectIcon kind={kind} />- </span>- <span className="cu-gfs-existing-access__identity">- <span className="cu-gfs-existing-access__subject">{label}</span>- </span>- <span className="cu-gfs-existing-access__meta">- <SelectionDropdown- ariaLabel={`Access role for ${label}`}- className="cu-gfs-existing-access__role"- disabled={actionPending}- multiple={false}- onChange={next => {- if (!inherited) {- void updateAccessRole(- row.direct as GfsExistingAccessItem,- (next[0] ?? 'read') as AccessRole- )- return- }- const nextRole = (next[0] ?? 'read') as AccessRole- void prepareParentRoleChange(row, nextRole)- }}- menuClassName="cu-gfs-existing-access__role-menu"- options={ROLE_OPTIONS}- placeholder="Role"- portal- searchable={false}- showSelectedChips={false}- value={[roleForPermissions(row.permissions)]}- />- </span>- <RowActionMenu- actions={[- {- key: 'remove',- label: 'Remove access',- danger: true,- disabled: actionPending,- onSelect: () =>- inherited- ? setParentUpdate({ row, mode: 'remove' })- : void revokeAccess(row.direct as GfsExistingAccessItem),- },- ]}- ariaLabel={`Actions for ${label}`}- />- </RecordListRow>- )- })- : sortedExistingAccess.map(item => {- const label = subjectLabel(item)- const kind = subjectKind(item)- return (- <RecordListRow- className="cu-gfs-existing-access__item"- data-testid={`gfs-access-row-${subjectKey(item.subject)}`}- data-access-id={item.grantId ?? item.shareIds[0]}- key={`direct:${subjectKey(item.subject)}`}- >- <span- aria-hidden="true"- className={`cu-gfs-existing-access__avatar cu-gfs-existing-access__avatar--${kind}`}- data-subject-kind={kind}- >- <AccessSubjectIcon kind={kind} />- </span>- <span className="cu-gfs-existing-access__identity">- <span className="cu-gfs-existing-access__subject">{label}</span>- </span>- <span className="cu-gfs-existing-access__meta">- <SelectionDropdown- ariaLabel={`Access role for ${label}`}- className="cu-gfs-existing-access__role"- disabled={actionPending}- multiple={false}- onChange={next =>- void updateAccessRole(item, (next[0] ?? 'read') as AccessRole)- }- menuClassName="cu-gfs-existing-access__role-menu"- options={ROLE_OPTIONS}- placeholder="Role"- portal- searchable={false}- showSelectedChips={false}- value={[roleForPermissions(item.permissions)]}- />- </span>- <RowActionMenu- actions={[- {- key: 'remove',- label: 'Remove access',- danger: true,- disabled: actionPending,- onSelect: () => void revokeAccess(item),- },- ]}- ariaLabel={`Actions for ${label}`}- />- </RecordListRow>- )- })}+ {sortedAccessRows.map(row => {+ const label = subjectLabel(row)+ const kind = subjectKind(row)+ const inherited = row.inherited !== null+ return (+ <RecordListRow+ className="cu-gfs-existing-access__item"+ data-testid={`gfs-access-row-${subjectKey(row.subject)}`}+ data-access-id={row.direct?.grantId ?? row.direct?.shareIds[0]}+ data-inherited={inherited ? 'true' : undefined}+ key={`access:${subjectKey(row.subject)}`}+ >+ <span+ aria-hidden="true"+ className={`cu-gfs-existing-access__avatar cu-gfs-existing-access__avatar--${kind}`}+ data-subject-kind={kind}+ >+ <AccessSubjectIcon kind={kind} />+ </span>+ <span className="cu-gfs-existing-access__identity">+ <span className="cu-gfs-existing-access__subject">{label}</span>+ </span>+ <span className="cu-gfs-existing-access__meta">+ <SelectionDropdown+ ariaLabel={`Access role for ${label}`}+ className="cu-gfs-existing-access__role"+ disabled={actionPending}+ multiple={false}+ onChange={next => {+ if (!inherited) {+ void updateAccessRole(+ row.direct as GfsExistingAccessItem,+ (next[0] ?? 'read') as AccessRole+ )+ return+ }+ const nextRole = (next[0] ?? 'read') as AccessRole+ void prepareParentRoleChange(row, nextRole)+ }}+ menuClassName="cu-gfs-existing-access__role-menu"+ options={ROLE_OPTIONS}+ placeholder="Role"+ portal+ searchable={false}+ showSelectedChips={false}+ value={[roleForPermissions(row.permissions)]}+ />+ </span>+ <RowActionMenu+ actions={[+ {+ key: 'remove',+ label: 'Remove access',+ danger: true,+ disabled: actionPending,+ onSelect: () =>+ inherited+ ? setParentUpdate({ row, mode: 'remove' })+ : void revokeAccess(row.direct as GfsExistingAccessItem),+ },+ ]}+ ariaLabel={`Actions for ${label}`}+ />+ </RecordListRow>+ )+ })}</RecordList>)}</section>diff --git a/control-ui/components/__tests__/GfsGrantPanel.bulk.test.tsx b/control-ui/components/__tests__/GfsGrantPanel.bulk.test.tsxindex 48ed11164..1c9f17431 100644--- a/control-ui/components/__tests__/GfsGrantPanel.bulk.test.tsx+++ b/control-ui/components/__tests__/GfsGrantPanel.bulk.test.tsx@@ -3,6 +3,7 @@ import { fireEvent, render, screen, waitFor, within } from '@testing-library/reaimport {type GfsMutationResponse,type GfsSubjectInput,+ apiGet,deleteGfsGrant,deleteGfsShare,getAdminTeams,@@ -17,6 +18,7 @@ import { GfsGrantPanel } from '../GfsGrantPanel'import { ToastProvider } from '../Toast'vi.mock('@lib/api', () => ({+ apiGet: vi.fn(),getAdminTeams: vi.fn(),getAdminUsers: vi.fn(),getHosts: vi.fn(),@@ -28,6 +30,7 @@ vi.mock('@lib/api', () => ({putGfsGrant: vi.fn(),}))+const mockApiGet = vi.mocked(apiGet)const mockGetAdminUsers = vi.mocked(getAdminUsers)const mockGetAdminTeams = vi.mocked(getAdminTeams)const mockGetHosts = vi.mocked(getHosts)@@ -94,6 +97,9 @@ async function submit(action: 'Share') {describe('GfsGrantPanel bulk access', () => {beforeEach(() => {vi.clearAllMocks()+ // The bulk suite exercises direct rows; resolve any path-less target to a+ // root-level resource so the inherited walk has zero ancestors to derive.+ mockApiGet.mockResolvedValue({ resourceId: resource.resourceId, path: '/', kind: 'file' })mockGetAdminUsers.mockResolvedValue({items: [{diff --git a/control-ui/components/__tests__/GfsGrantPanel.inherited.test.tsx b/control-ui/components/__tests__/GfsGrantPanel.inherited.test.tsxindex 9214c6d11..6c26dc2d5 100644--- a/control-ui/components/__tests__/GfsGrantPanel.inherited.test.tsx+++ b/control-ui/components/__tests__/GfsGrantPanel.inherited.test.tsx@@ -1,6 +1,7 @@import { beforeEach, describe, expect, it, vi } from 'vitest'import { fireEvent, render, screen, waitFor, within } from '@testing-library/react'import {+ apiGet,deleteGfsGrant,deleteGfsShare,getAdminTeams,@@ -17,6 +18,7 @@ import { ToastProvider } from '../Toast'import { gfsAncestorPaths } from '../gfsInheritedAccess'vi.mock('@lib/api', () => ({+ apiGet: vi.fn(),getAdminTeams: vi.fn(),getAdminUsers: vi.fn(),getHosts: vi.fn(),@@ -29,6 +31,7 @@ vi.mock('@lib/api', () => ({putGfsGrant: vi.fn(),}))+const mockApiGet = vi.mocked(apiGet)const mockGetAdminUsers = vi.mocked(getAdminUsers)const mockGetAdminTeams = vi.mocked(getAdminTeams)const mockGetHosts = vi.mocked(getHosts)@@ -450,7 +453,7 @@ describe('GfsGrantPanel inherited access', () => {)})- it('keeps folder dialogs unchanged: direct rows only, no derived ancestor rows', async () => {+ it('derives inherited ancestor rows for FOLDER dialogs too', async () => {renderPanel(folderResource)const existing = await screen.findByRole('region', { name: 'People with access' })@@ -464,17 +467,32 @@ describe('GfsGrantPanel inherited access', () => {.textContent).toContain('Editor')expect(within(miguelRow as HTMLElement).queryByText(/Inherited from/)).toBeNull()- // Ancestor derivation never runs for folders.- await waitFor(() => expect(mockGetGfsResourceByPath).not.toHaveBeenCalled())- expect(within(existing).queryByText('Research')).toBeNull()+ // The folder's only ancestor is the drive root; its descendant-covering+ // share now shows as a normal inherited row — the reported folder bug.+ const teamRow = await within(existing).findByTestId(researchTeamRowTestId)+ expect(+ within(teamRow).getByRole('button', { name: 'Access role for Research' }).textContent+ ).toContain('Read')+ expect(within(teamRow).queryByText(/Inherited from/)).toBeNull()+ expect(mockGetGfsResourceByPath).toHaveBeenCalledWith('main', '/', expect.anything())})- it('skips derivation when the resource has no path and hides no direct rows', async () => {+ it('resolves the target once when the dialog resource carries no path', async () => {+ mockApiGet.mockResolvedValue({+ resourceId: FILE_ID,+ path: '/team-docs/report.md',+ kind: 'file',+ })renderPanel({ ...fileResource, path: null })const existing = await screen.findByRole('region', { name: 'People with access' })- await waitFor(() => expect(within(existing).getByText('No one has access yet.')).toBeTruthy())- expect(mockGetGfsResourceByPath).not.toHaveBeenCalled()+ await within(existing).findByTestId(miguelRowTestId)+ expect(mockApiGet).toHaveBeenCalledWith(+ '/api/v1/gfs/resolve',+ { uri: fileResource.gfsUri },+ expect.anything()+ )+ expect(mockGetGfsResourceByPath).toHaveBeenCalledWith('main', '/team-docs', expect.anything())})// R1-M3 — a total derivation failure is a quiet inline notice, never adiff --git a/control-ui/components/__tests__/gfsInheritedAccess.test.ts b/control-ui/components/__tests__/gfsInheritedAccess.test.tsindex f4ffd733b..19cd83558 100644--- a/control-ui/components/__tests__/gfsInheritedAccess.test.ts+++ b/control-ui/components/__tests__/gfsInheritedAccess.test.ts@@ -1,13 +1,15 @@import { beforeEach, describe, expect, it, vi } from 'vitest'-import { getGfsGrants, getGfsResourceByPath, getGfsShares } from '@lib/api'+import { apiGet as apiGetFn, getGfsGrants, getGfsResourceByPath, getGfsShares } from '@lib/api'import { loadGfsInheritedAccess } from '../gfsInheritedAccess'vi.mock('@lib/api', () => ({+ apiGet: vi.fn(),getGfsGrants: vi.fn(),getGfsResourceByPath: vi.fn(),getGfsShares: vi.fn(),}))+const apiGet = vi.mocked(apiGetFn)const mockGetGfsGrants = vi.mocked(getGfsGrants)const mockGetGfsResourceByPath = vi.mocked(getGfsResourceByPath)const mockGetGfsShares = vi.mocked(getGfsShares)@@ -54,7 +56,7 @@ describe('loadGfsInheritedAccess', () => {}})- await expect(loadGfsInheritedAccess('/nested/report.md', 'main')).rejects.toThrow(+ await expect(loadGfsInheritedAccess({ path: '/nested/report.md' }, 'main')).rejects.toThrow('inherited_access_derivation_failed')expect(mockGetGfsResourceByPath.mock.calls.map(([, path]) => path)).toEqual(['/nested'])@@ -67,9 +69,50 @@ describe('loadGfsInheritedAccess', () => {throw new Error('unexpected path')})- await expect(loadGfsInheritedAccess('/nested/report.md', 'main')).rejects.toThrow(+ await expect(loadGfsInheritedAccess({ path: '/nested/report.md' }, 'main')).rejects.toThrow('inherited_access_derivation_failed')expect(mockGetGfsResourceByPath.mock.calls.map(([, path]) => path)).toEqual(['/nested'])})++ it('resolves the canonical path once when the target carries none', async () => {+ apiGet.mockResolvedValue({+ resourceId: 'nested-folder',+ path: '/nested',+ kind: 'directory',+ } as never)+ mockGetGfsResourceByPath.mockImplementation(async (_drive, path) => {+ if (path === '/nested') return resourceView('nested-folder', 'nested', '/nested')+ if (path === '/') return resourceView('root-folder', '', '/')+ throw new Error('unexpected path')+ })+ mockGetGfsGrants.mockResolvedValue({ items: [] })+ mockGetGfsShares.mockResolvedValue({ items: [] })++ const items = await loadGfsInheritedAccess({ path: null, gfsUri: 'gfs://main/abcdef' }, 'main')+ expect(items).toEqual([])+ expect(apiGet).toHaveBeenCalledWith(+ '/api/v1/gfs/resolve',+ { uri: 'gfs://main/abcdef' },+ expect.anything()+ )+ // The resolved target is the FOLDER /nested — its only ancestor is /.+ expect(mockGetGfsResourceByPath.mock.calls.map(([, path]) => path)).toEqual(['/'])+ })++ it('fails the derivation when a path-less target cannot be resolved', async () => {+ apiGet.mockRejectedValue(new Error('403 forbidden') as never)+ mockGetGfsResourceByPath.mockResolvedValue(resourceView('root-folder', '', '/'))++ await expect(+ loadGfsInheritedAccess({ path: null, gfsUri: 'gfs://main/abcdef' }, 'main')+ ).rejects.toThrow('inherited_access_derivation_failed')+ expect(mockGetGfsResourceByPath).not.toHaveBeenCalled()+ })++ it('fails the derivation when a target has neither a path nor a gfs URI', async () => {+ await expect(loadGfsInheritedAccess({ path: null, gfsUri: null }, 'main')).rejects.toThrow(+ 'inherited_access_derivation_failed'+ )+ })})diff --git a/control-ui/components/gfsInheritedAccess.ts b/control-ui/components/gfsInheritedAccess.tsindex 00f11d9c9..526cc0047 100644--- a/control-ui/components/gfsInheritedAccess.ts+++ b/control-ui/components/gfsInheritedAccess.ts@@ -1,6 +1,7 @@import { gfsAncestorPathsOf } from '@clerum/gfs-interaction-policy'import {type GfsResourceByPathView,+ apiGet,getGfsGrants,getGfsResourceByPath,getGfsShares,@@ -82,19 +83,47 @@ async function listInheritingRows(}/**- * Derives inherited access only when every ancestor and ACL list is available.- * Any incomplete walk throws `inherited_access_derivation_failed`, so the- * caller can distinguish a read failure from a complete empty result. The- * drive root carries an empty name, so its label falls back to the drive name,- * matching the browser breadcrumb.+ * Derives inherited access for FILES AND FOLDERS only when every ancestor and+ * ACL list is available. Any incomplete walk throws+ * `inherited_access_derivation_failed`, so the caller can distinguish a read+ * failure from a complete empty result. The drive root carries an empty name,+ * so its label falls back to the drive name, matching the browser breadcrumb.+ *+ * When the target's canonical path is unknown (for example a Share dialog+ * opened on the breadcrumb's current folder, whose crumb carries no path),+ * the target is resolved once through `/api/v1/gfs/resolve` to obtain it; a+ * target with neither a path nor a resolvable gfs URI fails the derivation so+ * the dialog never presents "no ancestors" as fact.*/export async function loadGfsInheritedAccess(- path: string,+ target: { path: string | null; gfsUri?: string | null },drive: string,signal?: AbortSignal): Promise<GfsInheritedAccessItem[]> {+ let canonicalPath = target.path+ if (!canonicalPath) {+ if (!target.gfsUri) throw new Error('inherited_access_derivation_failed')+ try {+ const resolved = (await apiGet(+ '/api/v1/gfs/resolve',+ { uri: target.gfsUri },+ { signal }+ )) as {+ path?: string | null+ kind?: string+ }+ if (resolved.kind && resolved.kind !== 'directory' && resolved.kind !== 'file') {+ throw new Error('unexpected kind')+ }+ canonicalPath = resolved.path ?? null+ } catch (error) {+ if (signal?.aborted) throw error+ throw new Error('inherited_access_derivation_failed')+ }+ if (!canonicalPath) throw new Error('inherited_access_derivation_failed')+ }const bySubject = new Map<string, GfsInheritedAccessItem>()- const ancestorPaths = gfsAncestorPaths(path)+ const ancestorPaths = gfsAncestorPaths(canonicalPath)for (const ancestorPath of ancestorPaths) {let folder: GfsResourceByPathViewtry {diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex b91d7ddbb..97632d750 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.732",+ "version": "0.1.733","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.732",+ "version": "0.1.733","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/frontend-components": "file:../packages/frontend-components",diff --git a/control-ui/package.json b/control-ui/package.jsonindex b587ca335..11575ef86 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.732",+ "version": "0.1.733","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",