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)
| 1861 | // If RequireWorkspaceAccess already resolved the workspace, reads from context. |
| 1862 | // Otherwise falls back to direct resolution (for unauthenticated paths). |
| 1863 | func (s *Server) getWorkspaceID(w http.ResponseWriter, r *http.Request) (string, bool) { |
| 1864 | // Fast path: already resolved by RequireWorkspaceAccess middleware |
| 1865 | if wsID, ok := r.Context().Value(ctxResolvedWorkspaceID).(string); ok && wsID != "" { |
| 1866 | return wsID, true |
| 1867 | } |
| 1868 | |
| 1869 | // Slow path: resolve directly (should rarely happen — only for routes |
| 1870 | // that don't go through RequireWorkspaceAccess) |
| 1871 | slugOrID := chi.URLParam(r, "slug") |
| 1872 | ws, err := s.resolveWorkspace(slugOrID, currentUser(r)) |
| 1873 | if err != nil { |
| 1874 | writeInternalError(w, err) |
| 1875 | return "", false |
| 1876 | } |
| 1877 | if ws == nil { |
| 1878 | writeError(w, http.StatusNotFound, "not_found", "Workspace not found") |
| 1879 | return "", false |
| 1880 | } |
| 1881 | return ws.ID, true |
| 1882 | } |
| 1883 | |
| 1884 | // getWorkspace returns the full workspace object resolved by middleware. |
| 1885 | // Falls back to direct resolution for routes without RequireWorkspaceAccess. |
no test coverage detected