feat(authPolicies): add demo project as a publicly loadable override (#5137)

This commit is contained in:
Gergő Jedlicska
2025-07-24 11:04:53 +02:00
committed by GitHub
parent f8c8170e48
commit d0cd330a61
2 changed files with 22 additions and 0 deletions
@@ -38,6 +38,21 @@ const buildCanLoadPolicy = (overrides?: Partial<Parameters<typeof canLoadPolicy>
})
describe('canLoad', () => {
it('returns ok if anyone is trying to load a publicly loadable project', async () => {
const canLoad = buildCanLoadPolicy()
// this is a deliberate copy pasta, if anyone removes from the baked in list,
// the test should fail
const publiclyLoadableProjects = ['8be1007be1']
for (const projectId of publiclyLoadableProjects) {
const result = await canLoad({
userId: undefined,
projectId
})
expect(result).toBeAuthOKResult()
}
})
it('returns error if user is not logged in', async () => {
const canLoad = buildCanLoadPolicy()
@@ -45,6 +45,9 @@ type PolicyErrors = InstanceType<
export const canLoadPolicy: AuthPolicy<PolicyLoaderKeys, PolicyArgs, PolicyErrors> =
(loaders) =>
async ({ userId, projectId }) => {
if (publiclyLoadableProjects.includes(projectId)) {
return ok()
}
const hasAdminAccess = await checkIfAdminOverrideEnabledFragment(loaders)({
userId
})
@@ -70,3 +73,7 @@ export const canLoadPolicy: AuthPolicy<PolicyLoaderKeys, PolicyArgs, PolicyError
return ok()
}
const publiclyLoadableProjects = [
'8be1007be1' // Demo models
]