Merge remote-tracking branch 'origin/access-view-grant' into run-as-service-accounts

This commit is contained in:
Guilhem Lemouel
2026-11-02 02:15:33 -08:00
5 changed files with 47 additions and 14 deletions
@@ -7,7 +7,7 @@
import Cell from './table/Cell.svelte'
import RowIcon from './common/table/RowIcon.svelte'
import { GranularAclService, type AccessReason, type PrincipalAccess } from '$lib/gen'
import { workspaceStore } from '$lib/stores'
import { useOperatingWorkspace } from './operatingWorkspace.svelte'
import { sendUserToast } from '$lib/toast'
import type { Item } from '$lib/utils'
import { logFeatureUsage } from '$lib/utils/featureUsage'
@@ -20,6 +20,8 @@
import { KIND_LABELS, setGrant, type GrantLevel } from './access/access'
import type { RunnableKind } from './access/detectNeeds'
const operatingWorkspace = useOperatingWorkspace()
type Target = 'self' | 'user' | 'service_account' | 'group'
const PAGE = 100
@@ -56,7 +58,7 @@
const id = ++requestId
try {
const result = await GranularAclService.getPrincipalAccess({
workspace: $workspaceStore!,
workspace: $operatingWorkspace!,
principal
})
if (id === requestId) access = result
@@ -106,7 +108,7 @@
async function changeGrant(kind: string, path: string, level: GrantLevel) {
try {
await setGrant($workspaceStore!, kind, path, principal, level)
await setGrant($operatingWorkspace!, kind, path, principal, level)
} catch (e) {
const what = kind === 'folder' ? `f/${path}` : path
sendUserToast(`Could not change access to ${what}: ${e?.body ?? e}`, true)
@@ -1,11 +1,13 @@
<script lang="ts">
import { Alert, Button, Skeleton } from '$lib/components/common'
import Checkbox from '$lib/components/common/checkbox/Checkbox.svelte'
import { workspaceStore } from '$lib/stores'
import { useOperatingWorkspace } from '$lib/components/operatingWorkspace.svelte'
import { Info, X } from 'lucide-svelte'
import { setGrant } from './access'
import { detectNeeds, type Needs, type RunnableKind } from './detectNeeds'
const operatingWorkspace = useOperatingWorkspace()
let {
principal,
kind,
@@ -30,7 +32,7 @@
let granting = $state(false)
// The host keys this component on the runnable, so it detects once per runnable.
detectNeeds($workspaceStore!, kind, path)
detectNeeds($operatingWorkspace!, kind, path)
.then((found) => {
needs = found
selected = Object.fromEntries(
@@ -46,7 +48,7 @@
const key = `${item.kind}:${item.path}`
if (!selected[key]) continue
try {
await setGrant($workspaceStore!, item.kind, item.path, principal, 'read')
await setGrant($operatingWorkspace!, item.kind, item.path, principal, 'read')
results[key] = 'Granted'
selected[key] = false
} catch (e) {
@@ -20,13 +20,16 @@ Picking a row grants the principal read on it; the "All of f/x" row grants the w
type BrowseAccessItemsResponse,
type PrincipalAccess
} from '$lib/gen'
import { userStore, workspaceStore } from '$lib/stores'
import { userStore } from '$lib/stores'
import { useOperatingWorkspace } from '$lib/components/operatingWorkspace.svelte'
import { sendUserToast } from '$lib/toast'
import { debounce } from '$lib/utils'
import { Folder, ScanSearch, User, Users } from 'lucide-svelte'
import { setGrant } from './access'
import type { RunnableKind } from './detectNeeds'
const operatingWorkspace = useOperatingWorkspace()
type Row = BrowseAccessItemsResponse['items'][number]
/** `kind` `folder` is the "All of f/x" row, its `path` the folder name. */
type Leaf = Row & { owner?: boolean }
@@ -66,7 +69,7 @@ Picking a row grants the principal read on it; the "All of f/x" row grants the w
async function loadFolders() {
try {
folders = await GranularAclService.browseAccessFolders({
workspace: $workspaceStore!,
workspace: $operatingWorkspace!,
principal
})
} catch (e) {
@@ -82,7 +85,7 @@ Picking a row grants the principal read on it; the "All of f/x" row grants the w
let offset = 0
while (true) {
const page = await GranularAclService.browseAccessItems({
workspace: $workspaceStore!,
workspace: $operatingWorkspace!,
principal,
prefix: `${branch}/`,
offset
@@ -105,7 +108,7 @@ Picking a row grants the principal read on it; the "All of f/x" row grants the w
const searchSoon = debounce(async (search: string) => {
try {
const page = await GranularAclService.browseAccessItems({
workspace: $workspaceStore!,
workspace: $operatingWorkspace!,
principal,
search
})
@@ -192,7 +195,7 @@ Picking a row grants the principal read on it; the "All of f/x" row grants the w
})
const reaches = $derived(
new Map([
new Map<string, boolean>([
...access.items.map((i) => [`${i.kind}:${i.path}`, i.write] as const),
...access.folders.map((f) => [`folder:${f.name}`, f.write] as const)
])
@@ -202,7 +205,7 @@ Picking a row grants the principal read on it; the "All of f/x" row grants the w
const row = leaf.data
if (row.grant != undefined) return
try {
await setGrant($workspaceStore!, row.kind, row.path, principal, 'read')
await setGrant($operatingWorkspace!, row.kind, row.path, principal, 'read')
row.grant = false
if (row.kind === 'folder') {
const folder = folders?.find((f) => f.name === row.path)
@@ -4,7 +4,17 @@ const readVariable = (path: string) =>
`import * as wmill from "windmill-client"\nexport async function main() { return await wmill.getVariable("${path}") }\n`
vi.mock('$lib/gen', () => ({
AppService: { getAppByPath: vi.fn() },
AppService: {
getAppByPath: vi.fn(async () => ({
value: {
files: {
'/App.tsx': `const key = await wmill.getVariable("f/x/browser_secret")`,
'/notes.md': `getVariable("f/x/not_code")`
},
runnables: {}
}
}))
},
AssetService: { listAssetsByUsage: vi.fn(async () => [[]]) },
FlowService: {
getFlowByPath: vi.fn(async () => ({
@@ -65,4 +75,9 @@ describe('detectNeeds', () => {
])
expect(needs.errors).toEqual([])
})
it("reads a full-code app's frontend source files", async () => {
const needs = await detectNeeds('w', 'app', 'f/x/app')
expect(needs.items.map((i) => `${i.kind}:${i.path}`)).toEqual(['variable:f/x/browser_secret'])
})
})
@@ -29,6 +29,7 @@ const ITEM_PATH = /^[ufg]\/[^/]+\/.+/
const STATIC_REF = /^\$(res|var|jsonvar):(.+)$/
// The asset parser finds resources but has no variable kind, so literal variable reads are matched
// here. A path the code builds at run time is found by neither.
const SOURCE_FILE = /\.(?:[cm]?[jt]sx?|svelte|vue)$/
const VARIABLE_CALL = /\b(?:getVariable|get_variable)\(\s*["'`]([^"'`]+)["'`]/g
/**
@@ -155,7 +156,17 @@ export async function detectNeeds(
} else {
// Apps record no asset usages, so their inline code is parsed here.
const app = await AppService.getAppByPath({ workspace, path: runnablePath })
await walk(app.value, runnablePath, depth)
// A full-code app's frontend calls the SDK as its viewer, from source kept as plain
// strings under `files`, which the walk below cannot tell from other strings.
const files = (app.value as { files?: Record<string, unknown> } | undefined)?.files ?? {}
await Promise.all([
walk(app.value, runnablePath, depth),
...Object.entries(files)
.filter(([name, content]) => SOURCE_FILE.test(name) && typeof content === 'string')
.map(([name, content]) =>
scanCode('bun', content as string, `${runnablePath} › ${name}`)
)
])
}
} catch (e) {
// The item itself unreadable is a failure of the whole scan, not a partial result.