Skip to content

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

TypeScript

fix(control-ui): merge share-modal rows per subject and make every role toggleable

M624757b63702
diff --git a/control-ui/components/GfsGrantPanel.tsx b/control-ui/components/GfsGrantPanel.tsx
index e9462cc5e..b6da5efad 100644
--- a/control-ui/components/GfsGrantPanel.tsx
+++ b/control-ui/components/GfsGrantPanel.tsx
@@ -6,13 +6,13 @@ import { useConfirmDialog } from '@components/ConfirmDialog'
import { GfsSubjectPicker } from '@components/GfsSubjectPicker'
import { SelectionDropdown } from '@components/SelectionDropdown'
import type { SelectionDropdownOption } from '@components/SelectionDropdown/types'
-import { IconFolder } from '@components/Sidebar/icons'
import { useToast } from '@components/Toast'
import { Button, CheckboxField } from '@components/ui'
import { GFS_MAX_BULK_SUBJECTS } from '@constants/gfsGrantSubjects'
import {
type AdminUser,
type GfsGrantError,
+ type GfsSubjectInput,
type HostResource,
type TeamListItem,
type WorkflowRecipeResource,
@@ -105,10 +105,33 @@ export function GfsGrantPanel({ resource }: GfsGrantPanelProps): React.JSX.Eleme
getGfsShares(resource.resourceId, DRIVE, controller.signal),
])
if (requestId !== existingAccessRequest.current) return
- setExistingAccess([
- ...grantResult.items.map(item => ({ ...item, kind: 'grant' as const })),
- ...shareResult.items.map(item => ({ ...item, kind: 'share' as const })),
- ])
+ // Merge per subject: legacy flows could leave the same principal with
+ // BOTH a grant and a URI share (rendered as duplicate rows with
+ // different toggle semantics). One row per subject, permissions and
+ // descendant coverage unioned, both row ids retained for revoke.
+ const bySubject = new Map<string, GfsExistingAccessItem>()
+ const entryFor = (subject: GfsSubjectInput): GfsExistingAccessItem => {
+ const key = `${subject.type}:${subject.id ?? ''}`
+ let entry = bySubject.get(key)
+ if (!entry) {
+ entry = { subject, permissions: [], inherit: false, grantId: null, shareIds: [] }
+ bySubject.set(key, entry)
+ }
+ return entry
+ }
+ for (const grant of grantResult.items) {
+ const entry = entryFor(grant.subject)
+ entry.grantId = grant.id
+ entry.inherit = entry.inherit || grant.inherit
+ entry.permissions = [...new Set([...entry.permissions, ...grant.permissions])]
+ }
+ for (const share of shareResult.items) {
+ const entry = entryFor(share.subject)
+ entry.shareIds.push(share.id)
+ entry.inherit = entry.inherit || share.includeDescendants
+ entry.permissions = [...new Set([...entry.permissions, ...share.permissions])]
+ }
+ setExistingAccess([...bySubject.values()])
} catch (caught) {
if (requestId !== existingAccessRequest.current) return
setExistingAccessError(
@@ -301,8 +324,9 @@ export function GfsGrantPanel({ resource }: GfsGrantPanelProps): React.JSX.Eleme
numeric: true,
sensitivity: 'base',
}) ||
- left.kind.localeCompare(right.kind) ||
- left.id.localeCompare(right.id)
+ `${left.subject.type}:${left.subject.id ?? ''}`.localeCompare(
+ `${right.subject.type}:${right.subject.id ?? ''}`
+ )
),
[existingAccess, subjectLabel]
)
@@ -311,7 +335,7 @@ export function GfsGrantPanel({ resource }: GfsGrantPanelProps): React.JSX.Eleme
const label = subjectLabel(item)
const confirmed = await confirm({
title: 'Remove access?',
- message: `Remove ${item.kind} access for ${label} from "${resource.name}"?`,
+ message: `Remove access for ${label} from "${resource.name}"?`,
confirmLabel: 'Remove access',
tone: 'danger',
})
@@ -319,8 +343,8 @@ export function GfsGrantPanel({ resource }: GfsGrantPanelProps): React.JSX.Eleme
setBusy(true)
setError('')
try {
- if (item.kind === 'grant') await deleteGfsGrant(item.id)
- else await deleteGfsShare(item.id)
+ if (item.grantId) await deleteGfsGrant(item.grantId)
+ for (const shareId of item.shareIds) await deleteGfsShare(shareId)
showToast('Access removed.', { tone: 'success' })
await loadExistingAccess()
} catch (caught) {
@@ -340,7 +364,6 @@ export function GfsGrantPanel({ resource }: GfsGrantPanelProps): React.JSX.Eleme
}
async function updateAccessRole(item: GfsExistingAccessItem, nextRole: AccessRole) {
- if (item.kind !== 'grant') return
const permissions = rolePermissions(nextRole, hostOnlySubject(item.subject))
setBusy(true)
setError('')
@@ -352,6 +375,9 @@ export function GfsGrantPanel({ resource }: GfsGrantPanelProps): React.JSX.Eleme
permissions,
inherit: item.inherit,
})
+ // The upserted grant supersedes any legacy URI share for this subject;
+ // the server has no share-update surface, so consolidation happens here.
+ for (const shareId of item.shareIds) await deleteGfsShare(shareId)
showToast(
`${subjectLabel(item)} is now ${nextRole === 'editor' ? 'an Editor' : 'Read-only'}.`,
{
@@ -464,49 +490,35 @@ export function GfsGrantPanel({ resource }: GfsGrantPanelProps): React.JSX.Eleme
<RecordList className="cu-gfs-existing-access__list" aria-label="Resource access">
{sortedExistingAccess.map(item => {
const label = subjectLabel(item)
- const coversDescendants =
- item.kind === 'grant' ? item.inherit : item.includeDescendants
+ const kindLabel = item.grantId ? 'direct grant' : 'direct share'
return (
<RecordListRow
className="cu-gfs-existing-access__item"
- data-testid={`gfs-access-row-${item.kind}-${item.id}`}
- data-access-id={item.id}
- key={`${item.kind}:${item.id}`}
+ data-testid={`gfs-access-row-${item.subject.type}`}
+ data-access-id={item.grantId ?? item.shareIds[0]}
+ key={`${item.subject.type}:${item.grantId ?? item.shareIds[0]}`}
>
<span className="cu-gfs-existing-access__identity">
<span className="cu-gfs-existing-access__subject">{label}</span>
<span className="cu-gfs-existing-access__detail">
- {item.kind === 'grant' ? 'Direct grant' : 'Direct share'} ·{' '}
- {item.subject.type}
+ {item.grantId ? 'Direct grant' : 'Direct share'} · {item.subject.type}
</span>
</span>
<span className="cu-gfs-existing-access__meta">
- {item.kind === 'grant' ? (
- <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)
- }
- options={ROLE_OPTIONS}
- placeholder="Role"
- searchable={false}
- showSelectedChips={false}
- value={[roleForPermissions(item.permissions)]}
- />
- ) : (
- <span className="cu-gfs-existing-access__role-label">
- {roleForPermissions(item.permissions) === 'editor' ? 'Editor' : 'Read'}
- </span>
- )}
- {coversDescendants ? (
- <span className="cu-gfs-existing-access__inherit">
- <IconFolder />
- Includes contents
- </span>
- ) : null}
+ <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)
+ }
+ options={ROLE_OPTIONS}
+ placeholder="Role"
+ searchable={false}
+ showSelectedChips={false}
+ value={[roleForPermissions(item.permissions)]}
+ />
</span>
<RowActionMenu
actions={[
@@ -518,7 +530,7 @@ export function GfsGrantPanel({ resource }: GfsGrantPanelProps): React.JSX.Eleme
onSelect: () => void revokeAccess(item),
},
]}
- ariaLabel={`Actions for ${item.kind === 'grant' ? 'direct grant to' : 'direct share to'} ${label}`}
+ ariaLabel={`Actions for ${kindLabel} to ${label}`}
/>
</RecordListRow>
)
diff --git a/control-ui/components/GfsGrantPanel.types.ts b/control-ui/components/GfsGrantPanel.types.ts
index 1e5a69b00..63f04212c 100644
--- a/control-ui/components/GfsGrantPanel.types.ts
+++ b/control-ui/components/GfsGrantPanel.types.ts
@@ -1,4 +1,4 @@
-import type { GfsBulkGrantSubjectInput, GfsGrantListItem, GfsShareListItem } from '@lib/api'
+import type { GfsBulkGrantSubjectInput, GfsSubjectInput } from '@lib/api'
export type GfsGrantSubjectType =
| 'user'
@@ -31,6 +31,17 @@ export interface GfsGrantPanelProps {
resource: GfsGrantResource
}
-export type GfsExistingAccessItem =
- | ({ kind: 'grant' } & GfsGrantListItem)
- | ({ kind: 'share' } & GfsShareListItem)
+/**
+ * One displayed access row per subject: the direct grant plus any legacy URI
+ * shares for that same subject, merged. The server has no share-update
+ * surface, so any role change (or revoke) consolidates the subject onto the
+ * single grant — the upsert preserves effective permissions (inherit ⊔
+ * includeDescendants) and the superseded share rows are deleted.
+ */
+export type GfsExistingAccessItem = {
+ subject: GfsSubjectInput
+ permissions: string[]
+ inherit: boolean
+ grantId: string | null
+ shareIds: string[]
+}
diff --git a/control-ui/components/__tests__/GfsGrantPanel.bulk.test.tsx b/control-ui/components/__tests__/GfsGrantPanel.bulk.test.tsx
index aea5ae784..2e5d2c1de 100644
--- a/control-ui/components/__tests__/GfsGrantPanel.bulk.test.tsx
+++ b/control-ui/components/__tests__/GfsGrantPanel.bulk.test.tsx
@@ -202,7 +202,7 @@ describe('GfsGrantPanel bulk access', () => {
)
})
- it('distinguishes direct grant and share menus for the same principal', async () => {
+ it('merges a legacy grant and share for the same principal into one toggleable row', async () => {
mockGetGfsGrants.mockResolvedValue({
items: [
{
@@ -223,20 +223,84 @@ describe('GfsGrantPanel bulk access', () => {
resourceId: resource.resourceId,
subject: userSubject,
permissions: ['read'],
- includeDescendants: false,
+ includeDescendants: true,
},
],
})
+ mockPutGfsGrant.mockResolvedValue(successfulMutation(userSubject))
renderPanel()
const existing = await screen.findByRole('region', { name: 'People with access' })
+ // ONE row for the principal — not one per backend row kind.
+ expect(within(existing).getAllByText('Ada Lovelace')).toHaveLength(1)
+ expect(within(existing).getByText('Direct grant · user')).toBeTruthy()
expect(
within(existing).getByRole('button', { name: 'Actions for direct grant to Ada Lovelace' })
- ).toBeInTheDocument()
+ ).toBeTruthy()
expect(
- within(existing).getByRole('button', { name: 'Actions for direct share to Ada Lovelace' })
- ).toBeInTheDocument()
+ within(existing).queryByRole('button', { name: 'Actions for direct share to Ada Lovelace' })
+ ).toBeNull()
+ // The descendant-coverage badge stays out of the row.
+ expect(within(existing).queryByText('Includes contents')).toBeNull()
+
+ // Role change consolidates: the grant upsert supersedes the legacy share.
+ fireEvent.click(within(existing).getByRole('button', { name: 'Access role for Ada Lovelace' }))
+ fireEvent.click(screen.getByRole('option', { name: 'Editor' }))
+
+ await waitFor(() =>
+ expect(mockPutGfsGrant).toHaveBeenCalledWith({
+ drive: 'main',
+ resourceId: resource.resourceId,
+ subject: userSubject,
+ permissions: ['read', 'write', 'delete', 'manage_acl', 'share'],
+ inherit: true,
+ })
+ )
+ await waitFor(() =>
+ expect(mockDeleteGfsShare).toHaveBeenCalledWith('44444444-4444-4444-4444-444444444444')
+ )
+ })
+
+ it('offers a toggleable role for a share-only principal and migrates it on change', async () => {
+ mockGetGfsShares.mockResolvedValue({
+ items: [
+ {
+ id: '44444444-4444-4444-4444-444444444444',
+ drive: 'main',
+ resourceId: resource.resourceId,
+ subject: userSubject,
+ permissions: ['read'],
+ includeDescendants: true,
+ },
+ ],
+ })
+ mockPutGfsGrant.mockResolvedValue(successfulMutation(userSubject))
+
+ renderPanel()
+
+ const existing = await screen.findByRole('region', { name: 'People with access' })
+ const role = await within(existing).findByRole('button', {
+ name: 'Access role for Ada Lovelace',
+ })
+ expect(role).toHaveTextContent('Read')
+ expect(within(existing).getByText('Direct share · user')).toBeTruthy()
+
+ fireEvent.click(role)
+ fireEvent.click(screen.getByRole('option', { name: 'Editor' }))
+
+ await waitFor(() =>
+ expect(mockPutGfsGrant).toHaveBeenCalledWith({
+ drive: 'main',
+ resourceId: resource.resourceId,
+ subject: userSubject,
+ permissions: ['read', 'write', 'delete', 'manage_acl', 'share'],
+ inherit: true,
+ })
+ )
+ await waitFor(() =>
+ expect(mockDeleteGfsShare).toHaveBeenCalledWith('44444444-4444-4444-4444-444444444444')
+ )
})
it('sorts access records by visible principal identity', async () => {
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index aa42f899a..ac1890943 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.568",
+ "version": "0.1.569",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.568",
+ "version": "0.1.569",
"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.json
index 2a6f933b3..d7cdcecc9 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.568",
+ "version": "0.1.569",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",