Skip to content

Commit 173dc0e

Browse files
authored
chore: refactor patch custom organization route to live in enterprise (coder#14099)
* chore: refactor patch custom organization route to live in enterprise
1 parent a77a9ab commit 173dc0e

File tree

9 files changed

+215
-108
lines changed

9 files changed

+215
-108
lines changed

coderd/apidoc/docs.go

+42
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

+40
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/coderd.go

-7
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,6 @@ func New(options *Options) *API {
464464
TemplateScheduleStore: options.TemplateScheduleStore,
465465
UserQuietHoursScheduleStore: options.UserQuietHoursScheduleStore,
466466
AccessControlStore: options.AccessControlStore,
467-
CustomRoleHandler: atomic.Pointer[CustomRoleHandler]{},
468467
Experiments: experiments,
469468
healthCheckGroup: &singleflight.Group[string, *healthsdk.HealthcheckReport]{},
470469
Acquirer: provisionerdserver.NewAcquirer(
@@ -476,8 +475,6 @@ func New(options *Options) *API {
476475
dbRolluper: options.DatabaseRolluper,
477476
}
478477

479-
var customRoleHandler CustomRoleHandler = &agplCustomRoleHandler{}
480-
api.CustomRoleHandler.Store(&customRoleHandler)
481478
api.AppearanceFetcher.Store(&appearance.DefaultFetcher)
482479
api.PortSharer.Store(&portsharing.DefaultPortSharer)
483480
buildInfo := codersdk.BuildInfoResponse{
@@ -887,8 +884,6 @@ func New(options *Options) *API {
887884
r.Get("/", api.listMembers)
888885
r.Route("/roles", func(r chi.Router) {
889886
r.Get("/", api.assignableOrgRoles)
890-
r.With(httpmw.RequireExperiment(api.Experiments, codersdk.ExperimentCustomRoles)).
891-
Patch("/", api.patchOrgRoles)
892887
})
893888

894889
r.Route("/{user}", func(r chi.Router) {
@@ -1340,8 +1335,6 @@ type API struct {
13401335
// passed to dbauthz.
13411336
AccessControlStore *atomic.Pointer[dbauthz.AccessControlStore]
13421337
PortSharer atomic.Pointer[portsharing.PortSharer]
1343-
// CustomRoleHandler is the AGPL/Enterprise implementation for custom roles.
1344-
CustomRoleHandler atomic.Pointer[CustomRoleHandler]
13451338

13461339
HTTPAuth *HTTPAuthorizer
13471340

coderd/roles.go

-47
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package coderd
22

33
import (
4-
"context"
54
"net/http"
65

76
"github.com/google/uuid"
@@ -16,52 +15,6 @@ import (
1615
"github.com/coder/coder/v2/coderd/rbac"
1716
)
1817

19-
// CustomRoleHandler handles AGPL/Enterprise interface for handling custom
20-
// roles. Ideally only included in the enterprise package, but the routes are
21-
// intermixed with AGPL endpoints.
22-
type CustomRoleHandler interface {
23-
PatchOrganizationRole(ctx context.Context, rw http.ResponseWriter, r *http.Request, orgID uuid.UUID, role codersdk.PatchRoleRequest) (codersdk.Role, bool)
24-
}
25-
26-
type agplCustomRoleHandler struct{}
27-
28-
func (agplCustomRoleHandler) PatchOrganizationRole(ctx context.Context, rw http.ResponseWriter, _ *http.Request, _ uuid.UUID, _ codersdk.PatchRoleRequest) (codersdk.Role, bool) {
29-
httpapi.Write(ctx, rw, http.StatusForbidden, codersdk.Response{
30-
Message: "Creating and updating custom roles is an Enterprise feature. Contact sales!",
31-
})
32-
return codersdk.Role{}, false
33-
}
34-
35-
// patchRole will allow creating a custom organization role
36-
//
37-
// @Summary Upsert a custom organization role
38-
// @ID upsert-a-custom-organization-role
39-
// @Security CoderSessionToken
40-
// @Produce json
41-
// @Param organization path string true "Organization ID" format(uuid)
42-
// @Tags Members
43-
// @Success 200 {array} codersdk.Role
44-
// @Router /organizations/{organization}/members/roles [patch]
45-
func (api *API) patchOrgRoles(rw http.ResponseWriter, r *http.Request) {
46-
var (
47-
ctx = r.Context()
48-
handler = *api.CustomRoleHandler.Load()
49-
organization = httpmw.OrganizationParam(r)
50-
)
51-
52-
var req codersdk.PatchRoleRequest
53-
if !httpapi.Read(ctx, rw, r, &req) {
54-
return
55-
}
56-
57-
updated, ok := handler.PatchOrganizationRole(ctx, rw, r, organization.ID, req)
58-
if !ok {
59-
return
60-
}
61-
62-
httpapi.Write(ctx, rw, http.StatusOK, updated)
63-
}
64-
6518
// AssignableSiteRoles returns all site wide roles that can be assigned.
6619
//
6720
// @Summary Get site member roles

docs/api/members.md

+35-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api/schemas.md

+40
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

enterprise/coderd/coderd.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,16 @@ func New(ctx context.Context, options *Options) (_ *API, err error) {
261261
r.Delete("/organizations/{organization}", api.deleteOrganization)
262262
})
263263

264+
r.Group(func(r chi.Router) {
265+
r.Use(
266+
apiKeyMiddleware,
267+
api.RequireFeatureMW(codersdk.FeatureCustomRoles),
268+
httpmw.RequireExperiment(api.AGPL.Experiments, codersdk.ExperimentCustomRoles),
269+
httpmw.ExtractOrganizationParam(api.Database),
270+
)
271+
r.Patch("/organizations/{organization}/members/roles", api.patchOrgRoles)
272+
})
273+
264274
r.Route("/organizations/{organization}/groups", func(r chi.Router) {
265275
r.Use(
266276
apiKeyMiddleware,
@@ -795,16 +805,6 @@ func (api *API) updateEntitlements(ctx context.Context) error {
795805
api.AGPL.PortSharer.Store(&ps)
796806
}
797807

798-
if initial, changed, enabled := featureChanged(codersdk.FeatureCustomRoles); shouldUpdate(initial, changed, enabled) {
799-
var handler coderd.CustomRoleHandler = &enterpriseCustomRoleHandler{API: api, Enabled: enabled}
800-
api.AGPL.CustomRoleHandler.Store(&handler)
801-
}
802-
803-
if initial, changed, enabled := featureChanged(codersdk.FeatureMultipleOrganizations); shouldUpdate(initial, changed, enabled) {
804-
var handler coderd.CustomRoleHandler = &enterpriseCustomRoleHandler{API: api, Enabled: enabled}
805-
api.AGPL.CustomRoleHandler.Store(&handler)
806-
}
807-
808808
// External token encryption is soft-enforced
809809
featureExternalTokenEncryption := entitlements.Features[codersdk.FeatureExternalTokenEncryption]
810810
featureExternalTokenEncryption.Enabled = len(api.ExternalTokenEncryption) > 0

0 commit comments

Comments
 (0)