//native
import * as wmill from "windmill-client"
// windmill-client errors only carry the status text: throw the response body, which says why
wmill.OpenAPI.interceptors.response.use(async (response) => {
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return response
})
export type DynSelect_name = string
export async function name() {
const names = await wmill.FolderService.listFolderNames({
workspace: wmill.getWorkspace(),
})
return names.map((n) => ({ value: n, label: n }))
}
/**
* Add User or Group to Folder
* Grant a user (`u/<username>`) or group (`g/<group>`) access to a folder as viewer, writer or admin. Requires a folder admin or a workspace admin.
*/
export async function main(
name: DynSelect_name,
member: string,
role: "viewer" | "writer" | "admin" = "viewer"
) {
const ws = wmill.getWorkspace()
if (role === "admin") {
return await wmill.FolderService.addOwnerToFolder({
workspace: ws,
name,
requestBody: { owner: member },
})
}
return await wmill.GranularAclService.addGranularAcls({
workspace: ws,
kind: "folder",
path: name,
requestBody: { owner: member, write: role === "writer" },
})
}
Submitted by hugo989 5 hours ago