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)
| 1991 | // (e.g. handlers_ref_resolver.go) should use checkItemVisible directly with |
| 1992 | // a manually-derived role. |
| 1993 | func (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 |
no test coverage detected