Promote to admin only on the first-register screen, not any first create
An open sign-up on an empty collection would otherwise become admin. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
4c199acdfd
commit
e5d86b8afe
@@ -118,8 +118,8 @@ describe('forms collection: public read, editor+ write, Emails hidden from plain
|
||||
})
|
||||
})
|
||||
|
||||
describe('roles field: the first account becomes admin', () => {
|
||||
const hook = async (totalDocs: number, value: string[]) => {
|
||||
describe('roles field: the first-register account becomes admin', () => {
|
||||
const hook = async (totalDocs: number, value: string[], pathname = '/api/users/first-register') => {
|
||||
const config = await ipalKit({ access: { authCollection: 'users' }, i18n, twoFactor: false })(empty())
|
||||
const users = config.collections?.find((c) => c.slug === 'users') as CollectionConfig
|
||||
const roles = users.fields.find((f) => 'name' in f && f.name === 'roles') as { hooks?: { beforeChange?: ((a: unknown) => unknown)[] } }
|
||||
@@ -127,7 +127,7 @@ describe('roles field: the first account becomes admin', () => {
|
||||
return roles.hooks?.beforeChange?.[0]?.({
|
||||
collection: { slug: 'users' },
|
||||
operation: 'create',
|
||||
req: { payload: { count } },
|
||||
req: { pathname, payload: { count } },
|
||||
value,
|
||||
})
|
||||
}
|
||||
@@ -139,4 +139,8 @@ describe('roles field: the first account becomes admin', () => {
|
||||
test('later accounts keep what access allowed', async () => {
|
||||
expect(await hook(1, ['user'])).toEqual(['user'])
|
||||
})
|
||||
|
||||
test('an open sign-up on an empty collection is not promoted', async () => {
|
||||
expect(await hook(0, ['user'], '/api/users')).toEqual(['user'])
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user