MCPcopy Index your code
hub / github.com/coder/coder / patchChat

Method patchChat

coderd/exp_chats.go:2653–2921  ·  view source on GitHub ↗

patchChat updates a chat resource. Supports updating labels, workspace binding, archiving, pinning, and pinned-chat ordering. @Summary Update chat @ID update-chat @Security CoderSessionToken @Tags Chats @Accept json @Param chat path string true "Chat ID" format(uuid) @Param request body codersdk.Up

(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

2651// @Router /api/experimental/chats/{chat} [patch]
2652// @Description Experimental: this endpoint is subject to change.
2653func (api *API) patchChat(rw http.ResponseWriter, r *http.Request) {
2654 ctx := r.Context()
2655 chat := httpmw.ChatParam(r)
2656
2657 if !api.Authorize(r, policy.ActionUpdate, chat.RBACObject()) {
2658 httpapi.ResourceNotFound(rw)
2659 return
2660 }
2661
2662 aReq, commitAudit := audit.InitRequest[database.Chat](rw, &audit.RequestParams{
2663 Audit: *api.Auditor.Load(),
2664 Log: api.Logger,
2665 Request: r,
2666 Action: database.AuditActionWrite,
2667 })
2668 defer commitAudit()
2669 aReq.Old = chat
2670 aReq.UpdateOrganizationID(chat.OrganizationID)
2671
2672 var req codersdk.UpdateChatRequest
2673 if !httpapi.Read(ctx, rw, r, &req) {
2674 return
2675 }
2676
2677 var planModeUpdate *database.NullChatPlanMode
2678 if req.PlanMode != nil {
2679 if !validateChatPlanMode(*req.PlanMode) {
2680 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
2681 Message: "Invalid plan_mode value.",
2682 })
2683 return
2684 }
2685 resolvedPlanMode := planModeToNullChatPlanMode(*req.PlanMode)
2686 planModeUpdate = &resolvedPlanMode
2687 }
2688
2689 if req.Title != nil {
2690 updatedChat, handled := api.applyChatTitleUpdate(ctx, rw, chat, *req.Title)
2691 if handled {
2692 return
2693 }
2694 chat = updatedChat
2695 }
2696 if req.Labels != nil {
2697 if errs := httpapi.ValidateChatLabels(*req.Labels); len(errs) > 0 {
2698 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
2699 Message: "Invalid labels.",
2700 Validations: errs,
2701 })
2702 return
2703 }
2704 labelsJSON, err := json.Marshal(*req.Labels)
2705 if err != nil {
2706 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
2707 Message: "Failed to marshal labels.",
2708 Detail: err.Error(),
2709 })
2710 return

Callers

nothing calls this directly

Calls 15

AuthorizeMethod · 0.95
applyChatTitleUpdateMethod · 0.95
ChatParamFunction · 0.92
ResourceNotFoundFunction · 0.92
InitRequestFunction · 0.92
ReadFunction · 0.92
WriteFunction · 0.92
ValidateChatLabelsFunction · 0.92
IsCheckViolationFunction · 0.92
validateChatPlanModeFunction · 0.85

Tested by

no test coverage detected