MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / appReadmitBeforeWrite

Method appReadmitBeforeWrite

internal/server/app_api_write.go:388–418  ·  view source on GitHub ↗

appReadmitBeforeWrite re-admits a write after its body is read and before its write, and reports false after answering: a body can arrive slowly, and the person a delegated token acts for can lose access meanwhile. A full re-admission (the credential, the install, the person, their membership and ro

(w http.ResponseWriter, r *http.Request, itemID, collectionID string)

Source from the content-addressed store, hash-verified

386// checks the install and the companion again; what remains is the gap
387// between this check and that transaction, the one an upload has.
388func (s *Server) appReadmitBeforeWrite(w http.ResponseWriter, r *http.Request, itemID, collectionID string) bool {
389 ac := appContextFrom(r)
390 if err := s.appRevalidate(r); err != nil {
391 switch {
392 case errors.Is(err, errAppAdmitInternal):
393 writeInternalError(w, err)
394 case errors.Is(err, errAppCredential):
395 writeAppUnauthorized(w)
396 default:
397 writeError(w, http.StatusForbidden, "forbidden", "This app may no longer write here")
398 }
399 return false
400 }
401 if !appWriteAllows(r, collectionID) {
402 writeError(w, http.StatusForbidden, "forbidden", "This app may no longer write here")
403 return false
404 }
405 ok, err := s.canEditInCollection(r, ac.WorkspaceID, itemID, collectionID)
406 if err != nil {
407 writeInternalError(w, err)
408 return false
409 }
410 if !ok {
411 writeError(w, http.StatusForbidden, "forbidden", "This app may no longer write here")
412 return false
413 }
414 if s.appAfterWriteReadmit != nil {
415 s.appAfterWriteReadmit()
416 }
417 return true
418}

Callers 6

appCreateItemMethod · 0.95
appUpdateItemMethod · 0.95
appCreateCommentMethod · 0.95
appUpdateCommentMethod · 0.95
appDeleteCommentMethod · 0.95
appUploadAttachmentMethod · 0.95

Calls 8

appRevalidateMethod · 0.95
canEditInCollectionMethod · 0.95
appContextFromFunction · 0.85
writeInternalErrorFunction · 0.85
writeAppUnauthorizedFunction · 0.85
writeErrorFunction · 0.85
appWriteAllowsFunction · 0.85
IsMethod · 0.45

Tested by

no test coverage detected