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

Method getWorkspace

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

1884// getWorkspace returns the full workspace object resolved by middleware.
1885// Falls back to direct resolution for routes without RequireWorkspaceAccess.
1886func (s *Server) getWorkspace(w http.ResponseWriter, r *http.Request) (*models.Workspace, bool) {
1887 // Fast path: use middleware-resolved ID
1888 if wsID, ok := r.Context().Value(ctxResolvedWorkspaceID).(string); ok && wsID != "" {
1889 ws, err := s.store.GetWorkspaceByID(wsID)
1890 if err != nil {
1891 writeInternalError(w, err)
1892 return nil, false
1893 }
1894 if ws != nil {
1895 return ws, true
1896 }
1897 }
1898
1899 // Slow path: resolve from URL param
1900 slugOrID := chi.URLParam(r, "slug")
1901 ws, err := s.resolveWorkspace(slugOrID, currentUser(r))
1902 if err != nil {
1903 writeInternalError(w, err)
1904 return nil, false
1905 }
1906 if ws == nil {
1907 writeError(w, http.StatusNotFound, "not_found", "Workspace not found")
1908 return nil, false
1909 }
1910 return ws, true
1911}
1912
1913// visibleCollectionIDs returns the set of collection IDs the current user can
1914// 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