(w http.ResponseWriter, r *http.Request)
| 191 | } |
| 192 | |
| 193 | func (s *Server) appUpdateItem(w http.ResponseWriter, r *http.Request) { |
| 194 | ac := appContextFrom(r) |
| 195 | before, _, ok := s.appVisibleItem(w, r) |
| 196 | if !ok { |
| 197 | return |
| 198 | } |
| 199 | if !s.requireEditPermission(w, r, ac.WorkspaceID, before.ID, before.CollectionID) { |
| 200 | return |
| 201 | } |
| 202 | var in AppItemUpdateRequest |
| 203 | if err := decodeAppJSON(r, &in); err != nil { |
| 204 | writeError(w, http.StatusBadRequest, "bad_request", err.Error()) |
| 205 | return |
| 206 | } |
| 207 | if !s.appReadmitBeforeWrite(w, r, before.ID, before.CollectionID) { |
| 208 | return |
| 209 | } |
| 210 | as, err := s.appStore() |
| 211 | if err != nil { |
| 212 | writeInternalError(w, err) |
| 213 | return |
| 214 | } |
| 215 | wr, err := as.UpdateItemWrite(r.Context(), ac.appFenceSpec(), before.ID, appstore.AppItemUpdate{FieldsPatch: in.FieldsPatch, ExpectedETag: in.ExpectedETag}, appActor(ac)) |
| 216 | if err != nil { |
| 217 | writeAppStoreError(w, err) |
| 218 | return |
| 219 | } |
| 220 | after := wr.Item |
| 221 | s.publishItemEventWithName(sseItemUpdated, ac.WorkspaceID, after.ID, after.Title, wr.View.CollectionSlug, appActorKind(ac), wr.ActorDisplay, "app", after.Seq) |
| 222 | // Watchers hear about an app's status change as about anyone's. The signal is the fenced |
| 223 | // transaction's own, never a comparison with this handler's earlier read: a status another writer |
| 224 | // changed between that read and the commit is not this write's. |
| 225 | if after.LastMutation != nil && after.LastMutation.StatusChanged { |
| 226 | s.publishWatchNotifications(ac.WorkspaceID, after, appActorKind(ac), wr.ActorDisplay) |
| 227 | } |
| 228 | writeAppJSON(w, http.StatusOK, appWrittenItemDTO(wr)) |
| 229 | } |
| 230 | |
| 231 | // appCommentDTO is one comment's DTO, written by this request's actor. |
| 232 | func appCommentDTO(c *models.Comment, authorKind string) AppComment { |
nothing calls this directly
no test coverage detected