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

Method getWorkspaceID

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

1995// If RequireWorkspaceAccess already resolved the workspace, reads from context.
1996// Otherwise falls back to direct resolution (for unauthenticated paths).
1997func (s *Server) getWorkspaceID(w http.ResponseWriter, r *http.Request) (string, bool) {
1998 // Fast path: already resolved by RequireWorkspaceAccess middleware
1999 if wsID, ok := r.Context().Value(ctxResolvedWorkspaceID).(string); ok && wsID != "" {
2000 return wsID, true
2001 }
2002
2003 // Slow path: resolve directly (should rarely happen — only for routes
2004 // that don't go through RequireWorkspaceAccess)
2005 slugOrID := chi.URLParam(r, "slug")
2006 ws, err := s.resolveWorkspace(slugOrID, currentUser(r))
2007 if err != nil {
2008 writeInternalError(w, err)
2009 return "", false
2010 }
2011 if ws == nil {
2012 writeError(w, http.StatusNotFound, "not_found", "Workspace not found")
2013 return "", false
2014 }
2015 return ws.ID, true
2016}
2017
2018// getWorkspace returns the full workspace object resolved by middleware.
2019// 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