(db database.Store)
| 23 | } |
| 24 | |
| 25 | func ExtractGroupByNameParam(db database.Store) func(http.Handler) http.Handler { |
| 26 | return func(next http.Handler) http.Handler { |
| 27 | return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { |
| 28 | var ( |
| 29 | ctx = r.Context() |
| 30 | org = OrganizationParam(r) |
| 31 | ) |
| 32 | |
| 33 | name := chi.URLParam(r, "groupName") |
| 34 | if name == "" { |
| 35 | httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ |
| 36 | Message: "Missing group name in URL", |
| 37 | }) |
| 38 | return |
| 39 | } |
| 40 | |
| 41 | group, err := db.GetGroupByOrgAndName(ctx, database.GetGroupByOrgAndNameParams{ |
| 42 | OrganizationID: org.ID, |
| 43 | Name: name, |
| 44 | }) |
| 45 | if httpapi.Is404Error(err) { |
| 46 | httpapi.ResourceNotFound(rw) |
| 47 | return |
| 48 | } |
| 49 | if err != nil { |
| 50 | httpapi.InternalServerError(rw, err) |
| 51 | return |
| 52 | } |
| 53 | |
| 54 | ctx = context.WithValue(ctx, groupParamContextKey{}, group) |
| 55 | chi.RouteContext(ctx).URLParams.Add("organization", group.OrganizationID.String()) |
| 56 | next.ServeHTTP(rw, r.WithContext(ctx)) |
| 57 | }) |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | // ExtraGroupParam grabs a group from the "group" URL parameter. |
| 62 | func ExtractGroupParam(db database.Store) func(http.Handler) http.Handler { |
no test coverage detected