getWorkspaceID resolves workspace slug/ID from the request. If RequireWorkspaceAccess already resolved the workspace, reads from context. Otherwise falls back to direct resolution (for unauthenticated paths).
(w http.ResponseWriter, r *http.Request)
| 2257 | // If RequireWorkspaceAccess already resolved the workspace, reads from context. |
| 2258 | // Otherwise falls back to direct resolution (for unauthenticated paths). |
| 2259 | func (s *Server) getWorkspaceID(w http.ResponseWriter, r *http.Request) (string, bool) { |
| 2260 | // Fast path: already resolved by RequireWorkspaceAccess middleware |
| 2261 | if wsID, ok := r.Context().Value(ctxResolvedWorkspaceID).(string); ok && wsID != "" { |
| 2262 | return wsID, true |
| 2263 | } |
| 2264 | |
| 2265 | // Slow path: resolve directly (should rarely happen — only for routes |
| 2266 | // that don't go through RequireWorkspaceAccess) |
| 2267 | slugOrID := chi.URLParam(r, "slug") |
| 2268 | ws, err := s.resolveWorkspace(slugOrID, currentUser(r)) |
| 2269 | if err != nil { |
| 2270 | writeInternalError(w, err) |
| 2271 | return "", false |
| 2272 | } |
| 2273 | if ws == nil { |
| 2274 | writeError(w, http.StatusNotFound, "not_found", "Workspace not found") |
| 2275 | return "", false |
| 2276 | } |
| 2277 | return ws.ID, true |
| 2278 | } |
| 2279 | |
| 2280 | // getWorkspace returns the full workspace object resolved by middleware. |
| 2281 | // Falls back to direct resolution for routes without RequireWorkspaceAccess. |
no test coverage detected