Skip to content

Commit f2c7b60

Browse files
committed
move cli show roles to org scope
1 parent 95a8931 commit f2c7b60

File tree

5 files changed

+61
-77
lines changed

5 files changed

+61
-77
lines changed

cli/organization.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func (r *RootCmd) organizations() *serpent.Command {
3030
r.currentOrganization(),
3131
r.switchOrganization(),
3232
r.createOrganization(),
33+
r.organizationRoles(),
3334
},
3435
}
3536

enterprise/cli/rolescmd.go renamed to cli/organizationroles.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,23 @@ import (
1212
"github.com/coder/serpent"
1313
)
1414

15-
// **NOTE** Only covers site wide roles at present. Org scoped roles maybe
16-
// should be nested under some command that scopes to an org??
17-
18-
func (r *RootCmd) roles() *serpent.Command {
15+
func (r *RootCmd) organizationRoles() *serpent.Command {
1916
cmd := &serpent.Command{
2017
Use: "roles",
21-
Short: "Manage site-wide roles.",
18+
Short: "Manage organization roles.",
2219
Aliases: []string{"role"},
2320
Handler: func(inv *serpent.Invocation) error {
2421
return inv.Command.HelpHandler(inv)
2522
},
2623
Hidden: true,
2724
Children: []*serpent.Command{
28-
r.showRole(),
25+
r.showOrganizationRoles(),
2926
},
3027
}
3128
return cmd
3229
}
3330

34-
func (r *RootCmd) showRole() *serpent.Command {
31+
func (r *RootCmd) showOrganizationRoles() *serpent.Command {
3532
formatter := cliui.NewOutputFormatter(
3633
cliui.ChangeFormatterData(
3734
cliui.TableFormat([]assignableRolesTableRow{}, []string{"name", "display_name", "built_in", "site_permissions", "org_permissions", "user_permissions"}),
@@ -67,7 +64,12 @@ func (r *RootCmd) showRole() *serpent.Command {
6764
),
6865
Handler: func(inv *serpent.Invocation) error {
6966
ctx := inv.Context()
70-
roles, err := client.ListSiteRoles(ctx)
67+
org, err := CurrentOrganization(r, inv, client)
68+
if err != nil {
69+
return err
70+
}
71+
72+
roles, err := client.ListOrganizationRoles(ctx, org.ID)
7173
if err != nil {
7274
return xerrors.Errorf("listing roles: %w", err)
7375
}

cli/organizationroles_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package cli_test
2+
3+
import (
4+
"bytes"
5+
"testing"
6+
7+
"github.com/google/uuid"
8+
"github.com/stretchr/testify/require"
9+
10+
"github.com/coder/coder/v2/cli/clitest"
11+
"github.com/coder/coder/v2/coderd/coderdtest"
12+
"github.com/coder/coder/v2/coderd/database"
13+
"github.com/coder/coder/v2/coderd/database/dbgen"
14+
"github.com/coder/coder/v2/testutil"
15+
)
16+
17+
func TestShowOrganizationRoles(t *testing.T) {
18+
t.Parallel()
19+
20+
t.Run("OK", func(t *testing.T) {
21+
t.Parallel()
22+
23+
client, db := coderdtest.NewWithDatabase(t, &coderdtest.Options{})
24+
owner := coderdtest.CreateFirstUser(t, client)
25+
26+
const expectedRole = "test-role"
27+
dbgen.CustomRole(t, db, database.CustomRole{
28+
Name: expectedRole,
29+
DisplayName: "Expected",
30+
SitePermissions: nil,
31+
OrgPermissions: nil,
32+
UserPermissions: nil,
33+
OrganizationID: uuid.NullUUID{
34+
UUID: owner.OrganizationID,
35+
Valid: true,
36+
},
37+
})
38+
39+
// Requires an owner
40+
ctx := testutil.Context(t, testutil.WaitMedium)
41+
inv, root := clitest.New(t, "organization", "roles", "show")
42+
clitest.SetupConfig(t, client, root)
43+
44+
buf := new(bytes.Buffer)
45+
inv.Stdout = buf
46+
err := inv.WithContext(ctx).Run()
47+
require.NoError(t, err)
48+
require.Contains(t, buf.String(), expectedRole)
49+
})
50+
}

enterprise/cli/rolescmd_test.go

Lines changed: 0 additions & 68 deletions
This file was deleted.

enterprise/cli/root.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ func (r *RootCmd) enterpriseOnly() []*serpent.Command {
1717
r.licenses(),
1818
r.groups(),
1919
r.provisionerDaemons(),
20-
r.roles(),
2120
}
2221
}
2322

0 commit comments

Comments
 (0)