### What? When read access is restricted on the `users` collection - restricted users would not have access to other users complete user data object only their IDs when accessing `user.value`. ### Why? This is problematic when determining the lock status of a document from a restricted users perspective as `user.id` would not exist - the user data would not be an object in this case but instead a `string` or `number` value for user ID ### How? This PR properly handles both cases now and checks if the incoming user data is an object or just a `string` / `number`.
65 lines
1.7 KiB
TypeScript
65 lines
1.7 KiB
TypeScript
import { fileURLToPath } from 'node:url'
|
|
import path from 'path'
|
|
|
|
import { buildConfigWithDefaults } from '../buildConfigWithDefaults.js'
|
|
import { devUser, regularUser } from '../credentials.js'
|
|
import { PagesCollection, pagesSlug } from './collections/Pages/index.js'
|
|
import { PostsCollection, postsSlug } from './collections/Posts/index.js'
|
|
import { TestsCollection } from './collections/Tests/index.js'
|
|
import { Users } from './collections/Users/index.js'
|
|
import { AdminGlobal } from './globals/Admin/index.js'
|
|
import { MenuGlobal } from './globals/Menu/index.js'
|
|
|
|
const filename = fileURLToPath(import.meta.url)
|
|
const dirname = path.dirname(filename)
|
|
|
|
export default buildConfigWithDefaults({
|
|
admin: {
|
|
importMap: {
|
|
baseDir: path.resolve(dirname),
|
|
},
|
|
},
|
|
collections: [PagesCollection, PostsCollection, TestsCollection, Users],
|
|
globals: [AdminGlobal, MenuGlobal],
|
|
onInit: async (payload) => {
|
|
if (process.env.SEED_IN_CONFIG_ONINIT !== 'false') {
|
|
await payload.create({
|
|
collection: 'users',
|
|
data: {
|
|
email: devUser.email,
|
|
password: devUser.password,
|
|
name: 'Admin',
|
|
roles: ['is_admin', 'is_user'],
|
|
},
|
|
})
|
|
|
|
await payload.create({
|
|
collection: 'users',
|
|
data: {
|
|
email: regularUser.email,
|
|
password: regularUser.password,
|
|
name: 'Dev',
|
|
roles: ['is_user'],
|
|
},
|
|
})
|
|
|
|
await payload.create({
|
|
collection: pagesSlug,
|
|
data: {
|
|
text: 'example page',
|
|
},
|
|
})
|
|
|
|
await payload.create({
|
|
collection: postsSlug,
|
|
data: {
|
|
text: 'example post',
|
|
},
|
|
})
|
|
}
|
|
},
|
|
typescript: {
|
|
outputFile: path.resolve(dirname, 'payload-types.ts'),
|
|
},
|
|
})
|