(w http.ResponseWriter, r *http.Request)
| 245 | } |
| 246 | |
| 247 | func (s *Server) appCreateComment(w http.ResponseWriter, r *http.Request) { |
| 248 | ac := appContextFrom(r) |
| 249 | item, _, ok := s.appVisibleItem(w, r) |
| 250 | if !ok { |
| 251 | return |
| 252 | } |
| 253 | if !s.requireEditPermission(w, r, ac.WorkspaceID, item.ID, item.CollectionID) { |
| 254 | return |
| 255 | } |
| 256 | var in AppCommentCreateRequest |
| 257 | if err := decodeAppJSON(r, &in); err != nil { |
| 258 | writeError(w, http.StatusBadRequest, "bad_request", err.Error()) |
| 259 | return |
| 260 | } |
| 261 | if !s.appReadmitBeforeWrite(w, r, item.ID, item.CollectionID) { |
| 262 | return |
| 263 | } |
| 264 | as, err := s.appStore() |
| 265 | if err != nil { |
| 266 | writeInternalError(w, err) |
| 267 | return |
| 268 | } |
| 269 | // The author is server-set: the app's bot display name, |
| 270 | // read in the write's transaction (Author left empty). What the write |
| 271 | // publishes is the item as that transaction found it: a human may have |
| 272 | // moved it to another companion since this handler's read, and a |
| 273 | // notification naming the old collection would reach that collection's |
| 274 | // watchers. |
| 275 | cw, err := as.CreateCommentWrite(r.Context(), ac.appFenceSpec(), item.ID, |
| 276 | appstore.AppCommentCreate{Body: in.Body, ParentID: in.ParentCommentID}, appActor(ac)) |
| 277 | if err != nil { |
| 278 | writeAppStoreError(w, err) |
| 279 | return |
| 280 | } |
| 281 | comment, at := cw.Comment, cw.Item |
| 282 | s.publishCommentEvent(sseCommentCreated, ac.WorkspaceID, at.ID, comment.ID, at.Title, at.CollectionSlug, appActorKind(ac), "app") |
| 283 | s.publishWatchNotification(watchevents.Notification{ |
| 284 | WorkspaceID: ac.WorkspaceID, |
| 285 | ItemID: at.ID, |
| 286 | CollectionID: at.CollectionID, |
| 287 | ItemRef: at.Ref, |
| 288 | Kind: watchevents.KindComment, |
| 289 | Actor: appActorKind(ac), |
| 290 | ActorName: cw.ActorDisplay, |
| 291 | Summary: truncateForSummary(comment.Body, 120), |
| 292 | }) |
| 293 | writeAppJSON(w, http.StatusCreated, appCommentDTO(comment, appCommentAuthorKind(ac))) |
| 294 | } |
| 295 | |
| 296 | // appCommentOnItem resolves the comment for a PATCH or DELETE: the item |
| 297 | // first, then the comment, which must be on THAT item, else the same 404 a |
nothing calls this directly
no test coverage detected