chore: refactor patch custom organization route to live in enterprise (#14099)

* chore: refactor patch custom organization route to live in enterprise
This commit is contained in:
Steven Masley
2024-08-05 13:42:11 -05:00
committed by GitHub
parent a77a9ab0a6
commit 173dc0e35f
9 changed files with 220 additions and 113 deletions
-47
View File
@@ -1,7 +1,6 @@
package coderd
import (
"context"
"net/http"
"github.com/google/uuid"
@@ -16,52 +15,6 @@ import (
"github.com/coder/coder/v2/coderd/rbac"
)
// CustomRoleHandler handles AGPL/Enterprise interface for handling custom
// roles. Ideally only included in the enterprise package, but the routes are
// intermixed with AGPL endpoints.
type CustomRoleHandler interface {
PatchOrganizationRole(ctx context.Context, rw http.ResponseWriter, r *http.Request, orgID uuid.UUID, role codersdk.PatchRoleRequest) (codersdk.Role, bool)
}
type agplCustomRoleHandler struct{}
func (agplCustomRoleHandler) PatchOrganizationRole(ctx context.Context, rw http.ResponseWriter, _ *http.Request, _ uuid.UUID, _ codersdk.PatchRoleRequest) (codersdk.Role, bool) {
httpapi.Write(ctx, rw, http.StatusForbidden, codersdk.Response{
Message: "Creating and updating custom roles is an Enterprise feature. Contact sales!",
})
return codersdk.Role{}, false
}
// patchRole will allow creating a custom organization role
//
// @Summary Upsert a custom organization role
// @ID upsert-a-custom-organization-role
// @Security CoderSessionToken
// @Produce json
// @Param organization path string true "Organization ID" format(uuid)
// @Tags Members
// @Success 200 {array} codersdk.Role
// @Router /organizations/{organization}/members/roles [patch]
func (api *API) patchOrgRoles(rw http.ResponseWriter, r *http.Request) {
var (
ctx = r.Context()
handler = *api.CustomRoleHandler.Load()
organization = httpmw.OrganizationParam(r)
)
var req codersdk.PatchRoleRequest
if !httpapi.Read(ctx, rw, r, &req) {
return
}
updated, ok := handler.PatchOrganizationRole(ctx, rw, r, organization.ID, req)
if !ok {
return
}
httpapi.Write(ctx, rw, http.StatusOK, updated)
}
// AssignableSiteRoles returns all site wide roles that can be assigned.
//
// @Summary Get site member roles