MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / getWorkspace

Method getWorkspace

internal/server/server.go:2020–2045  ·  view source on GitHub ↗

getWorkspace returns the full workspace object resolved by middleware. Falls back to direct resolution for routes without RequireWorkspaceAccess.

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

2018// getWorkspace returns the full workspace object resolved by middleware.
2019// Falls back to direct resolution for routes without RequireWorkspaceAccess.
2020func (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

Callers 8

handleGetWorkspaceMethod · 0.95
handleUpdateWorkspaceMethod · 0.95
handleDeleteWorkspaceMethod · 0.95
handleExportWorkspaceMethod · 0.95
handlePushToItemMethod · 0.95

Calls 5

resolveWorkspaceMethod · 0.95
writeInternalErrorFunction · 0.85
currentUserFunction · 0.85
writeErrorFunction · 0.85
GetWorkspaceByIDMethod · 0.80

Tested by

no test coverage detected