Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(gfs): show row actions for every authorized resource
Me8dc8f432366
diff --git a/control-ui/components/__tests__/GfsBrowser.test.tsx b/control-ui/components/__tests__/GfsBrowser.test.tsxindex beee07308..afcd52cc1 100644--- a/control-ui/components/__tests__/GfsBrowser.test.tsx+++ b/control-ui/components/__tests__/GfsBrowser.test.tsx@@ -975,6 +975,28 @@ describe('GfsBrowser', () => {])})+ it('shows share and rename actions on both folder and file rows', async () => {+ mockApiGet.mockResolvedValueOnce({+ items: [child('archive', 'directory', 1), child('report.md', 'file', 2)],+ nextCursor: null,+ })+ renderBrowser()++ const currentResources = await screen.findByRole('list', { name: 'Current folder resources' })+ const folderRow = within(currentResources).getByText('archive').closest('li')+ const fileRow = within(currentResources).getByText('report.md').closest('li')+ expect(folderRow).not.toBeNull()+ expect(fileRow).not.toBeNull()++ expect(within(folderRow!).getByRole('button', { name: 'Share archive' })).toBeTruthy()+ expect(within(folderRow!).getByRole('button', { name: 'Rename archive' })).toBeTruthy()+ expect(within(folderRow!).queryByRole('button', { name: 'Download archive' })).toBeNull()++ expect(within(fileRow!).getByRole('button', { name: 'Share report.md' })).toBeTruthy()+ expect(within(fileRow!).getByRole('button', { name: 'Download report.md' })).toBeTruthy()+ expect(within(fileRow!).getByRole('button', { name: 'Rename report.md' })).toBeTruthy()+ })+it('surfaces download failures through the toast stack', async () => {mockApiGet.mockResolvedValueOnce({items: [child('report.md', 'file', 2)],diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex f52e28a76..5884b4829 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.504",+ "version": "0.1.505","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.504",+ "version": "0.1.505","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/llm-providers": "file:../packages/llm-providers",diff --git a/control-ui/package.json b/control-ui/package.jsonindex 75d634af4..2fcc63dcb 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.504",+ "version": "0.1.505","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",diff --git a/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsxindex 95b5ffaa4..4d080f60f 100644--- a/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx+++ b/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx@@ -90,6 +90,11 @@ function Probe() {<div data-testid="accessible-error">{ctrl.accessibleError ?? 'none'}</div><div data-testid="accessible-notice">{ctrl.accessibleNotice ?? 'none'}</div><div data-testid="held-permissions">{ctrl.affordances?.held.join(',') ?? 'none'}</div>+ {ctrl.items.map(item => (+ <div key={item.resourceId} data-testid={`row-affordances-${item.resourceId}`}>+ {ctrl.rowAffordancesByResourceId[item.resourceId]?.held.join(',') ?? 'none'}+ </div>+ ))}{ctrl.accessibleResources.map(resource => (<button key={resource.resourceId} type="button" onClick={() => ctrl.openResource(resource)}>open {resource.name}@@ -352,6 +357,105 @@ describe('useGfsBrowserController', () => {expect(affordances).toHaveBeenCalledTimes(1)})+ it('resolves affordances for every visible child row', async () => {+ const parent = {+ resourceId: 'folder-root',+ rid: 'folder-root',+ gfsUri: 'gfs://main/folder-root',+ drive: 'main',+ parentResourceId: null,+ name: 'Workspace',+ kind: 'directory' as const,+ path: '/Workspace',+ version: 1,+ bytes: 0,+ sources: ['grant'],+ permissions: ['read'],+ coversDescendants: true,+ }+ const childFolder = {+ resourceId: 'child-folder',+ rid: 'child-folder',+ gfsUri: 'gfs://main/child-folder',+ drive: 'main',+ parentResourceId: 'folder-root',+ name: 'Assets',+ kind: 'directory' as const,+ path: '/Workspace/Assets',+ version: 2,+ bytes: 0,+ }+ const childFile = {+ resourceId: 'child-file',+ rid: 'child-file',+ gfsUri: 'gfs://main/child-file',+ drive: 'main',+ parentResourceId: 'folder-root',+ name: 'report.txt',+ kind: 'file' as const,+ path: '/Workspace/report.txt',+ version: 3,+ bytes: 12,+ }+ const readonlyFile = {+ ...childFile,+ resourceId: 'readonly-file',+ rid: 'readonly-file',+ gfsUri: 'gfs://main/readonly-file',+ name: 'readonly.txt',+ }+ const listChildren = vi.fn(async () => ({+ items: [childFolder, childFile, readonlyFile],+ nextCursor: null,+ }))+ const affordances = vi.fn(async (resourceId: string) => {+ const held =+ resourceId === 'readonly-file'+ ? ['read']+ : resourceId === 'folder-root'+ ? ['read']+ : ['read', 'write', 'manage_acl']+ return {+ held,+ canDelegate: held.includes('manage_acl'),+ grantableBits: [],+ canCreateShare: false,+ }+ })+ Object.defineProperty(window, 'clerum', {+ configurable: true,+ value: {+ gfs: {+ listAccessible: vi.fn(async () => ({ items: [parent], nextCursor: null })),+ listChildren,+ affordances,+ },+ },+ })++ render(<Probe />, { wrapper: Harness })+ await waitFor(() => expect(screen.getByRole('button', { name: 'open Workspace' })).toBeTruthy())++ await act(async () => {+ screen.getByRole('button', { name: 'open Workspace' }).click()+ })++ await waitFor(() => expect(listChildren).toHaveBeenCalledWith('folder-root', 'main', undefined))+ await waitFor(() => {+ expect(screen.getByTestId('row-affordances-child-folder').textContent).toBe(+ 'read,write,manage_acl'+ )+ expect(screen.getByTestId('row-affordances-child-file').textContent).toBe(+ 'read,write,manage_acl'+ )+ expect(screen.getByTestId('row-affordances-readonly-file').textContent).toBe('read')+ })++ expect(affordances).toHaveBeenCalledWith('child-folder', 'main')+ expect(affordances).toHaveBeenCalledWith('child-file', 'main')+ expect(affordances).toHaveBeenCalledWith('readonly-file', 'main')+ })+it('loads accessible GFS resources and opens one without a pasted link', async () => {Object.defineProperty(window, 'clerum', {configurable: true,diff --git a/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts b/desktop-app/ui/src/hooks/domain/useGfsBrowserController.tsindex c95be3eac..03b6d701b 100644--- a/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts+++ b/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts@@ -1,6 +1,12 @@import { useCallback, useEffect, useMemo, useRef, useState } from 'react'import { useAuthContext } from '@contexts/AuthContext'-import { useInfiniteQuery, useMutation, useQuery, useQueryClient } from '@tanstack/react-query'+import {+ useInfiniteQuery,+ useMutation,+ useQueries,+ useQuery,+ useQueryClient,+} from '@tanstack/react-query'import { GFS_BREADCRUMB_MAX_DEPTH } from '@constants/gfsBrowser'import type { GfsGrantListItem, GfsShareListItem } from '@/gfs/delegation.types'import { desktopQueryKeys } from './queryKeys'@@ -346,37 +352,6 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {},[revokeAccess])- // Query-surfaced authorization failures (a refetch after revocation is the- // normal way the loss is discovered under Infinity staleTime). Discovery is- // the session/authority boundary; per-resource verdicts stay local.- const queryAuthorizationError = [- accessibleQuery.error- ? { message: toMessage(accessibleQuery.error), surface: 'discovery' as const }- : null,- childrenQuery.error- ? { message: toMessage(childrenQuery.error), surface: 'operation' as const }- : null,- affordancesQuery.error- ? { message: toMessage(affordancesQuery.error), surface: 'operation' as const }- : null,- rowAffordancesQuery.error- ? { message: toMessage(rowAffordancesQuery.error), surface: 'operation' as const }- : null,- grantsQuery.error- ? { message: toMessage(grantsQuery.error), surface: 'operation' as const }- : null,- sharesQuery.error- ? { message: toMessage(sharesQuery.error), surface: 'operation' as const }- : null,- ]- .filter(- (entry): entry is { message: string; surface: 'discovery' | 'operation' } => entry !== null- )- .find(entry => isGfsSessionAuthorityFailure(entry.message, entry.surface))- useEffect(() => {- if (!queryAuthorizationError || accessState === 'revoked') return- revokeAccess()- }, [accessState, queryAuthorizationError, revokeAccess])// All GFS mutations share the central fail-closed boundary: an authority// rejection (401 / typed lifecycle code) revokes the session even when the// caller would only have toasted. Policy verdicts (403/412) stay local.@@ -486,6 +461,78 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {() => (authorityPending ? [] : (childrenQuery.data?.pages ?? []).flatMap(page => page.items)),[authorityPending, childrenQuery.data])+ /**+ * Children listings deliberately contain no permission bits. Resolve the+ * caller's affordances for every visible child so row-level Share, Rename,+ * and Delete controls are consistent across files and folders instead of+ * only appearing after that row's overflow menu has been opened.+ *+ * The query keys are shared with the selected-row observer above. That keeps+ * the overflow menu and Manage dialog on the same cache entry while the+ * per-row queries remain fail-closed until their own server verdict arrives.+ */+ const rowAffordancesQueries = useQueries({+ queries: items.map(item => ({+ queryKey: desktopQueryKeys.gfsAffordances(+ sessionScope ?? 'anonymous',+ item.resourceId,+ DRIVE+ ),+ queryFn: () => window.clerum.gfs.affordances(item.resourceId, DRIVE),+ enabled:+ Boolean(sessionScope) &&+ Boolean(current) &&+ currentIsDirectory &&+ !authorityPending &&+ accessState === 'active',+ // Permission changes made outside this page must not leave row actions+ // stale when a folder is revisited.+ refetchOnMount: 'always' as const,+ })),+ })+ const rowAffordancesByResourceId = useMemo(() => {+ const byResourceId: Record<string, GfsBrowserAffordances> = {}+ if (authorityPending || accessState === 'revoked') return byResourceId+ items.forEach((item, index) => {+ const data = rowAffordancesQueries[index]?.data+ if (data) byResourceId[item.resourceId] = data as GfsBrowserAffordances+ })+ return byResourceId+ }, [accessState, authorityPending, items, rowAffordancesQueries])+ // Query-surfaced authorization failures (a refetch after revocation is the+ // normal way the loss is discovered under Infinity staleTime). Discovery is+ // the session/authority boundary; per-resource verdicts stay local.+ const queryAuthorizationError = [+ accessibleQuery.error+ ? { message: toMessage(accessibleQuery.error), surface: 'discovery' as const }+ : null,+ childrenQuery.error+ ? { message: toMessage(childrenQuery.error), surface: 'operation' as const }+ : null,+ affordancesQuery.error+ ? { message: toMessage(affordancesQuery.error), surface: 'operation' as const }+ : null,+ rowAffordancesQuery.error+ ? { message: toMessage(rowAffordancesQuery.error), surface: 'operation' as const }+ : null,+ ...rowAffordancesQueries.map(query =>+ query.error ? { message: toMessage(query.error), surface: 'operation' as const } : null+ ),+ grantsQuery.error+ ? { message: toMessage(grantsQuery.error), surface: 'operation' as const }+ : null,+ sharesQuery.error+ ? { message: toMessage(sharesQuery.error), surface: 'operation' as const }+ : null,+ ]+ .filter(+ (entry): entry is { message: string; surface: 'discovery' | 'operation' } => entry !== null+ )+ .find(entry => isGfsSessionAuthorityFailure(entry.message, entry.surface))+ useEffect(() => {+ if (!queryAuthorizationError || accessState === 'revoked') return+ revokeAccess()+ }, [accessState, queryAuthorizationError, revokeAccess])const accessibleResources = useMemo<GfsAccessibleResource[]>(() =>authorityPending@@ -684,6 +731,7 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {: ((affordancesQuery.data as GfsBrowserAffordances | undefined) ?? null),affordancesError: affordancesQuery.error ? toMessage(affordancesQuery.error) : null,loadingAffordances: affordancesQuery.isFetching,+ rowAffordancesByResourceId,rowAffordancesResourceId,setRowAffordancesResourceId,rowAffordances:diff --git a/desktop-app/ui/src/pages/FilesPage.tsx b/desktop-app/ui/src/pages/FilesPage.tsxindex 6f6fe2d62..62739d0ef 100644--- a/desktop-app/ui/src/pages/FilesPage.tsx+++ b/desktop-app/ui/src/pages/FilesPage.tsx@@ -911,42 +911,37 @@ export function FilesPage({ pushToast, pendingGfsUri, onPendingGfsUriHandled }:}/**- * Delete gate for list rows. Root "shared with me" rows already carry their- * permission bits; folder children don't, so their gate resolves lazily from- * the affordances of the one row whose ⋯ menu is open.+ * Folder children do not carry permission bits in the listing payload. The+ * controller resolves each visible row independently; retain the selected+ * row fallback for older controller shapes and while an overflow query is+ * transitioning.*/+ const rowAffordancesFor = (resource: GfsDriveResource) => {+ if (!currentIsFolder) return null+ return (+ ctrl.rowAffordancesByResourceId?.[resource.resourceId] ??+ (ctrl.rowAffordancesResourceId === resource.resourceId ? ctrl.rowAffordances : null)+ )+ }++ /** Delete gate for list rows. Shared-with-me rows carry their permission+ * bits directly; child rows use their own server-computed affordances. */const rowCanDelete = (resource: GfsDriveResource): boolean => {- if (currentIsFolder) {- return (- ctrl.rowAffordancesResourceId === resource.resourceId &&- Boolean(ctrl.rowAffordances?.held.includes('delete'))- )- }+ if (currentIsFolder) return hasBit(rowAffordancesFor(resource), 'delete')return Boolean(resource.permissions?.includes('delete'))}- /** Rename gate: same lazy resolution as rowCanDelete, but on the write bit- * (rename needs `write` on the resource itself). */+ /** Rename needs `write` on the resource itself. */const rowCanRename = (resource: GfsDriveResource): boolean => {- if (currentIsFolder) {- return (- ctrl.rowAffordancesResourceId === resource.resourceId &&- Boolean(ctrl.rowAffordances?.held.includes('write'))- )- }+ if (currentIsFolder) return hasBit(rowAffordancesFor(resource), 'write')return Boolean(resource.permissions?.includes('write'))}/** Manage gate: the ACL modal needs `manage_acl` (view-ACL = manage-ACL- * server-side). Same lazy row resolution as delete/rename — a read-only- * row must not offer a Manage entry that would only 403 on open. */+ * server-side). A read-only row must not offer a Manage entry that would+ * only 403 on open. */const rowCanManage = (resource: GfsDriveResource): boolean => {- if (currentIsFolder) {- return (- ctrl.rowAffordancesResourceId === resource.resourceId &&- Boolean(ctrl.rowAffordances?.held.includes('manage_acl'))- )- }+ if (currentIsFolder) return hasBit(rowAffordancesFor(resource), 'manage_acl')return Boolean(resource.permissions?.includes('manage_acl'))}diff --git a/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx b/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsxindex 39488cc99..5a04c0e9d 100644--- a/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx+++ b/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx@@ -28,6 +28,7 @@ function baseController() {loadingAffordances: false,rowAffordancesResourceId: null,setRowAffordancesResourceId: vi.fn(),+ rowAffordancesByResourceId: {},rowAffordances: null,rowAffordancesError: null,loadingAccessible: false,@@ -265,6 +266,94 @@ describe('FilesPage', () => {])})+ it('shows permission-backed share and rename actions for folder and file children', () => {+ const folder = {+ resourceId: 'folder-child',+ rid: 'folder-child',+ gfsUri: 'gfs://main/folder-child',+ drive: 'main',+ parentResourceId: 'parent-1',+ name: 'Assets',+ kind: 'directory' as const,+ path: '/Workspace/Assets',+ version: 2,+ bytes: 0,+ }+ const file = {+ resourceId: 'file-child',+ rid: 'file-child',+ gfsUri: 'gfs://main/file-child',+ drive: 'main',+ parentResourceId: 'parent-1',+ name: 'report.txt',+ kind: 'file' as const,+ path: '/Workspace/report.txt',+ version: 3,+ bytes: 12,+ }+ const readonlyFile = {+ ...file,+ resourceId: 'readonly-child',+ rid: 'readonly-child',+ gfsUri: 'gfs://main/readonly-child',+ name: 'readonly.txt',+ }+ hookMock.useGfsBrowserController.mockReturnValue({+ ...baseController(),+ current: {+ resourceId: 'parent-1',+ gfsUri: 'gfs://main/parent-1',+ name: 'Workspace',+ kind: 'directory',+ version: 1,+ bytes: 0,+ },+ items: [folder, file, readonlyFile],+ rowAffordancesByResourceId: {+ 'folder-child': {+ held: ['read', 'write', 'manage_acl'],+ canDelegate: false,+ grantableBits: [],+ canCreateShare: false,+ },+ 'file-child': {+ held: ['read', 'write', 'manage_acl'],+ canDelegate: false,+ grantableBits: [],+ canCreateShare: false,+ },+ 'readonly-child': {+ held: ['read'],+ canDelegate: false,+ grantableBits: [],+ canCreateShare: false,+ },+ },+ })++ renderFilesPage()++ const folderRow = screen.getByRole('button', { name: 'Open Assets' }).closest('.da-grid__row')+ const fileRow = screen.getByRole('button', { name: 'Open report.txt' }).closest('.da-grid__row')+ const readonlyRow = screen+ .getByRole('button', { name: 'Open readonly.txt' })+ .closest('.da-grid__row')+ expect(folderRow).not.toBeNull()+ expect(fileRow).not.toBeNull()+ expect(readonlyRow).not.toBeNull()++ expect(within(folderRow!).getByRole('button', { name: 'Share Assets' })).toBeTruthy()+ expect(within(folderRow!).getByRole('button', { name: 'Rename Assets' })).toBeTruthy()+ expect(within(folderRow!).queryByRole('button', { name: 'Download Assets' })).toBeNull()++ expect(within(fileRow!).getByRole('button', { name: 'Share report.txt' })).toBeTruthy()+ expect(within(fileRow!).getByRole('button', { name: 'Download report.txt' })).toBeTruthy()+ expect(within(fileRow!).getByRole('button', { name: 'Rename report.txt' })).toBeTruthy()++ expect(within(readonlyRow!).queryByRole('button', { name: 'Share readonly.txt' })).toBeNull()+ expect(within(readonlyRow!).queryByRole('button', { name: 'Rename readonly.txt' })).toBeNull()+ })+it('orders directories before files, both alphabetically by name', async () => {hookMock.useGfsBrowserController.mockReturnValue({...baseController(),