From e327037d6a8a5b7eb3b2609f4b8221a5a8f1e02a Mon Sep 17 00:00:00 2001 From: Moiz Adnan <67912355+MoizAdnan@users.noreply.github.com> Date: Tue, 9 Jul 2024 16:35:55 +0500 Subject: [PATCH] IR: 2908: Re-evaluate feathers validator usage for projects services (#10518) * fixed project services validators * chore: Update project helper to include assetsOnly parameter --- .../project-build/project-build.hooks.ts | 2 +- .../project-invalidate.hooks.ts | 2 +- .../project-permission.hooks.ts | 6 +++--- .../src/projects/project/project-helper.ts | 6 +----- .../src/projects/project/project.hooks.ts | 19 ++++++------------- .../src/projects/project/project.test.ts | 5 ++--- 6 files changed, 14 insertions(+), 26 deletions(-) diff --git a/packages/server-core/src/projects/project-build/project-build.hooks.ts b/packages/server-core/src/projects/project-build/project-build.hooks.ts index 52d00ba61e..1e0967fc30 100644 --- a/packages/server-core/src/projects/project-build/project-build.hooks.ts +++ b/packages/server-core/src/projects/project-build/project-build.hooks.ts @@ -43,7 +43,7 @@ export default { update: [disallow()], patch: [ iff(isProvider('external'), verifyScope('projects', 'write')), - () => schemaHooks.validateData(projectBuildPatchValidator), + schemaHooks.validateData(projectBuildPatchValidator), schemaHooks.resolveData(projectBuildPatchResolver) ], remove: [disallow()] diff --git a/packages/server-core/src/projects/project-invalidate/project-invalidate.hooks.ts b/packages/server-core/src/projects/project-invalidate/project-invalidate.hooks.ts index 629b0230fe..3d08d2208d 100644 --- a/packages/server-core/src/projects/project-invalidate/project-invalidate.hooks.ts +++ b/packages/server-core/src/projects/project-invalidate/project-invalidate.hooks.ts @@ -39,7 +39,7 @@ export default { update: [disallow()], patch: [ iff(isProvider('external'), verifyScope('projects', 'write')), - () => schemaHooks.validateData(projectInvalidatePatchValidator), + schemaHooks.validateData(projectInvalidatePatchValidator), schemaHooks.resolveData(projectInvalidatePatchResolver) ], remove: [disallow()] diff --git a/packages/server-core/src/projects/project-permission/project-permission.hooks.ts b/packages/server-core/src/projects/project-permission/project-permission.hooks.ts index 181f1d35bb..1f43656183 100644 --- a/packages/server-core/src/projects/project-permission/project-permission.hooks.ts +++ b/packages/server-core/src/projects/project-permission/project-permission.hooks.ts @@ -210,7 +210,7 @@ export default { before: { all: [ - () => schemaHooks.validateQuery(projectPermissionQueryValidator), + schemaHooks.validateQuery(projectPermissionQueryValidator), schemaHooks.resolveQuery(projectPermissionQueryResolver) ], find: [ @@ -222,7 +222,7 @@ export default { get: [], create: [ iff(isProvider('external'), verifyProjectOwner()), - () => schemaHooks.validateData(projectPermissionDataValidator), + schemaHooks.validateData(projectPermissionDataValidator), schemaHooks.resolveData(projectPermissionDataResolver), setLoggedInUserData('createdBy'), ensureInviteCode, @@ -231,7 +231,7 @@ export default { update: [disallow()], patch: [ iff(isProvider('external'), verifyProjectOwner()), - () => schemaHooks.validateData(projectPermissionPatchValidator), + schemaHooks.validateData(projectPermissionPatchValidator), schemaHooks.resolveData(projectPermissionPatchResolver), ensureTypeInPatch ], diff --git a/packages/server-core/src/projects/project/project-helper.ts b/packages/server-core/src/projects/project/project-helper.ts index c57a833fef..582cb5f201 100644 --- a/packages/server-core/src/projects/project/project-helper.ts +++ b/packages/server-core/src/projects/project/project-helper.ts @@ -42,7 +42,6 @@ import fetch from 'node-fetch' import path from 'path' import semver from 'semver' import { promisify } from 'util' -import { v4 as uuidv4 } from 'uuid' import { AssetType } from '@etherealengine/common/src/constants/AssetType' import { INSTALLATION_SIGNED_REGEX, PUBLIC_SIGNED_REGEX } from '@etherealengine/common/src/regex' @@ -1483,7 +1482,6 @@ export const updateProject = async ( ? // Add to DB await app.service(projectPath).create( { - id: uuidv4(), name: projectName, enabled, repositoryPath, @@ -1496,9 +1494,7 @@ export const updateProject = async ( updateUserId: userId || null, commitSHA, commitDate: toDateTimeSql(commitDate), - assetsOnly: assetsOnly, - createdAt: await getDateTimeSql(), - updatedAt: await getDateTimeSql() + assetsOnly }, params || {} ) diff --git a/packages/server-core/src/projects/project/project.hooks.ts b/packages/server-core/src/projects/project/project.hooks.ts index b3673f5f7b..869bbd0d7f 100644 --- a/packages/server-core/src/projects/project/project.hooks.ts +++ b/packages/server-core/src/projects/project/project.hooks.ts @@ -73,7 +73,6 @@ import verifyScope from '../../hooks/verify-scope' import { createExecutorJob } from '../../k8s-job-helper' import logger from '../../ServerLogger' import { useGit } from '../../util/gitHelperFunctions' -import { projectPermissionDataResolver } from '../project-permission/project-permission.resolvers' import { checkAppOrgStatus, checkUserOrgWriteStatus, checkUserRepoWriteStatus } from './github-helper' import { deleteProjectFilesInStorageProvider, @@ -428,15 +427,9 @@ const createProjectPermission = async (context: HookContext) => const result = (Array.isArray(context.result) ? context.result : [context.result]) as ProjectType[] if (context.params?.user?.id) { - const projectPermissionData = await projectPermissionDataResolver.resolve( - { - userId: context.params.user.id, - projectId: result[0].id, - type: 'owner' - }, - context as any - ) - return context.app.service(projectPermissionPath).create(projectPermissionData) + return context.app + .service(projectPermissionPath) + .create({ projectId: result[0].id, userId: context.params.user.id, type: 'owner' }) } return context } @@ -591,7 +584,7 @@ export default createSkippableHooks( }, before: { - all: [() => schemaHooks.validateQuery(projectQueryValidator), schemaHooks.resolveQuery(projectQueryResolver)], + all: [schemaHooks.validateQuery(projectQueryValidator), schemaHooks.resolveQuery(projectQueryResolver)], find: [ enableClientPagination(), iffElse(isAction('admin'), [], filterDisabledProjects), @@ -603,7 +596,7 @@ export default createSkippableHooks( get: [], create: [ iff(isProvider('external') && !isSignedByAppJWT(), verifyScope('editor', 'write')), - () => schemaHooks.validateData(projectDataValidator), + schemaHooks.validateData(projectDataValidator), schemaHooks.resolveData(projectDataResolver), discardQuery('action'), checkIfProjectExists, @@ -625,7 +618,7 @@ export default createSkippableHooks( verifyScope('editor', 'write'), projectPermissionAuthenticate(false) ), - () => schemaHooks.validateData(projectPatchValidator), + schemaHooks.validateData(projectPatchValidator), schemaHooks.resolveData(projectPatchResolver), iff(isProvider('external'), iffElse(checkEnabled, [], linkGithubToProject)) ], diff --git a/packages/server-core/src/projects/project/project.test.ts b/packages/server-core/src/projects/project/project.test.ts index 2851534c96..17f2fd275f 100644 --- a/packages/server-core/src/projects/project/project.test.ts +++ b/packages/server-core/src/projects/project/project.test.ts @@ -196,11 +196,10 @@ describe('project.test', () => { describe('patch', () => { it('should change the project data', async () => { - const randomUpdateType = `test-update-type-${Math.round(Math.random() * 1000)}` - const patchedProject = await app.service(projectPath).patch(testProject.id, { updateType: randomUpdateType }) + const patchedProject = await app.service(projectPath).patch(testProject.id, { updateType: 'tag' }) assert.equal(patchedProject.name, testProject.name) - assert.equal(patchedProject.updateType, randomUpdateType) + assert.equal(patchedProject.updateType, 'tag') }) })