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

Method requireItemVisible

internal/server/server.go:1993–2004  ·  view source on GitHub ↗

requireItemVisible checks that the item's collection is visible to the requesting user. For guests with item-level grants, also verifies that the specific item is granted (not just the collection). Writes a 404 and returns false if not. Callers should invoke this immediately after resolving an item

(w http.ResponseWriter, r *http.Request, workspaceID string, item *models.Item)

Source from the content-addressed store, hash-verified

1991// (e.g. handlers_ref_resolver.go) should use checkItemVisible directly with
1992// a manually-derived role.
1993func (s *Server) requireItemVisible(w http.ResponseWriter, r *http.Request, workspaceID string, item *models.Item) bool {
1994 visible, err := s.checkItemVisible(workspaceID, item, currentUser(r), workspaceRole(r), isBearerAuth(r))
1995 if err != nil {
1996 writeInternalError(w, err)
1997 return false
1998 }
1999 if !visible {
2000 writeError(w, http.StatusNotFound, "not_found", "Item not found")
2001 return false
2002 }
2003 return true
2004}
2005
2006// checkItemVisible is the context-free visibility decision. Returns (true,
2007// nil) when the (user, role) pair can see `item` under the same rules

Callers 15

handleListItemGrantsMethod · 0.95
handleCreateItemGrantMethod · 0.95
handleDeleteItemGrantMethod · 0.95
handleGetItemLinksMethod · 0.95
handleCreateItemLinkMethod · 0.95
handleShowPlaybookMethod · 0.95
handleRunPlaybookMethod · 0.95
handleGetItemVersionMethod · 0.95

Calls 6

checkItemVisibleMethod · 0.95
currentUserFunction · 0.85
workspaceRoleFunction · 0.85
isBearerAuthFunction · 0.85
writeInternalErrorFunction · 0.85
writeErrorFunction · 0.85

Tested by

no test coverage detected