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

Method getWorkspace

internal/server/server.go:1977–2002  ·  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

1975// getWorkspace returns the full workspace object resolved by middleware.
1976// Falls back to direct resolution for routes without RequireWorkspaceAccess.
1977func (s *Server) getWorkspace(w http.ResponseWriter, r *http.Request) (*models.Workspace, bool) {
1978 // Fast path: use middleware-resolved ID
1979 if wsID, ok := r.Context().Value(ctxResolvedWorkspaceID).(string); ok && wsID != "" {
1980 ws, err := s.store.GetWorkspaceByID(wsID)
1981 if err != nil {
1982 writeInternalError(w, err)
1983 return nil, false
1984 }
1985 if ws != nil {
1986 return ws, true
1987 }
1988 }
1989
1990 // Slow path: resolve from URL param
1991 slugOrID := chi.URLParam(r, "slug")
1992 ws, err := s.resolveWorkspace(slugOrID, currentUser(r))
1993 if err != nil {
1994 writeInternalError(w, err)
1995 return nil, false
1996 }
1997 if ws == nil {
1998 writeError(w, http.StatusNotFound, "not_found", "Workspace not found")
1999 return nil, false
2000 }
2001 return ws, true
2002}
2003
2004// visibleCollectionIDs returns the set of collection IDs the current user can
2005// see in the given workspace. Returns nil if the user has "all" access (no

Callers 7

handleGetWorkspaceMethod · 0.95
handleUpdateWorkspaceMethod · 0.95
handleDeleteWorkspaceMethod · 0.95
handleExportWorkspaceMethod · 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