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

Method appReadmitBeforeWrite

internal/server/app_api_write.go:383–413  ·  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

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

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