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)
| 140 | // workspace, inside the ceiling and the actor's visibility, or reports false |
| 141 | // after answering the same 404 a missing collection gets. |
| 142 | func (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 | |
| 167 | var errAppRecheck = errors.New("app authorization no longer holds") |
| 168 |
no test coverage detected