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

Method requireAppWorkspace

internal/server/app_api.go:440–468  ·  view source on GitHub ↗

requireAppWorkspace is step 3 (RequireAppWorkspaceAccess). {ws} must be the token's workspace, by ID: a slug, another workspace, or a deleted one all get the workspace 404. It then sets every context key the shared helpers read, from the grant and real membership, and refuses the request if any is m

(next http.Handler)

Source from the content-addressed store, hash-verified

438// shared helpers read, from the grant and real membership, and refuses the
439// request if any is missing.
440func (s *Server) requireAppWorkspace(next http.Handler) http.Handler {
441 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
442 ac := appContextFrom(r)
443 if ac == nil {
444 writeAppUnauthorized(w)
445 return
446 }
447 if chi.URLParam(r, "ws") != ac.WorkspaceID {
448 writeWorkspaceNotFound(w, "Workspace not found")
449 return
450 }
451 full, err := s.appAdmitWorkspace(ac)
452 if err != nil {
453 if errors.Is(err, errAppAdmitInternal) {
454 writeInternalError(w, err)
455 return
456 }
457 writeWorkspaceNotFound(w, "Workspace not found")
458 return
459 }
460 r = r.WithContext(appRequestContext(r.Context(), full))
461 if err := appContextSelfCheck(r); err != nil {
462 slog.Error("app API: context self-check failed", "error", err)
463 writeInternalError(w, err)
464 return
465 }
466 next.ServeHTTP(w, r)
467 })
468}
469
470// appAdmitWorkspace is the workspace half of admission, shared by the door
471// and the re-admission: the workspace is live, the bot is a member, and the

Callers 2

registerAppAPIRoutesMethod · 0.95

Calls 10

appAdmitWorkspaceMethod · 0.95
appContextFromFunction · 0.85
writeAppUnauthorizedFunction · 0.85
writeWorkspaceNotFoundFunction · 0.85
writeInternalErrorFunction · 0.85
appRequestContextFunction · 0.85
appContextSelfCheckFunction · 0.85
IsMethod · 0.45
ErrorMethod · 0.45
ServeHTTPMethod · 0.45

Tested by 1