(rw http.ResponseWriter, r *http.Request)
| 7211 | } |
| 7212 | |
| 7213 | func (api *API) deleteChatModelConfig(rw http.ResponseWriter, r *http.Request) { |
| 7214 | ctx := r.Context() |
| 7215 | if !api.Authorize(r, policy.ActionUpdate, rbac.ResourceDeploymentConfig) { |
| 7216 | httpapi.Forbidden(rw) |
| 7217 | return |
| 7218 | } |
| 7219 | |
| 7220 | modelConfigID, ok := parseChatModelConfigID(rw, r) |
| 7221 | if !ok { |
| 7222 | return |
| 7223 | } |
| 7224 | |
| 7225 | if _, err := api.Database.GetChatModelConfigByID(ctx, modelConfigID); err != nil { |
| 7226 | if httpapi.Is404Error(err) { |
| 7227 | httpapi.ResourceNotFound(rw) |
| 7228 | return |
| 7229 | } |
| 7230 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 7231 | Message: "Failed to get chat model config.", |
| 7232 | Detail: err.Error(), |
| 7233 | }) |
| 7234 | return |
| 7235 | } |
| 7236 | |
| 7237 | if err := api.Database.InTx(func(tx database.Store) error { |
| 7238 | if err := tx.DeleteChatModelConfigByID(ctx, modelConfigID); err != nil { |
| 7239 | return err |
| 7240 | } |
| 7241 | return ensureDefaultChatModelConfig(ctx, tx) |
| 7242 | }, nil); err != nil { |
| 7243 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 7244 | Message: "Failed to delete chat model config.", |
| 7245 | Detail: err.Error(), |
| 7246 | }) |
| 7247 | return |
| 7248 | } |
| 7249 | |
| 7250 | publishChatConfigEvent(api.Logger, api.Pubsub, pubsub.ChatConfigEventModelConfig, modelConfigID) |
| 7251 | |
| 7252 | rw.WriteHeader(http.StatusNoContent) |
| 7253 | } |
| 7254 | |
| 7255 | func ensureDefaultChatModelConfig( |
| 7256 | ctx context.Context, |
no test coverage detected