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)
| 1995 | // If RequireWorkspaceAccess already resolved the workspace, reads from context. |
| 1996 | // Otherwise falls back to direct resolution (for unauthenticated paths). |
| 1997 | func (s *Server) getWorkspaceID(w http.ResponseWriter, r *http.Request) (string, bool) { |
| 1998 | // Fast path: already resolved by RequireWorkspaceAccess middleware |
| 1999 | if wsID, ok := r.Context().Value(ctxResolvedWorkspaceID).(string); ok && wsID != "" { |
| 2000 | return wsID, true |
| 2001 | } |
| 2002 | |
| 2003 | // Slow path: resolve directly (should rarely happen — only for routes |
| 2004 | // that don't go through RequireWorkspaceAccess) |
| 2005 | slugOrID := chi.URLParam(r, "slug") |
| 2006 | ws, err := s.resolveWorkspace(slugOrID, currentUser(r)) |
| 2007 | if err != nil { |
| 2008 | writeInternalError(w, err) |
| 2009 | return "", false |
| 2010 | } |
| 2011 | if ws == nil { |
| 2012 | writeError(w, http.StatusNotFound, "not_found", "Workspace not found") |
| 2013 | return "", false |
| 2014 | } |
| 2015 | return ws.ID, true |
| 2016 | } |
| 2017 | |
| 2018 | // getWorkspace returns the full workspace object resolved by middleware. |
| 2019 | // Falls back to direct resolution for routes without RequireWorkspaceAccess. |
no test coverage detected