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

Method appVisibleCollection

internal/server/app_api_read.go:142–165  ·  view source on GitHub ↗

appVisibleCollection resolves a collection by EXACT slug in the token's workspace, inside the ceiling and the actor's visibility, or reports false after answering the same 404 a missing collection gets.

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

Source from the content-addressed store, hash-verified

140// workspace, inside the ceiling and the actor's visibility, or reports false
141// after answering the same 404 a missing collection gets.
142func (s *Server) appVisibleCollection(w http.ResponseWriter, r *http.Request, slug string) (*models.Collection, bool) {
143 ac := appContextFrom(r)
144 c, err := s.store.GetCollectionBySlug(ac.WorkspaceID, slug)
145 if err != nil {
146 writeInternalError(w, err)
147 return nil, false
148 }
149 if c == nil || c.DeletedAt != nil || c.Slug != slug {
150 writeAppNotFound(w, "Collection")
151 return nil, false
152 }
153 ids, err := s.visibleCollectionIDs(r, ac.WorkspaceID)
154 if err != nil {
155 writeInternalError(w, err)
156 return nil, false
157 }
158 if !isCollectionVisible(c.ID, ids) || !appCeilingAllows(r, c.ID) {
159 writeAppNotFound(w, "Collection")
160 return nil, false
161 }
162 id := c.ID
163 appAddRecheck(r, func(r2 *http.Request) error { return s.appRecheckCollection(r2, id) })
164 return c, true
165}
166
167var errAppRecheck = errors.New("app authorization no longer holds")
168

Callers 3

appGetCollectionMethod · 0.95
appListItemsMethod · 0.95
appCreateItemMethod · 0.95

Calls 9

visibleCollectionIDsMethod · 0.95
appRecheckCollectionMethod · 0.95
appContextFromFunction · 0.85
writeInternalErrorFunction · 0.85
writeAppNotFoundFunction · 0.85
isCollectionVisibleFunction · 0.85
appCeilingAllowsFunction · 0.85
appAddRecheckFunction · 0.85
GetCollectionBySlugMethod · 0.80

Tested by

no test coverage detected