MCPcopy Index your code
hub / github.com/coder/coder / workspaceACLToTable

Function workspaceACLToTable

cli/sharing.go:286–329  ·  view source on GitHub ↗
(ctx context.Context, acl *codersdk.WorkspaceACL)

Source from the content-addressed store, hash-verified

284}
285
286func workspaceACLToTable(ctx context.Context, acl *codersdk.WorkspaceACL) (string, error) {
287 type workspaceShareRow struct {
288 User string `table:"user"`
289 Group string `table:"group,default_sort"`
290 Role codersdk.WorkspaceRole `table:"role"`
291 }
292
293 formatter := cliui.NewOutputFormatter(
294 cliui.TableFormat(
295 []workspaceShareRow{}, []string{"User", "Group", "Role"}),
296 cliui.JSONFormat())
297
298 outputRows := make([]workspaceShareRow, 0)
299 for _, user := range acl.Users {
300 if user.Role == codersdk.WorkspaceRoleDeleted {
301 continue
302 }
303
304 outputRows = append(outputRows, workspaceShareRow{
305 User: user.Username,
306 Group: defaultGroupDisplay,
307 Role: user.Role,
308 })
309 }
310 for _, group := range acl.Groups {
311 if group.Role == codersdk.WorkspaceRoleDeleted {
312 continue
313 }
314
315 for _, user := range group.Members {
316 outputRows = append(outputRows, workspaceShareRow{
317 User: user.Username,
318 Group: group.Name,
319 Role: group.Role,
320 })
321 }
322 }
323 out, err := formatter.Format(ctx, outputRows)
324 if err != nil {
325 return "", err
326 }
327
328 return out, nil
329}
330
331type fetchUsersAndGroupsParams struct {
332 Client *codersdk.Client

Callers 3

shareWorkspaceMethod · 0.85
unshareWorkspaceMethod · 0.85

Calls 4

FormatMethod · 0.95
NewOutputFormatterFunction · 0.92
TableFormatFunction · 0.92
JSONFormatFunction · 0.92

Tested by

no test coverage detected