Small fixes: optional R2_PUBLIC_URL, seo.uploadsCollection, staff features without roles

- ipalEnvRules({ storage: true }): R2_PUBLIC_URL optional (media served by
  the app); storage: { requirePublicUrl: true } requires it again.
- seo.uploadsCollection: upload collection of the meta image (default media).
- userMeetsRole(req, minimum): the plugin's admin/editor features (Site
  Integrations, settings globals, test e-mail, stats, consent records, form
  submissions) stay reachable when `access` is omitted — without a roles
  field every logged-in account passes, as in Payload's default.
- IndexNow skip for seed writes is covered by test/seed.test.ts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-10-22 18:33:35 +02:00
co-authored by Claude Opus 5.5
parent cff76c2a69
commit 4911da7112
24 changed files with 167 additions and 68 deletions
+16 -2
View File
@@ -12,10 +12,10 @@ const r2 = {
R2_SECRET_ACCESS_KEY: 's',
}
function check(env: Record<string, string>) {
function check(env: Record<string, string>, storage: NonNullable<Parameters<typeof ipalEnvRules>[0]>['storage'] = true) {
vi.unstubAllEnvs()
for (const [k, v] of Object.entries(env)) {vi.stubEnv(k, v)}
return () => assertEnv(ipalEnvRules({ storage: true }), { env })
return () => assertEnv(ipalEnvRules({ storage }), { env })
}
afterEach(() => vi.unstubAllEnvs())
@@ -26,6 +26,20 @@ describe('ipalEnvRules({ storage })', () => {
expect(check({ ...base, ...r2, NODE_ENV: 'production' })).not.toThrow()
})
test('production: R2_PUBLIC_URL is optional by default (media served by the app)', () => {
const { R2_PUBLIC_URL: _unused, ...credentials } = r2
expect(check({ ...base, ...credentials, NODE_ENV: 'production' })).not.toThrow()
// still validated when set
expect(check({ ...base, ...r2, NODE_ENV: 'production', R2_PUBLIC_URL: '/media' })).toThrow(/absolute URL in production/)
})
test('requirePublicUrl: true makes R2_PUBLIC_URL required with the credentials', () => {
const { R2_PUBLIC_URL: _unused, ...credentials } = r2
expect(check({ ...base, ...credentials, NODE_ENV: 'production' }, { requirePublicUrl: true })).toThrow(/R2_PUBLIC_URL is required/)
expect(check({ ...base, ...r2, NODE_ENV: 'production' }, { requirePublicUrl: true })).not.toThrow()
expect(check({ ...base, NODE_ENV: 'development' }, { requirePublicUrl: true })).not.toThrow()
})
test('development: no R2 at all is fine (local disk)', () => {
expect(check({ ...base, NODE_ENV: 'development' })).not.toThrow()
})