@@ -181,24 +181,35 @@ private function getViewableCollections(array $collections): SupportCollection
181181
182182 public function getResourceCollection ($ request , $ items )
183183 {
184- // With no viewable collections we return empty data and, crucially, no columns. The
185- // columns would otherwise be derived from the first configured collection's blueprint,
186- // which the user isn't allowed to view.
187- if ($ this ->getViewableCollections ($ this ->getConfiguredCollections ())->isEmpty ()) {
184+ // Derive columns only from a collection the user can view. With none viewable, return
185+ // empty data and no columns rather than leaking the structure of an unviewable blueprint.
186+ if (! $ collection = $ this ->getColumnCollection ($ request )) {
188187 return JsonResource::collection ($ items )->additional (['meta ' => ['columns ' => []]]);
189188 }
190189
191190 return (new EntriesFieldtypeEntries ($ items , $ this ))
192- ->blueprint ($ this -> getBlueprint ( $ request ))
193- ->columnPreferenceKey ("collections. {$ this -> getFirstCollectionFromRequest ( $ request ) ->handle ()}.columns " )
191+ ->blueprint ($ collection -> entryBlueprint ( ))
192+ ->columnPreferenceKey ("collections. {$ collection ->handle ()}.columns " )
194193 ->additional (['meta ' => [
195194 'activeFilterBadges ' => $ this ->activeFilterBadges ,
196195 ]]);
197196 }
198197
199198 protected function getBlueprint ($ request = null )
200199 {
201- return $ this ->getFirstCollectionFromRequest ($ request )->entryBlueprint ();
200+ return $ this ->getColumnCollection ($ request )?->entryBlueprint();
201+ }
202+
203+ protected function getColumnCollection ($ request = null )
204+ {
205+ $ collection = $ this ->getFirstCollectionFromRequest ($ request );
206+
207+ // Only derive columns from a collection the user can view. If the first requested or
208+ // configured collection isn't viewable, fall back to the first viewable configured
209+ // collection, or none at all when the user can view none of them.
210+ return User::current ()->can ('view ' , $ collection )
211+ ? $ collection
212+ : $ this ->getViewableCollections ($ this ->getConfiguredCollections ())->first ();
202213 }
203214
204215 protected function getFirstCollectionFromRequest ($ request )
@@ -468,18 +479,22 @@ public function toGqlType()
468479
469480 public function getColumns ()
470481 {
471- if (count ($ this ->getConfiguredCollections ()) === 1 ) {
472- $ columns = $ this ->getBlueprint ()->columns ();
482+ // Don't derive columns from a blueprint the user can't view; fall back to the
483+ // default columns when none of the configured collections are viewable.
484+ if (! $ collection = $ this ->getColumnCollection ()) {
485+ return parent ::getColumns ();
486+ }
487+
488+ $ columns = $ collection ->entryBlueprint ()->columns ();
473489
490+ if (count ($ this ->getConfiguredCollections ()) === 1 ) {
474491 $ this ->addColumn ($ columns , 'status ' );
475492
476- $ columns ->setPreferred ("collections. {$ this -> getConfiguredCollections ()[ 0 ] }.columns " );
493+ $ columns ->setPreferred ("collections. {$ collection -> handle () }.columns " );
477494
478495 return $ columns ->rejectUnlisted ()->values ();
479496 }
480497
481- $ columns = $ this ->getBlueprint ()->columns ();
482-
483498 if ($ this ->canSelectAcrossSites ()) {
484499 $ this ->addColumn ($ columns , 'site ' );
485500 }
0 commit comments