Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(evendrive): judge parent-role bits by the folder's affordances (R1-M1)

Mfa08117f7155
diff --git a/desktop-app/ui/src/pages/FilesPage.tsx b/desktop-app/ui/src/pages/FilesPage.tsx
index 08c839f76..bad6c81be 100644
--- a/desktop-app/ui/src/pages/FilesPage.tsx
+++ b/desktop-app/ui/src/pages/FilesPage.tsx
@@ -76,6 +76,12 @@ function roleForAccessPermissions(permissions: string[]): GfsAccessRole {
: 'read'
}
+/** The permission set a role stands for: hosts cap at read/write. */
+function rolePermissionRequest(subjectType: string, role: GfsAccessRole): string[] {
+ if (subjectType === 'host') return role === 'editor' ? ['read', 'write'] : ['read']
+ return role === 'editor' ? ['read', 'write', 'delete', 'manage_acl', 'share'] : ['read', 'share']
+}
+
function hasDraggedFiles(event: ReactDragEvent<HTMLElement>): boolean {
return Array.from(event.dataTransfer.types || []).includes('Files')
}
@@ -235,9 +241,16 @@ export function FilesPage({ pushToast, pendingGfsUri, onPendingGfsUriHandled }:
const [shareDetailsOpen, setShareDetailsOpen] = useState(false)
const [updatingAccessRole, setUpdatingAccessRole] = useState(false)
// Pending parent-folder confirmation (role change or removal) for a member
- // whose file access is inherited from an ancestor folder.
+ // whose file access is inherited from an ancestor folder. change-role
+ // carries the bits the pre-flight validated on the parent folder itself.
const [parentUpdate, setParentUpdate] = useState<
- | { row: GfsMergedAccessRow; label: string; mode: 'change-role'; nextRole: GfsAccessRole }
+ | {
+ row: GfsMergedAccessRow
+ label: string
+ mode: 'change-role'
+ nextRole: GfsAccessRole
+ parentBits: string[]
+ }
| { row: GfsMergedAccessRow; label: string; mode: 'remove' }
| null
>(null)
@@ -550,15 +563,9 @@ export function FilesPage({ pushToast, pendingGfsUri, onPendingGfsUriHandled }:
label: string,
role: GfsAccessRole
) => {
- const requested =
- item.subject.type === 'host'
- ? role === 'editor'
- ? ['read', 'write']
- : ['read']
- : role === 'editor'
- ? ['read', 'write', 'delete', 'manage_acl', 'share']
- : ['read', 'share']
- const bits = requested.filter(bit => affordances?.grantableBits.includes(bit))
+ const bits = rolePermissionRequest(item.subject.type, role).filter(bit =>
+ affordances?.grantableBits.includes(bit)
+ )
const subjectKey = item.subject.id
? `${item.subject.type}:${item.subject.id}`
: item.subject.type
@@ -578,12 +585,42 @@ export function FilesPage({ pushToast, pendingGfsUri, onPendingGfsUriHandled }:
// A merged row whose access comes from a parent folder: any edit (upgrade,
// downgrade, or removal — no exceptions) is confirmed against the parent
// folder before anything is sent. Cancel reverts the dropdown untouched.
- const handleInheritedRoleChange = (
+ const handleInheritedRoleChange = async (
row: GfsMergedAccessRow,
label: string,
role: GfsAccessRole
) => {
- setParentUpdate({ row, label, mode: 'change-role', nextRole: role })
+ const inherited = row.inherited
+ if (!inherited) return
+ const source = inherited.source
+ const subject = inherited.subject
+ // Pre-flight: the parent grant is judged by the PARENT folder's own
+ // grantable bits, never by the open file's affordances (which may be
+ // missing or narrower). A role the folder cannot grant fails loudly here
+ // — the confirmation never opens with a promise it cannot keep.
+ let folderAffordances: { canDelegate: boolean; grantableBits: string[] }
+ try {
+ folderAffordances = await window.clerum.gfs.affordances(source.resourceId, GFS_DRIVE_MAIN)
+ } catch (affordancesError) {
+ if (failClosedOnAuthorizationError(affordancesError)) return
+ pushToast?.(describeGfsGrantError(affordancesError).message, 'error')
+ return
+ }
+ const parentBits = rolePermissionRequest(subject.type, role).filter(bit =>
+ folderAffordances.grantableBits.includes(bit)
+ )
+ const expressesRole =
+ role === 'editor'
+ ? parentBits.includes('read') && parentBits.includes('write')
+ : parentBits.includes('read')
+ if (!folderAffordances.canDelegate || !expressesRole) {
+ pushToast?.(
+ `Your access on ${source.name} does not allow making ${label} ${role === 'editor' ? 'an Editor' : 'Read-only'}.`,
+ 'error'
+ )
+ return
+ }
+ setParentUpdate({ row, label, mode: 'change-role', nextRole: role, parentBits })
}
const handleInheritedRemove = (row: GfsMergedAccessRow, label: string) => {
@@ -605,25 +642,26 @@ export function FilesPage({ pushToast, pendingGfsUri, onPendingGfsUriHandled }:
setUpdatingAccessRole(true)
try {
if (request.mode === 'change-role') {
- const requested =
- subject.type === 'host'
- ? request.nextRole === 'editor'
- ? ['read', 'write']
- : ['read']
- : request.nextRole === 'editor'
- ? ['read', 'write', 'delete', 'manage_acl', 'share']
- : ['read', 'share']
- const bits = requested.filter(bit => affordances?.grantableBits.includes(bit))
- // The parent folder's grant is updated first and keeps cascading to
+ // The parent folder's grant is updated first with the bits the
+ // pre-flight validated on the folder itself, and keeps cascading to
// everything inside; its superseded share rows are consolidated.
- await window.clerum.gfs.grant(source.resourceId, [subjectKey], bits, GFS_DRIVE_MAIN, true)
+ await window.clerum.gfs.grant(
+ source.resourceId,
+ [subjectKey],
+ request.parentBits,
+ GFS_DRIVE_MAIN,
+ true
+ )
for (const shareId of source.shareIds) await ctrl.revokeShare(shareId)
// The file's own direct rows are aligned so they cannot mask the
// confirmed role: the grant upsert expresses the new role and every
// direct file share for the member is revoked after it — a stale
// editor share would otherwise keep the member an Editor.
if (request.row.grant || request.row.shares.length > 0) {
- await ctrl.grant([subjectKey], bits, request.row.grant?.inherit ?? false)
+ const fileBits = rolePermissionRequest(subject.type, request.nextRole).filter(bit =>
+ affordances?.grantableBits.includes(bit)
+ )
+ await ctrl.grant([subjectKey], fileBits, request.row.grant?.inherit ?? false)
for (const share of request.row.shares) await ctrl.revokeShare(share.id)
}
pushToast?.(
diff --git a/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx b/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx
index 8bf7efa23..debb7a0d4 100644
--- a/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx
+++ b/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx
@@ -1717,6 +1717,12 @@ describe('FilesPage', () => {
gfs: {
getPathForFile: vi.fn((file: File) => `/tmp/${file.name}`),
grant: vi.fn(async () => undefined),
+ affordances: vi.fn(async () => ({
+ held: ['read', 'write', 'share', 'manage_acl'],
+ canDelegate: true,
+ grantableBits: ['read', 'share', 'write', 'delete', 'manage_acl'],
+ canCreateShare: true,
+ })),
},
agents: { listMine: vi.fn(async () => []) },
team: {
@@ -1886,6 +1892,103 @@ describe('FilesPage', () => {
)
})
+ // R1-M1 — the parent grant's bits are judged by the PARENT folder's
+ // grantable bits, never by the open file's affordances (which may be null
+ // or narrower than what the folder allows).
+ it('derives the parent grant bits from the parent folder affordances, not the file', async () => {
+ installInheritedDirectoryMocks()
+ const folderAffordances = (window.clerum.gfs as { affordances: ReturnType<typeof vi.fn> })
+ .affordances
+ const parentGrant = (window.clerum.gfs as { grant: ReturnType<typeof vi.fn> }).grant
+ const pushToast = vi.fn()
+ // The file's grantable bits came back empty (failed/narrow probe) — the
+ // legacy path built the parent bits from these and confirmed a [] grant.
+ hookMock.useGfsBrowserController.mockReturnValue(
+ inheritedFileController({
+ affordances: {
+ held: ['read', 'write', 'share', 'manage_acl'],
+ canDelegate: true,
+ grantableBits: [],
+ canCreateShare: false,
+ },
+ })
+ )
+
+ renderFilesPage(pushToast)
+ await openManageDialog('report.txt')
+ const manageDialog = await screen.findByRole('dialog', { name: 'Share file report.txt' })
+ const row = await within(manageDialog).findByTestId('gfs-access-row-inherited-user')
+
+ await act(async () => {
+ fireEvent.click(within(row).getByRole('button', { name: 'Access role for Test Two' }))
+ })
+ await act(async () => {
+ fireEvent.click(screen.getByRole('option', { name: 'Read' }))
+ })
+
+ // Pre-flight judged the parent folder itself before opening the modal.
+ await waitFor(() => expect(folderAffordances).toHaveBeenCalledWith('folder-1', 'main'))
+ const confirmDialog = await screen.findByRole('alertdialog')
+ await act(async () => {
+ fireEvent.click(within(confirmDialog).getByRole('button', { name: 'Update role' }))
+ })
+
+ await waitFor(() =>
+ expect(parentGrant).toHaveBeenCalledWith(
+ 'folder-1',
+ ['user:user-2'],
+ ['read', 'share'],
+ 'main',
+ true
+ )
+ )
+ expect(pushToast).toHaveBeenCalledWith(
+ 'Test Two is now Read-only on Team folder and everything inside it',
+ 'success'
+ )
+ })
+
+ it('refuses a role the parent folder cannot grant, before opening the confirmation', async () => {
+ installInheritedDirectoryMocks()
+ ;(window.clerum.gfs as { affordances: ReturnType<typeof vi.fn> }).affordances.mockResolvedValue(
+ {
+ held: ['read', 'share'],
+ canDelegate: true,
+ grantableBits: ['read', 'share'],
+ canCreateShare: false,
+ }
+ )
+ const parentGrant = (window.clerum.gfs as { grant: ReturnType<typeof vi.fn> }).grant
+ const pushToast = vi.fn()
+ hookMock.useGfsBrowserController.mockReturnValue(inheritedFileController())
+
+ renderFilesPage(pushToast)
+ await openManageDialog('report.txt')
+ const manageDialog = await screen.findByRole('dialog', { name: 'Share file report.txt' })
+ const row = await within(manageDialog).findByTestId('gfs-access-row-inherited-user')
+
+ // Editor needs write on the parent; this folder cannot grant it.
+ await act(async () => {
+ fireEvent.click(within(row).getByRole('button', { name: 'Access role for Test Two' }))
+ })
+ await act(async () => {
+ fireEvent.click(screen.getByRole('option', { name: 'Editor' }))
+ })
+
+ await waitFor(() =>
+ expect(pushToast).toHaveBeenCalledWith(
+ 'Your access on Team folder does not allow making Test Two an Editor.',
+ 'error'
+ )
+ )
+ expect(screen.queryByRole('alertdialog')).toBeNull()
+ expect(parentGrant).not.toHaveBeenCalled()
+ // The dropdown reverts to the server-backed role.
+ expect(
+ within(row).getByRole('button', { name: 'Access role for Test Two' }).textContent
+ ).toContain('Editor')
+ })
+
it('removes an inherited member from the parent folder after confirmation', async () => {
installInheritedDirectoryMocks()
const revokeGrant = vi.fn(async () => undefined)