Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
refactor(desktop): consume shared inherited-access policy
M060d8b91321a
diff --git a/desktop-app/ui/src/gfs/inheritedAccess.ts b/desktop-app/ui/src/gfs/inheritedAccess.tsindex e39fe40b7..be79ed4da 100644--- a/desktop-app/ui/src/gfs/inheritedAccess.ts+++ b/desktop-app/ui/src/gfs/inheritedAccess.ts@@ -13,11 +13,12 @@ export { planInheritedRoleChange, strongestInheritedSource } from './inheritedAc* includeDescendants=true — the server's allow() rule. Derivation is* all-or-nothing: if a required ancestor or its ACL cannot be read, callers* must show an incomplete-access notice rather than an empty/partial result.- * Rows are merged per subject through the pure merge core- * (`inheritedAccessMerge.ts`, property- * tested in R1-M4); EVERY contributing ancestor folder is kept as an editable- * source, so a confirmed removal revokes all of them and a confirmed- * downgrade lowers each one above the target role (R1-H1).+ * Rows are merged per subject through the shared pure core+ * (`@clerum/gfs-interaction-policy`, via the app adapter in+ * `inheritedAccessMerge.ts`, property tested in R1-M4); EVERY contributing+ * ancestor folder is kept as an editable source, so a confirmed removal+ * revokes all of them and a confirmed downgrade lowers each one above the+ * target role (R1-H1).*/const DEFAULT_DRIVE = 'main'diff --git a/desktop-app/ui/src/gfs/inheritedAccessMerge.ts b/desktop-app/ui/src/gfs/inheritedAccessMerge.tsindex 40ec8cf34..8c705c188 100644--- a/desktop-app/ui/src/gfs/inheritedAccessMerge.ts+++ b/desktop-app/ui/src/gfs/inheritedAccessMerge.ts@@ -1,39 +1,58 @@+import {+ gfsRoleRank,+ gfsSubjectKeyOf,+ isEditorGfsPermissions,+ mergeGfsInheritedAccessItem as mergeInheritedAccessPolicy,+ strongestGfsInheritedSource,+} from '@clerum/gfs-interaction-policy'+import type {+ GfsInheritedAccessItem as PolicyInheritedAccessItem,+ GfsInheritedAccessSource as PolicyInheritedAccessSource,+} from '@clerum/gfs-interaction-policy'import type { GfsInheritedAccessItem, GfsInheritedAccessSource } from './delegation.types'/**- * Pure merge core for the client-side inherited-access derivation (R1-M4).- * No window, no network — everything here is a function of its inputs, which- * is what the fast-check property suite in `__tests__/inheritedAccessMerge.prop.test.ts`- * relies on: merge idempotency, no source dropped, effective role = strongest- * of sources, and a total role order.+ * Desktop adapter over the shared inherited-access policy+ * (`@clerum/gfs-interaction-policy`), which owns the pure merge/planner+ * semantics (property tested there). This module keeps the app's historical+ * export surface and contribution shape stable: the Desktop walker hands+ * over rows pre-filtered to inheriting grants and descendant-covering shares,+ * so every translated contribution carries inherit/includeDescendants=true+ * and the same row ids the legacy core recorded.*//** Stable per-subject merge key. */export function inheritedSubjectKey(subject: { type: string; id?: string }): string {- return `${subject.type}:${subject.id ?? ''}`+ return gfsSubjectKeyOf(subject)}/** Editor-strength rows (write/delete/manage_acl) outrank read-only rows. */-export function isEditorPermissions(permissions: string[]): boolean {- return permissions.some(permission => ['write', 'delete', 'manage_acl'].includes(permission))-}+export const isEditorPermissions = isEditorGfsPermissions/** Total role order over permission sets: Read (0) < Editor (1). */-export function roleRank(permissions: string[]): number {- return isEditorPermissions(permissions) ? 1 : 0+export const roleRank = gfsRoleRank++/** One inheriting row on an ancestor folder, carrying its mutable row ids. */+export interface InheritedAccessContribution {+ subject: { type: string; id?: string }+ permissions: string[]+ grantId: string | null+ shareIds: string[]+}++/** The ancestor folder a contribution was collected from. */+export interface InheritedAccessFolder {+ resourceId: string+ name: string}/** The strongest contributing folder: editor beats read, nearest among equals. */export function strongestInheritedSource(sources: GfsInheritedAccessSource[]): GfsInheritedAccessSource | null {- return sources.reduce<GfsInheritedAccessSource | null>(- (strongest, source) =>- strongest === null || roleRank(strongest.permissions) < roleRank(source.permissions)- ? source- : strongest,- null- )+ return strongestGfsInheritedSource(+ sources as PolicyInheritedAccessSource[]+ ) as GfsInheritedAccessSource | null}/**@@ -44,85 +63,94 @@ export function strongestInheritedSource(* - upgrade: the single strongest source (nearest among equals) — the* effective role is the strongest across sources, so one raise is enough;* - no-op (target equals the effective role): none.+ *+ * Kept flat and order-preserving (the app's established contract): the+ * richer grant-vs-share split planner remains available from the shared+ * package for the scoped per-source edit work.*/export function planInheritedRoleChange(item: Pick<GfsInheritedAccessItem, 'permissions' | 'sources'>,targetRoleIsEditor: boolean): GfsInheritedAccessSource[] {- const effectiveIsEditor = isEditorPermissions(item.permissions)+ const effectiveIsEditor = isEditorGfsPermissions(item.permissions)if (targetRoleIsEditor === effectiveIsEditor) return []if (!targetRoleIsEditor) {- // Downgrade: lower every editor source down to Read.- return item.sources.filter(source => isEditorPermissions(source.permissions))+ return item.sources.filter(source => isEditorGfsPermissions(source.permissions))}- // Upgrade: raise the strongest source (nearest among equals) to Editor.const strongest = strongestInheritedSource(item.sources)return strongest ? [strongest] : []}-/** One inheriting row on an ancestor folder, carrying its mutable row ids. */-export interface InheritedAccessContribution {- subject: { type: string; id?: string }- permissions: string[]- grantId: string | null- shareIds: string[]-}--/** The ancestor folder a contribution was collected from. */-export interface InheritedAccessFolder {- resourceId: string- name: string-}-/*** Folds one inheriting row into a subject's derived access item (creating it- * on first sight). Pure: never mutates its inputs. EVERY contributing folder- * is kept as an editable source (R1-H1); a grant and a share for one subject- * on the same folder consolidate into one source (unioned permissions and- * row ids) so a confirmed edit mutates them together.+ * on first sight) through the shared pure core, then projects the result back+ * to the app's legacy-exact source shape. The policy core carries richer+ * per-row provenance (grant bits/scope flag, share entries) for the upcoming+ * scoped per-source edit work; this adapter exposes exactly the fields the+ * app consumes today, so importers and tests observe byte-identical items.*/export function mergeInheritedAccessItem(current: GfsInheritedAccessItem | null,contribution: InheritedAccessContribution,folder: InheritedAccessFolder): GfsInheritedAccessItem {- if (current === null) {- return {- subject: contribution.subject,- permissions: [...contribution.permissions],- inheritedFrom: [folder.name],- sources: [- {- resourceId: folder.resourceId,- name: folder.name,- permissions: [...contribution.permissions],- grantId: contribution.grantId,- shareIds: [...contribution.shareIds],- },- ],- }+ let folded = current as unknown as PolicyInheritedAccessItem | null+ if (contribution.grantId !== null && contribution.grantId !== '') {+ folded = mergeInheritedAccessPolicy(+ folded,+ {+ subject: contribution.subject,+ permissions: contribution.permissions,+ rowKind: 'grant',+ rowId: contribution.grantId,+ inherit: true,+ },+ folder+ )}- const next: GfsInheritedAccessItem = {- ...current,- permissions: [...new Set([...current.permissions, ...contribution.permissions])],- inheritedFrom: current.inheritedFrom.includes(folder.name)- ? [...current.inheritedFrom]- : [...current.inheritedFrom, folder.name],- sources: current.sources.map(source => ({ ...source, shareIds: [...source.shareIds] })),+ for (const shareId of contribution.shareIds) {+ folded = mergeInheritedAccessPolicy(+ folded,+ {+ subject: contribution.subject,+ permissions: contribution.permissions,+ rowKind: 'share',+ rowId: shareId,+ includeDescendants: true,+ },+ folder+ )}- const sameFolder = next.sources.find(source => source.resourceId === folder.resourceId)- if (sameFolder) {- sameFolder.permissions = [...new Set([...sameFolder.permissions, ...contribution.permissions])]- sameFolder.grantId = sameFolder.grantId ?? contribution.grantId- sameFolder.shareIds = [...new Set([...sameFolder.shareIds, ...contribution.shareIds])]- } else {- next.sources.push({- resourceId: folder.resourceId,- name: folder.name,- permissions: [...contribution.permissions],- grantId: contribution.grantId,- shareIds: [...contribution.shareIds],- })+ if (+ (contribution.grantId === null || contribution.grantId === '') &&+ contribution.shareIds.length === 0+ ) {+ folded = mergeInheritedAccessPolicy(+ folded,+ {+ subject: contribution.subject,+ permissions: contribution.permissions,+ rowKind: 'grant',+ rowId: null,+ },+ folder+ )}- return next+ return toAppInheritedAccessItem(folded)+}++/** Project a policy item onto the app's legacy-exact item/source shape. */+function toAppInheritedAccessItem(item: PolicyInheritedAccessItem | null): GfsInheritedAccessItem {+ return {+ subject: item?.subject ?? { type: 'user' },+ permissions: [...(item?.permissions ?? [])],+ inheritedFrom: [...(item?.inheritedFrom ?? [])],+ sources: (item?.sources ?? []).map(source => ({+ resourceId: source.resourceId,+ name: source.name,+ permissions: [...source.permissions],+ grantId: source.grantId,+ shareIds: [...source.shareIds],+ })),+ } as GfsInheritedAccessItem}