Edits history of script submission #23551 for ' Add User to Workspace (windmill)'

  • bunnative
    One script reply has been approved by the moderators
    Ap­pro­ved
    //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
    })
    
    /**
     * Add User to Workspace
     * Add an existing instance user to the workspace by email, as a developer, operator or admin. Leave username empty when the instance automates username creation (it rejects one). Requires a workspace admin.
     */
    export async function main(
      email: string,
      role: "developer" | "operator" | "admin" = "developer",
      username: string | undefined
    ) {
      return await wmill.WorkspaceService.addUser({
        workspace: wmill.getWorkspace(),
        requestBody: {
          email,
          is_admin: role === "admin",
          operator: role === "operator",
          username: username || undefined,
        },
      })
    }
    

    Submitted by hugo989 5 hours ago