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

Method getWorkspaceID

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

2257// If RequireWorkspaceAccess already resolved the workspace, reads from context.
2258// Otherwise falls back to direct resolution (for unauthenticated paths).
2259func (s *Server) getWorkspaceID(w http.ResponseWriter, r *http.Request) (string, bool) {
2260 // Fast path: already resolved by RequireWorkspaceAccess middleware
2261 if wsID, ok := r.Context().Value(ctxResolvedWorkspaceID).(string); ok && wsID != "" {
2262 return wsID, true
2263 }
2264
2265 // Slow path: resolve directly (should rarely happen — only for routes
2266 // that don't go through RequireWorkspaceAccess)
2267 slugOrID := chi.URLParam(r, "slug")
2268 ws, err := s.resolveWorkspace(slugOrID, currentUser(r))
2269 if err != nil {
2270 writeInternalError(w, err)
2271 return "", false
2272 }
2273 if ws == nil {
2274 writeError(w, http.StatusNotFound, "not_found", "Workspace not found")
2275 return "", false
2276 }
2277 return ws.ID, true
2278}
2279
2280// getWorkspace returns the full workspace object resolved by middleware.
2281// 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