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)
| 438 | // shared helpers read, from the grant and real membership, and refuses the |
| 439 | // request if any is missing. |
| 440 | func (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 |