mirror of
https://github.com/coder/coder.git
synced 2025-07-08 11:39:50 +00:00
feat: add groups support to the CLI (#4755)
This commit is contained in:
@ -7,6 +7,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/coder/coder/coderd/database"
|
||||
"github.com/coder/coder/coderd/httpapi"
|
||||
@ -24,6 +25,42 @@ func GroupParam(r *http.Request) database.Group {
|
||||
return group
|
||||
}
|
||||
|
||||
func ExtractGroupByNameParam(db database.Store) func(http.Handler) http.Handler {
|
||||
return func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
ctx = r.Context()
|
||||
org = OrganizationParam(r)
|
||||
)
|
||||
|
||||
name := chi.URLParam(r, "groupName")
|
||||
if name == "" {
|
||||
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
|
||||
Message: "Missing group name in URL",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
group, err := db.GetGroupByOrgAndName(ctx, database.GetGroupByOrgAndNameParams{
|
||||
OrganizationID: org.ID,
|
||||
Name: name,
|
||||
})
|
||||
if xerrors.Is(err, sql.ErrNoRows) {
|
||||
httpapi.ResourceNotFound(rw)
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
httpapi.InternalServerError(rw, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx = context.WithValue(ctx, groupParamContextKey{}, group)
|
||||
chi.RouteContext(ctx).URLParams.Add("organization", group.OrganizationID.String())
|
||||
next.ServeHTTP(rw, r.WithContext(ctx))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// ExtraGroupParam grabs a group from the "group" URL parameter.
|
||||
func ExtractGroupParam(db database.Store) func(http.Handler) http.Handler {
|
||||
return func(next http.Handler) http.Handler {
|
||||
|
Reference in New Issue
Block a user