getWorkspace returns the full workspace object resolved by middleware. Falls back to direct resolution for routes without RequireWorkspaceAccess.
(w http.ResponseWriter, r *http.Request)
| 2018 | // getWorkspace returns the full workspace object resolved by middleware. |
| 2019 | // Falls back to direct resolution for routes without RequireWorkspaceAccess. |
| 2020 | func (s *Server) getWorkspace(w http.ResponseWriter, r *http.Request) (*models.Workspace, bool) { |
| 2021 | // Fast path: use middleware-resolved ID |
| 2022 | if wsID, ok := r.Context().Value(ctxResolvedWorkspaceID).(string); ok && wsID != "" { |
| 2023 | ws, err := s.store.GetWorkspaceByID(wsID) |
| 2024 | if err != nil { |
| 2025 | writeInternalError(w, err) |
| 2026 | return nil, false |
| 2027 | } |
| 2028 | if ws != nil { |
| 2029 | return ws, true |
| 2030 | } |
| 2031 | } |
| 2032 | |
| 2033 | // Slow path: resolve from URL param |
| 2034 | slugOrID := chi.URLParam(r, "slug") |
| 2035 | ws, err := s.resolveWorkspace(slugOrID, currentUser(r)) |
| 2036 | if err != nil { |
| 2037 | writeInternalError(w, err) |
| 2038 | return nil, false |
| 2039 | } |
| 2040 | if ws == nil { |
| 2041 | writeError(w, http.StatusNotFound, "not_found", "Workspace not found") |
| 2042 | return nil, false |
| 2043 | } |
| 2044 | return ws, true |
| 2045 | } |
| 2046 | |
| 2047 | // visibleCollectionIDs returns the set of collection IDs the current user can |
| 2048 | // see in the given workspace. Returns nil if the user has "all" access (no |
no test coverage detected