-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api,ui): organization for user (#5996)
- Loading branch information
Showing
102 changed files
with
2,500 additions
and
816 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/ovh/cds/cli" | ||
) | ||
|
||
var adminUsersCmd = cli.Command{ | ||
Name: "users", | ||
Aliases: []string{"user"}, | ||
Short: "Manage CDS users", | ||
} | ||
|
||
func adminUsers() *cobra.Command { | ||
return cli.NewCommand(adminUsersCmd, nil, []*cobra.Command{ | ||
cli.NewCommand(adminUserSetOrganizationCmd, adminUserSetOrganizationRun, nil), | ||
}) | ||
} | ||
|
||
var adminUserSetOrganizationCmd = cli.Command{ | ||
Name: "set-organization", | ||
Short: "Set organization for given user", | ||
Args: []cli.Arg{ | ||
{ | ||
Name: "username", | ||
}, | ||
{ | ||
Name: "organization", | ||
}, | ||
}, | ||
} | ||
|
||
func adminUserSetOrganizationRun(v cli.Values) error { | ||
ctx := context.Background() | ||
username := v.GetString("username") | ||
organization := v.GetString("organization") | ||
|
||
u, err := client.UserGet(ctx, username) | ||
if err != nil { | ||
return err | ||
} | ||
if u.Organization != "" { | ||
return cli.NewError("user organization already set to %q", u.Organization) | ||
} | ||
|
||
u.Organization = organization | ||
|
||
if err := client.UserUpdate(ctx, u.Username, u); err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("User organization set to %q\n", u.Organization) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.