mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-24 00:00:46 +00:00
33 lines
872 B
TypeScript
33 lines
872 B
TypeScript
import { get } from 'svelte/store'
|
|
import { UserService, type User } from '$lib/gen'
|
|
import { superadmin, type UserExt } from './stores.js'
|
|
|
|
export async function refreshSuperadmin(): Promise<void> {
|
|
if (get(superadmin) == undefined) {
|
|
UserService.globalWhoami().then((x) => {
|
|
if (x.super_admin) {
|
|
superadmin.set(x.email)
|
|
} else {
|
|
superadmin.set(false)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
export async function getUserExt(workspace: string): Promise<UserExt | undefined> {
|
|
try {
|
|
const user = await UserService.whoami({ workspace })
|
|
return mapUserToUserExt(user)
|
|
} catch (error) {
|
|
return undefined
|
|
}
|
|
}
|
|
|
|
function mapUserToUserExt(user: User): UserExt {
|
|
return {
|
|
...user,
|
|
groups: user.groups!,
|
|
pgroups: user.groups!.map((x) => `g/${x}`)
|
|
}
|
|
}
|