Skip to content

Commit

Permalink
feat(cdsctl): add group user list command (#3773) (#3776)
Browse files Browse the repository at this point in the history
* feat(cdsctl): add group user list command (#3773)

Signed-off-by: Benjamin Coenen <[email protected]>

* feat(cdsctl): add group user list command (#3773)

Signed-off-by: Benjamin Coenen <[email protected]>
  • Loading branch information
bnjjj authored and richardlt committed Dec 26, 2018
1 parent 689b82c commit d089ab9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
28 changes: 27 additions & 1 deletion cli/cdsctl/group_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/spf13/cobra"

"github.com/ovh/cds/cli"
"github.com/ovh/cds/sdk"
)

var groupUserCmd = cli.Command{
Expand All @@ -13,16 +14,41 @@ var groupUserCmd = cli.Command{

func groupUser() *cobra.Command {
return cli.NewCommand(groupUserCmd, nil, []*cobra.Command{
cli.NewListCommand(groupUserListCmd, groupUserListRun, nil, withAllCommandModifiers()...),
cli.NewCommand(groupUserAdd, groupUserAddRun, nil),
cli.NewDeleteCommand(groupUserRemove, groupUserRemoveRun, nil),
cli.NewCommand(groupUserSetAdmin, groupUserSetAdminRun, nil),
cli.NewCommand(groupUserAdminRemove, groupUserAdminRemoveRun, nil),
})
}

var groupUserListCmd = cli.Command{
Name: "list",
Short: "List users into a group",
Args: []cli.Arg{
{Name: "groupname"},
},
}

func groupUserListRun(v cli.Values) (cli.ListResult, error) {
gr, err := client.GroupGet(v.GetString("groupname"))
if err != nil {
return nil, err
}
users := make([]sdk.User, 0, len(gr.Admins)+len(gr.Users))

for _, admin := range gr.Admins {
admin.GroupAdmin = true
users = append(users, admin)
}
users = append(users, gr.Users...)

return cli.AsListResult(users), nil
}

var groupUserAdd = cli.Command{
Name: "add",
Short: "Add a user into a group",
Short: "Add an user into a group",
Args: []cli.Arg{
{Name: "groupname"},
{Name: "username"},
Expand Down
1 change: 1 addition & 0 deletions sdk/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type User struct {
Origin string `json:"origin" yaml:"origin,omitempty"`
Favorites []Favorite `json:"favorites" yaml:"favorites"`
Permissions UserPermissions `json:"permissions,omitempty" yaml:"-" cli:"-"`
GroupAdmin bool `json:"-" yaml:"-" cli:"group_admin"`
}

// Favorite represent the favorites workflow or project of the user
Expand Down

0 comments on commit d089ab9

Please sign in to comment.