fix: join collection read access (#9930)

Respect read access control through the join field collections for GraphQL and admin UI

fixes #9922 and #9865
This commit is contained in:
Dan Ribbens
2024-12-12 12:01:03 -05:00
committed by GitHub
parent d4d79c1141
commit 5af71fb8d0
8 changed files with 196 additions and 7 deletions

View File

@@ -11,6 +11,8 @@ import { Uploads } from './collections/Uploads.js'
import { Versions } from './collections/Versions.js'
import { seed } from './seed.js'
import {
categoriesJoinRestrictedSlug,
collectionRestrictedSlug,
localizedCategoriesSlug,
localizedPostsSlug,
postsSlug,
@@ -95,6 +97,25 @@ export default buildConfigWithDefaults({
},
],
},
{
slug: categoriesJoinRestrictedSlug,
admin: {
useAsTitle: 'name',
},
fields: [
{
name: 'name',
type: 'text',
},
{
// join collection with access.read: () => false which should not populate
name: 'collectionRestrictedJoin',
type: 'join',
collection: collectionRestrictedSlug,
on: 'category',
},
],
},
{
slug: restrictedPostsSlug,
admin: {
@@ -120,6 +141,31 @@ export default buildConfigWithDefaults({
},
],
},
{
slug: collectionRestrictedSlug,
admin: {
useAsTitle: 'title',
},
access: {
read: () => ({ canRead: { equals: true } }),
},
fields: [
{
name: 'title',
type: 'text',
},
{
name: 'canRead',
type: 'checkbox',
defaultValue: false,
},
{
name: 'category',
type: 'relationship',
relationTo: restrictedCategoriesSlug,
},
],
},
],
localization: {
locales: ['en', 'es'],