Edits history of script submission #23550 for ' Add User to Group (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
    })
    
    export type DynSelect_name = string
    
    export async function name() {
      const names = await wmill.GroupService.listGroupNames({
        workspace: wmill.getWorkspace(),
      })
      return names.map((n) => ({ value: n, label: n }))
    }
    
    export type DynSelect_username = string
    
    export async function username() {
      const names = await wmill.UserService.listUsernames({
        workspace: wmill.getWorkspace(),
      })
      return names.map((n) => ({ value: n, label: n }))
    }
    
    /**
     * Add User to Group
     * Add a workspace user to a group. Requires a workspace admin or a group admin.
     */
    export async function main(name: DynSelect_name, username: DynSelect_username) {
      return await wmill.GroupService.addUserToGroup({
        workspace: wmill.getWorkspace(),
        name,
        requestBody: { username },
      })
    }
    

    Submitted by hugo989 5 hours ago