EXPERIMENTAL: this endpoint is experimental and is subject to change. nolint:revive // get-return: revive assumes get* must be a getter, but this is an HTTP handler.
(rw http.ResponseWriter, r *http.Request)
| 5643 | // |
| 5644 | //nolint:revive // get-return: revive assumes get* must be a getter, but this is an HTTP handler. |
| 5645 | func (api *API) getChatTemplateAllowlist(rw http.ResponseWriter, r *http.Request) { |
| 5646 | ctx := r.Context() |
| 5647 | if !api.Authorize(r, policy.ActionRead, rbac.ResourceDeploymentConfig) { |
| 5648 | httpapi.ResourceNotFound(rw) |
| 5649 | return |
| 5650 | } |
| 5651 | raw, err := api.Database.GetChatTemplateAllowlist(ctx) |
| 5652 | if err != nil { |
| 5653 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 5654 | Message: "Internal error fetching chat template allowlist.", |
| 5655 | Detail: err.Error(), |
| 5656 | }) |
| 5657 | return |
| 5658 | } |
| 5659 | parsed, parseErr := xjson.ParseUUIDList(raw) |
| 5660 | if parseErr != nil { |
| 5661 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 5662 | Message: "Stored template allowlist is corrupt.", |
| 5663 | Detail: parseErr.Error(), |
| 5664 | }) |
| 5665 | return |
| 5666 | } |
| 5667 | ids := make([]string, len(parsed)) |
| 5668 | for i, id := range parsed { |
| 5669 | ids[i] = id.String() |
| 5670 | } |
| 5671 | resp := codersdk.ChatTemplateAllowlist{ |
| 5672 | TemplateIDs: ids, |
| 5673 | } |
| 5674 | httpapi.Write(ctx, rw, http.StatusOK, resp) |
| 5675 | } |
| 5676 | |
| 5677 | // EXPERIMENTAL: this endpoint is experimental and is subject to change. |
| 5678 | func (api *API) putChatTemplateAllowlist(rw http.ResponseWriter, r *http.Request) { |
no test coverage detected