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

Method getWorkspace

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

1920// getWorkspace returns the full workspace object resolved by middleware.
1921// Falls back to direct resolution for routes without RequireWorkspaceAccess.
1922func (s *Server) getWorkspace(w http.ResponseWriter, r *http.Request) (*models.Workspace, bool) {
1923 // Fast path: use middleware-resolved ID
1924 if wsID, ok := r.Context().Value(ctxResolvedWorkspaceID).(string); ok && wsID != "" {
1925 ws, err := s.store.GetWorkspaceByID(wsID)
1926 if err != nil {
1927 writeInternalError(w, err)
1928 return nil, false
1929 }
1930 if ws != nil {
1931 return ws, true
1932 }
1933 }
1934
1935 // Slow path: resolve from URL param
1936 slugOrID := chi.URLParam(r, "slug")
1937 ws, err := s.resolveWorkspace(slugOrID, currentUser(r))
1938 if err != nil {
1939 writeInternalError(w, err)
1940 return nil, false
1941 }
1942 if ws == nil {
1943 writeError(w, http.StatusNotFound, "not_found", "Workspace not found")
1944 return nil, false
1945 }
1946 return ws, true
1947}
1948
1949// visibleCollectionIDs returns the set of collection IDs the current user can
1950// 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