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

Method getWorkspaceID

internal/server/server.go:1863–1882  ·  view source on GitHub ↗

getWorkspaceID resolves workspace slug/ID from the request. If RequireWorkspaceAccess already resolved the workspace, reads from context. Otherwise falls back to direct resolution (for unauthenticated paths).

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

Source from the content-addressed store, hash-verified

1861// If RequireWorkspaceAccess already resolved the workspace, reads from context.
1862// Otherwise falls back to direct resolution (for unauthenticated paths).
1863func (s *Server) getWorkspaceID(w http.ResponseWriter, r *http.Request) (string, bool) {
1864 // Fast path: already resolved by RequireWorkspaceAccess middleware
1865 if wsID, ok := r.Context().Value(ctxResolvedWorkspaceID).(string); ok && wsID != "" {
1866 return wsID, true
1867 }
1868
1869 // Slow path: resolve directly (should rarely happen — only for routes
1870 // that don't go through RequireWorkspaceAccess)
1871 slugOrID := chi.URLParam(r, "slug")
1872 ws, err := s.resolveWorkspace(slugOrID, currentUser(r))
1873 if err != nil {
1874 writeInternalError(w, err)
1875 return "", false
1876 }
1877 if ws == nil {
1878 writeError(w, http.StatusNotFound, "not_found", "Workspace not found")
1879 return "", false
1880 }
1881 return ws.ID, true
1882}
1883
1884// getWorkspace returns the full workspace object resolved by middleware.
1885// Falls back to direct resolution for routes without RequireWorkspaceAccess.

Callers 15

handleListMembersMethod · 0.95
handleInviteMemberMethod · 0.95
handleRemoveMemberMethod · 0.95
handleListDocumentsMethod · 0.95
handleCreateDocumentMethod · 0.95
handleRestoreDocumentMethod · 0.95
getWorkspaceDocumentMethod · 0.95

Calls 4

resolveWorkspaceMethod · 0.95
currentUserFunction · 0.85
writeInternalErrorFunction · 0.85
writeErrorFunction · 0.85

Tested by

no test coverage detected