| 293 | } |
| 294 | |
| 295 | func userRolesToAddPickerOptions(ctx context.Context, cli *cli, userID string) ([]string, error) { |
| 296 | currentUserRoleList, err := cli.api.User.Roles(ctx, userID, management.PerPage(100)) |
| 297 | if err != nil { |
| 298 | return nil, fmt.Errorf("failed to read the current roles for user with ID %q: %w", userID, err) |
| 299 | } |
| 300 | |
| 301 | var roleList *management.RoleList |
| 302 | roleList, err = cli.api.Role.List(ctx) |
| 303 | if err != nil { |
| 304 | return nil, fmt.Errorf("failed to list all roles: %w", err) |
| 305 | } |
| 306 | |
| 307 | if len(roleList.Roles) == len(currentUserRoleList.Roles) { |
| 308 | return nil, fmt.Errorf("the user with ID %q has all roles assigned already", userID) |
| 309 | } |
| 310 | |
| 311 | var options []string |
| 312 | for _, role := range roleList.Roles { |
| 313 | if !containsRole(currentUserRoleList.Roles, role.GetID()) { |
| 314 | options = append(options, fmt.Sprintf("%s (Name: %s)", role.GetID(), role.GetName())) |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | return options, nil |
| 319 | } |
| 320 | |
| 321 | func userRolesToRemovePickerOptions(ctx context.Context, cli *cli, userID string) ([]string, error) { |
| 322 | currentUserRoleList, err := cli.api.User.Roles(ctx, userID, management.PerPage(100)) |