Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-ui): rp-032 revoke the URI shares that conflict with a role change
Mb7cf723cc4e7
diff --git a/control-ui/components/GfsGrantPanel.tsx b/control-ui/components/GfsGrantPanel.tsxindex b6307f130..2c4c47025 100644--- a/control-ui/components/GfsGrantPanel.tsx+++ b/control-ui/components/GfsGrantPanel.tsx@@ -40,6 +40,7 @@ import type {GfsExistingAccessItem,GfsFileAccessRow,GfsGrantPanelProps,+ GfsGrantShareEntry,GfsInheritedAccessCoverage,GfsInheritedAccessItem,GfsInheritedAccessSource,@@ -111,28 +112,47 @@ const ROLE_OPTIONS: SelectionDropdownOption[] = []/**- * Folders whose SHARING entries still grant Editor after a downgrade (R1-M5):- * a role change rewrites the folder's GRANT row only, so a share row survives- * it and the member keeps Editor through it. The confirmation discloses these- * BEFORE the operator approves; the post-change toast repeats the disclosure.+ * Folders whose SHARING entries still grant Editor after a role change+ * (R1-M5): the change rewrites the folder's GRANT row, so a share row+ * survives it and the member keeps Editor through it. RP-032 revokes the+ * sharing entries that CONFLICT with the requested role, so what survives is+ * exactly the share-only ancestors this panel cannot rewrite. The+ * confirmation discloses these BEFORE the operator approves; the post-change+ * toast repeats the disclosure.*/-function collectResidualEditorFolderNames(- sources: readonly GfsInheritedAccessSource[],- directShareEntries: readonly { permissions: string[] }[],- directName: string-): string[] {+function collectResidualEditorFolderNames(sources: readonly GfsInheritedAccessSource[]): string[] {return [- ...new Set([- ...sources+ ...new Set(+ sources.filter(source => source.shareEntries.some(entry => isEditorPermissions(entry.permissions)))- .map(source => source.name),- ...(directShareEntries.some(entry => isEditorPermissions(entry.permissions))- ? [directName]- : []),- ]),+ .map(source => source.name)+ ),]}+/**+ * The sharing entries that CONFLICT with the requested role (RP-032): a+ * Read-only downgrade must not leave effective Editor access through a link,+ * so every sharing entry on a rewritten resource that still grants Editor+ * bits is revoked with the role write. A sharing entry that already matches+ * the target role is not a conflict and survives the change.+ */+function conflictingShareEntries(+ entries: readonly GfsGrantShareEntry[],+ nextRole: AccessRole+): GfsGrantShareEntry[] {+ if (nextRole !== 'read') return []+ return entries.filter(entry => isEditorPermissions(entry.permissions))+}++/** Honest outcome copy for the sharing entries a role change revoked. */+function revokedSharesCopy(folderNames: string[]): string {+ if (folderNames.length === 1) {+ return `The sharing entry on ${folderNames[0]} was revoked.`+ }+ return `The sharing entries on ${joinFolderNames(folderNames)} were revoked.`+}+/*** A role promise is only as good as the coverage it was made under: when the* inherited walk did not complete, an ancestor the operator cannot see may@@ -590,6 +610,26 @@ export function GfsGrantPanel({ resource }: GfsGrantPanelProps): React.JSX.Eleme}}+ /**+ * RP-032 — revoke the sharing entries that CONFLICT with the requested role+ * on a resource whose grant this change rewrote. The server has no+ * share-update surface, so the client deletes them; a Read-only downgrade+ * must not leave effective Editor access through a link. Returns the+ * revoked row ids; a failure is thrown to the caller so the outcome stays+ * honest instead of silently claiming the member lost the access.+ */+ async function revokeConflictingShares(+ entries: readonly GfsGrantShareEntry[],+ nextRole: AccessRole+ ): Promise<string[]> {+ const revoked: string[] = []+ for (const entry of conflictingShareEntries(entries, nextRole)) {+ await deleteGfsShare(entry.rowId)+ revoked.push(entry.rowId)+ }+ return revoked+ }+async function updateAccessRole(item: GfsExistingAccessItem,nextRole: AccessRole,@@ -619,18 +659,37 @@ export function GfsGrantPanel({ resource }: GfsGrantPanelProps): React.JSX.Eleme// OR'd into a role write.inherit: item.grantInherit,})- // Shares survive role edits (R1-M5); when an editor-strength share- // remains, the effective role claim must say so.+ // RP-032: the rewritten grant is the member's access on this item, so a+ // sharing entry that still grants Editor goes with it — otherwise a+ // Read downgrade leaves effective Editor access through the link.+ let revokedNames: string[] = []+ try {+ const revoked = await revokeConflictingShares(item.shareEntries, nextRole)+ revokedNames = revoked.length > 0 ? [resource.name] : []+ } catch (caught) {+ if (!isAlreadyMissing(caught)) {+ setError(caught instanceof Error ? caught.message : 'Failed to revoke a sharing entry')+ }+ showToast(+ `Changed grant access to ${nextRole === 'editor' ? 'Editor' : 'Read-only'} on ${resource.name}. A sharing entry could not be revoked, so Editor access may remain.`,+ { tone: 'error' }+ )+ await loadExistingAccess()+ return+ }+ // What survives the change: the share-only ancestors this panel cannot+ // rewrite still grant Editor through their own sharing entries.const residualNames =- nextRole === 'read'- ? collectResidualEditorFolderNames(inheritedSources, item.shareEntries, resource.name)- : []+ nextRole === 'read' ? collectResidualEditorFolderNames(inheritedSources) : []const details: string[] = []if (skippedFolderNames.length > 0) {details.push(`Sharing details on ${joinFolderNames(skippedFolderNames)} could not be verified; existing access was kept.`)}+ if (revokedNames.length > 0) {+ details.push(revokedSharesCopy(revokedNames))+ }if (residualNames.length > 0) {details.push(`Sharing entries on ${joinFolderNames(residualNames)} still grant Editor access.`@@ -720,15 +779,11 @@ export function GfsGrantPanel({ resource }: GfsGrantPanelProps): React.JSX.ElemeresidualSources: plan.shareOnlySources,skippedFolderNames,// The surviving Editor shares are disclosed IN the confirmation, before- // the operator approves a role that will not remove them.+ // the operator approves a role that will not remove them. The folders+ // this change rewrites lose their conflicting sharing entries+ // (RP-032), so only the share-only ancestors remain.residualEditorFolderNames:- nextRole === 'read'- ? collectResidualEditorFolderNames(- [...plan.shareOnlySources, ...writable],- row.direct?.shareEntries ?? [],- resource.name- )- : [],+ nextRole === 'read' ? collectResidualEditorFolderNames(plan.shareOnlySources) : [],})}@@ -812,6 +867,7 @@ export function GfsGrantPanel({ resource }: GfsGrantPanelProps): React.JSX.Eleme}const affected = request.affectedconst affectedNames = affected.map(update => update.source.name)+ const revokedFolderNames: string[] = []let updated = 0for (const { source, permissions } of affected) {try {@@ -821,19 +877,34 @@ export function GfsGrantPanel({ resource }: GfsGrantPanelProps): React.JSX.Elemesubject: row.subject,permissions,// R1-M5: the folder grant's OWN scope flag (prepare guaranteed a- // known boolean) — share coverage is never OR'd in and the- // folder's share rows are never touched by a role change.+ // known boolean) — share coverage is never OR'd in.inherit: source.grantInherit === true,})updated += 1} catch (caught) {- if (isAlreadyMissing(caught)) {- updated += 1- continue+ if (!isAlreadyMissing(caught)) {+ await failPartially(+ caught,+ `Updated ${updated} of ${affected.length} folders — ${source.name} still grants access.`+ )+ return+ }+ // The grant row is already gone, but the folder's sharing entries+ // still grant access: they are revoked below.+ updated += 1+ }+ // RP-032: the rewritten grant is the member's access on this folder,+ // so a sharing entry that still grants Editor goes with it.+ try {+ const revoked = await revokeConflictingShares(source.shareEntries, request.nextRole)+ if (revoked.length > 0) revokedFolderNames.push(source.name)+ } catch (caught) {+ if (!isAlreadyMissing(caught)) {+ setError(caught instanceof Error ? caught.message : 'Failed to revoke a sharing entry')}await failPartially(caught,- `Updated ${updated} of ${affected.length} folders — ${source.name} still grants access.`+ `Updated ${updated} of ${affected.length} folders — a sharing entry on ${source.name} could not be revoked, so Editor access may remain.`)return}@@ -846,8 +917,8 @@ export function GfsGrantPanel({ resource }: GfsGrantPanelProps): React.JSX.ElemeresourceId: resource.resourceId,subject: row.subject,permissions,- // The direct GRANT's own scope flag; direct shares survive role- // edits (R1-M5) and a share-only direct row never gains a grant.+ // The direct GRANT's own scope flag; a share-only direct row+ // never gains a grant (R1-M5).inherit: row.direct.grantInherit,})} catch (caught) {@@ -857,23 +928,37 @@ export function GfsGrantPanel({ resource }: GfsGrantPanelProps): React.JSX.Eleme)return}+ // RP-032: the same revocation applies to this item's own sharing+ // entries — a Read downgrade must not leave effective Editor access+ // through a link on the item itself.+ try {+ const revoked = await revokeConflictingShares(row.direct.shareEntries, request.nextRole)+ if (revoked.length > 0) revokedFolderNames.push(resource.name)+ } catch (caught) {+ if (!isAlreadyMissing(caught)) {+ setError(caught instanceof Error ? caught.message : 'Failed to revoke a sharing entry')+ }+ await failPartially(+ caught,+ `Updated ${affected.length} of ${affected.length} folders — a sharing entry on ${resource.name} could not be revoked, so Editor access may remain.`+ )+ return+ }}- // Residual honesty (R1-M5): a downgrade never claims effective- // Read-only while a surviving share entry still grants Editor.+ // Residual honesty (RP-032): the conflicting sharing entries are revoked+ // with the change, so what can still grant Editor is the share-only+ // ancestor this panel cannot rewrite.const residualNames =- request.nextRole === 'read'- ? collectResidualEditorFolderNames(- [...request.residualSources, ...affected.map(update => update.source)],- row.direct?.shareEntries ?? [],- resource.name- )- : []+ request.nextRole === 'read' ? collectResidualEditorFolderNames(request.residualSources) : []const details: string[] = []if (request.skippedFolderNames.length > 0) {details.push(`Updated ${updated} of ${affected.length + request.skippedFolderNames.length} folders. Sharing details on ${joinFolderNames(request.skippedFolderNames)} could not be verified; existing access was kept.`)}+ if (revokedFolderNames.length > 0) {+ details.push(revokedSharesCopy(revokedFolderNames))+ }if (residualNames.length > 0) {details.push(`Sharing entries on ${joinFolderNames(residualNames)} still grant Editor access.`diff --git a/control-ui/components/GfsGrantPanel.types.ts b/control-ui/components/GfsGrantPanel.types.tsindex 06f1bfa7a..2ead1af05 100644--- a/control-ui/components/GfsGrantPanel.types.ts+++ b/control-ui/components/GfsGrantPanel.types.ts@@ -36,11 +36,23 @@ export interface GfsGrantPanelProps {/*** One displayed access row per subject: the direct grant plus any legacy URI* shares for that same subject, merged. Role changes rewrite only the grant- * row and preserve its own scope flag; share rows survive role edits and are- * removed only through explicit removal (R1-M5) — the server has no- * share-update surface, so a share-only row is not role-editable and a role- * change never creates a grant for it.+ * row and preserve its own scope flag; a share-only row is not role-editable+ * and a role change never creates a grant for it (R1-M5). A share row that+ * CONFLICTS with the requested role is revoked together with the grant write+ * (RP-032) — the server has no share-update surface — while a share row that+ * already matches the target role survives.*/+/**+ * One sharing row on a resource, with its own bits and descendant scope+ * (R1-M5). A role change preserves this per-row provenance; RP-032 revokes+ * only the rows whose bits CONFLICT with the requested role.+ */+export type GfsGrantShareEntry = {+ rowId: string+ permissions: string[]+ includeDescendants: boolean+}+export type GfsExistingAccessItem = {subject: GfsSubjectInputpermissions: string[]@@ -51,11 +63,7 @@ export type GfsExistingAccessItem = {grantId: string | nullshareIds: string[]/** Every direct share row with its own bits and descendant scope (R1-M5). */- shareEntries: Array<{- rowId: string- permissions: string[]- includeDescendants: boolean- }>+ shareEntries: GfsGrantShareEntry[]}/**@@ -94,11 +102,7 @@ export type GfsInheritedAccessSource = {/** The grant row's own scope flag; null when no grant row exists. */grantInherit: boolean | null/** Every contributing share row with its own bits and descendant scope. */- shareEntries: Array<{- rowId: string- permissions: string[]- includeDescendants: boolean- }>+ shareEntries: GfsGrantShareEntry[]}/**diff --git a/control-ui/components/GfsInheritedAccessDialog/types.ts b/control-ui/components/GfsInheritedAccessDialog/types.tsindex c90974d83..ebd4799f0 100644--- a/control-ui/components/GfsInheritedAccessDialog/types.ts+++ b/control-ui/components/GfsInheritedAccessDialog/types.ts@@ -23,11 +23,12 @@ export type GfsInheritedAccessDialogRequest = {/** change-role: the role that will replace the folders'/file's current role. */nextRole?: GfsInheritedAccessRole/**- * Folders whose SHARING entries still grant Editor after this change. A- * role change rewrites the folder's GRANT row only (R1-M5); a share row- * survives it, so the member keeps Editor through it. The confirmation says- * so BEFORE the user approves — the effective role it shows is not the whole- * truth, and only the post-change toast used to say so.+ * Folders whose SHARING entries still grant Editor after this change. The+ * change rewrites the folders' GRANT rows and revokes their conflicting+ * sharing entries (RP-032), so what survives is the share-only ancestor+ * this panel cannot rewrite. The confirmation says so BEFORE the user+ * approves — the effective role it shows is not the whole truth, and only+ * the post-change toast used to say so.*/residualEditorFolderNames?: string[]}diff --git a/control-ui/components/__tests__/GfsGrantPanel.inherited.test.tsx b/control-ui/components/__tests__/GfsGrantPanel.inherited.test.tsxindex 6ad328f29..aea554a51 100644--- a/control-ui/components/__tests__/GfsGrantPanel.inherited.test.tsx+++ b/control-ui/components/__tests__/GfsGrantPanel.inherited.test.tsx@@ -355,10 +355,10 @@ describe('GfsGrantPanel inherited access', () => {).toContain('Editor')})- // R1-M5 — a confirmed role change rewrites only the folder's GRANT (with- // its own scope flag); the folder's share rows survive as residual access- // and the outcome copy discloses the surviving Editor.- it('keeps the folder’s share rows on a confirmed role change and discloses the residual Editor', async () => {+ // RP-032 — a confirmed role change rewrites the folder's GRANT (with its+ // own scope flag) and revokes the sharing entry that still grants Editor,+ // so a Read downgrade cannot leave effective Editor access through a link.+ it('revokes the folder’s conflicting sharing entry on a confirmed role change', async () => {const FOLDER_SHARE_ID = '88888888-8888-8888-8888-888888888888'mockGetGfsGrants.mockImplementation(async resourceId => {if (resourceId === FOLDER_ID) {@@ -411,14 +411,15 @@ describe('GfsGrantPanel inherited access', () => {inherit: true,}))- // The role change NEVER deletes the folder's share row.- expect(mockDeleteGfsShare).not.toHaveBeenCalledWith(FOLDER_SHARE_ID)- // The honest outcome names the changed folder and discloses the residual.+ // The sharing entry that still granted Editor is revoked with the change.+ await waitFor(() => expect(mockDeleteGfsShare).toHaveBeenCalledWith(FOLDER_SHARE_ID))+ // The honest outcome names the revoked entry and claims no residual.expect(await screen.findByText(- 'Changed grant access to Read-only on team-docs. Sharing entries on team-docs still grant Editor access.'+ 'Changed grant access to Read-only on team-docs. The sharing entry on team-docs was revoked.')).toBeTruthy()+ expect(screen.queryByText(/still grant Editor access/)).toBeNull()})// R1-M5 — a share-only ancestor is never converted into a grant: nothing@@ -459,10 +460,10 @@ describe('GfsGrantPanel inherited access', () => {).toBeTruthy()})- // R1-M5 — a role change rewrites the folder's GRANT row only; the folder's- // SHARE row survives it, so the member keeps Editor through it. The- // confirmation must disclose that BEFORE the operator approves.- it('discloses the surviving Editor share in the confirmation before anything is applied', async () => {+ // RP-032 — a role change rewrites the folder's GRANT row and revokes the+ // folder's SHARE row that still grants Editor, so nothing survives on that+ // folder. The confirmation must NOT claim a surviving Editor there.+ it('claims no surviving Editor on a folder whose sharing entry is revoked', async () => {const FOLDER_SHARE_ID = '77777777-7777-4777-8777-777777777777'mockGetGfsGrants.mockImplementation(async resourceId => ({items:@@ -501,11 +502,12 @@ describe('GfsGrantPanel inherited access', () => {await chooseRole(miguelRow, 'Read')const dialog = await screen.findByRole('alertdialog')- expect(- within(dialog).getByText(- 'Sharing entries on team-docs still grant Editor access. This change does not remove them.'- )- ).toBeTruthy()+ expect(within(dialog).queryByText(/still grant Editor access/)).toBeNull()+ expect(mockPutGfsGrant).not.toHaveBeenCalled()++ fireEvent.click(within(dialog).getByRole('button', { name: 'Update role' }))++ await waitFor(() => expect(mockDeleteGfsShare).toHaveBeenCalledWith(FOLDER_SHARE_ID))})it('discloses inherited Editor shares when only a direct grant can be changed', async () => {@@ -561,6 +563,165 @@ describe('GfsGrantPanel inherited access', () => {).toBeTruthy()})+ // RP-032 — a Read downgrade must not leave effective Editor access through+ // a link: the sharing entry on the item itself is revoked with the grant+ // write, because the server has no share-update surface.+ it('revokes the item’s conflicting sharing entry when its role is downgraded', async () => {+ const FILE_SHARE_ID = 'abababab-abab-4bab-8bab-abababababab'+ mockGetGfsGrants.mockImplementation(async resourceId => ({+ items:+ resourceId === FILE_ID+ ? [+ {+ id: FILE_GRANT_ID,+ drive: 'main',+ resourceId: FILE_ID,+ subject: miguel,+ permissions: ['read', 'write'],+ inherit: false,+ },+ ]+ : [],+ }))+ mockGetGfsShares.mockImplementation(async resourceId => ({+ items:+ resourceId === FILE_ID+ ? [+ {+ id: FILE_SHARE_ID,+ drive: 'main',+ resourceId: FILE_ID,+ subject: miguel,+ permissions: ['read', 'write'],+ includeDescendants: true,+ },+ ]+ : [],+ }))+ renderPanel()++ const existing = await screen.findByRole('region', { name: 'People with access' })+ const miguelRow = await within(existing).findByTestId(miguelRowTestId)+ await chooseRole(miguelRow, 'Read')++ await waitFor(() =>+ expect(mockPutGfsGrant).toHaveBeenCalledWith({+ drive: 'main',+ resourceId: FILE_ID,+ subject: miguel,+ permissions: ['read', 'share'],+ inherit: false,+ })+ )+ await waitFor(() => expect(mockDeleteGfsShare).toHaveBeenCalledWith(FILE_SHARE_ID))+ expect(+ await screen.findByText(+ 'Changed grant access to Read-only on report.md. The sharing entry on report.md was revoked.'+ )+ ).toBeTruthy()+ })++ // RP-032 — only a CONFLICTING sharing entry is revoked: an entry that+ // already grants the target role is not a conflict and survives.+ it('keeps a sharing entry that already grants the target role', async () => {+ const FILE_SHARE_ID = 'cdcdcdcd-cdcd-4dcd-8dcd-cdcdcdcdcdcd'+ mockGetGfsGrants.mockImplementation(async resourceId => ({+ items:+ resourceId === FILE_ID+ ? [+ {+ id: FILE_GRANT_ID,+ drive: 'main',+ resourceId: FILE_ID,+ subject: miguel,+ permissions: ['read', 'write'],+ inherit: false,+ },+ ]+ : [],+ }))+ mockGetGfsShares.mockImplementation(async resourceId => ({+ items:+ resourceId === FILE_ID+ ? [+ {+ id: FILE_SHARE_ID,+ drive: 'main',+ resourceId: FILE_ID,+ subject: miguel,+ permissions: ['read'],+ includeDescendants: true,+ },+ ]+ : [],+ }))+ renderPanel()++ const existing = await screen.findByRole('region', { name: 'People with access' })+ const miguelRow = await within(existing).findByTestId(miguelRowTestId)+ await chooseRole(miguelRow, 'Read')++ await waitFor(() => expect(mockPutGfsGrant).toHaveBeenCalledTimes(1))+ expect(mockDeleteGfsShare).not.toHaveBeenCalled()+ expect(await screen.findByText('Miguel is now Read-only.')).toBeTruthy()+ })++ // RP-032 — a revocation that fails is a PARTIAL outcome: the role changed,+ // but the link may still grant Editor, and the copy must say so.+ it('states the true partial outcome when a sharing entry cannot be revoked', async () => {+ const FILE_SHARE_ID = 'efefefef-efef-4fef-8fef-efefefefefef'+ mockGetGfsGrants.mockImplementation(async resourceId => ({+ items:+ resourceId === FILE_ID+ ? [+ {+ id: FILE_GRANT_ID,+ drive: 'main',+ resourceId: FILE_ID,+ subject: miguel,+ permissions: ['read', 'write'],+ inherit: false,+ },+ ]+ : [],+ }))+ mockGetGfsShares.mockImplementation(async resourceId => ({+ items:+ resourceId === FILE_ID+ ? [+ {+ id: FILE_SHARE_ID,+ drive: 'main',+ resourceId: FILE_ID,+ subject: miguel,+ permissions: ['read', 'write'],+ includeDescendants: true,+ },+ ]+ : [],+ }))+ mockDeleteGfsShare.mockRejectedValueOnce(+ Object.assign(new Error('403 share_revocation_rejected'), {+ status: 403,+ code: 'share_revocation_rejected',+ serverMessage: 'share_revocation_rejected',+ })+ )+ renderPanel()++ const existing = await screen.findByRole('region', { name: 'People with access' })+ const miguelRow = await within(existing).findByTestId(miguelRowTestId)+ await chooseRole(miguelRow, 'Read')++ expect(+ await screen.findByText(+ 'Changed grant access to Read-only on report.md. A sharing entry could not be revoked, so Editor access may remain.'+ )+ ).toBeTruthy()+ const alert = await screen.findByRole('alert')+ expect(alert.textContent).toContain('share_revocation_rejected')+ })+// A role promise is only as good as the coverage it was made under: an// ancestor the operator cannot see may still grant Editor, so the success// copy must say what was NOT verified instead of promising an effectivediff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex 0a9d88d39..8fea81289 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.744",+ "version": "0.1.745","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.744",+ "version": "0.1.745","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 3437fedb6..bc2c54b6a 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.744",+ "version": "0.1.745","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",