Skip to content

Commit 69c063f

Browse files
committed
fix enterprise route override
1 parent c0b730e commit 69c063f

File tree

5 files changed

+26
-10
lines changed

5 files changed

+26
-10
lines changed

coderd/coderd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ func New(options *Options) *API {
917917
r.Post("/logout", api.postLogout)
918918
// These routes query information about site wide roles.
919919
r.Route("/roles", func(r chi.Router) {
920-
r.Get("/", api.assignableSiteRoles)
920+
r.Get("/", api.AssignableSiteRoles)
921921
})
922922
r.Route("/{user}", func(r chi.Router) {
923923
r.Use(httpmw.ExtractUserParam(options.Database))

coderd/roles.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/coder/coder/v2/coderd/rbac"
1212
)
1313

14-
// assignableSiteRoles returns all site wide roles that can be assigned.
14+
// AssignableSiteRoles returns all site wide roles that can be assigned.
1515
//
1616
// @Summary Get site member roles
1717
// @ID get-site-member-roles
@@ -20,7 +20,7 @@ import (
2020
// @Tags Members
2121
// @Success 200 {array} codersdk.AssignableRoles
2222
// @Router /users/roles [get]
23-
func (api *API) assignableSiteRoles(rw http.ResponseWriter, r *http.Request) {
23+
func (api *API) AssignableSiteRoles(rw http.ResponseWriter, r *http.Request) {
2424
ctx := r.Context()
2525
actorRoles := httpmw.UserAuthorization(r)
2626
if !api.Authorize(r, policy.ActionRead, rbac.ResourceAssignRole) {
@@ -32,7 +32,7 @@ func (api *API) assignableSiteRoles(rw http.ResponseWriter, r *http.Request) {
3232
httpapi.Write(ctx, rw, http.StatusOK, assignableRoles(actorRoles.Roles, roles))
3333
}
3434

35-
// assignableSiteRoles returns all org wide roles that can be assigned.
35+
// assignableOrgRoles returns all org wide roles that can be assigned.
3636
//
3737
// @Summary Get member roles by organization
3838
// @ID get-member-roles-by-organization

codersdk/roles.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ type Role struct {
4141
UserPermissions []Permission `json:"user_permissions"`
4242
}
4343

44-
// UpsertCustomSiteRole will upsert a custom site wide role
45-
func (c *Client) UpsertCustomSiteRole(ctx context.Context, req Role) (Role, error) {
44+
// PatchRole will upsert a custom site wide role
45+
func (c *Client) PatchRole(ctx context.Context, req Role) (Role, error) {
4646
res, err := c.Request(ctx, http.MethodPatch, "/api/v2/users/roles", req)
4747
if err != nil {
4848
return Role{}, err

enterprise/coderd/coderd.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,18 @@ func New(ctx context.Context, options *Options) (_ *API, err error) {
329329

330330
r.Route("/users/roles", func(r chi.Router) {
331331
r.Use(
332-
api.customRolesEnabledMW,
333332
apiKeyMiddleware,
334333
)
335-
336-
r.Patch("/", api.patchRole)
334+
r.Group(func(r chi.Router) {
335+
r.Use(
336+
api.customRolesEnabledMW,
337+
)
338+
r.Patch("/", api.patchRole)
339+
})
340+
// Unfortunate, but this r.Route overrides the AGPL roles route.
341+
// The AGPL does not have the entitlements to block the licensed
342+
// routes, so we need to duplicate the AGPL here.
343+
r.Get("/", api.AGPL.AssignableSiteRoles)
337344
})
338345

339346
r.Route("/users/{user}/quiet-hours", func(r chi.Router) {

enterprise/coderd/roles_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestCustomRole(t *testing.T) {
3636
ctx := testutil.Context(t, testutil.WaitMedium)
3737

3838
//nolint:gocritic // owner is required for this
39-
role, err := owner.UpsertCustomSiteRole(ctx, codersdk.Role{
39+
role, err := owner.PatchRole(ctx, codersdk.Role{
4040
Name: "test-role",
4141
DisplayName: "Testing Purposes",
4242
// Basically creating a template admin manually
@@ -59,5 +59,14 @@ func TestCustomRole(t *testing.T) {
5959

6060
// Try to create a template version
6161
coderdtest.CreateTemplateVersion(t, tmplAdmin, first.OrganizationID, nil)
62+
63+
// Verify the role exists in the list
64+
// TODO: Turn this assertion back on when the cli api experience is created.
65+
//allRoles, err := tmplAdmin.ListSiteRoles(ctx)
66+
//require.NoError(t, err)
67+
//
68+
//require.True(t, slices.ContainsFunc(allRoles, func(selected codersdk.AssignableRoles) bool {
69+
// return selected.Name == role.Name
70+
//}), "role missing from site role list")
6271
})
6372
}

0 commit comments

Comments
 (0)