Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
IR: 2908: Re-evaluate feathers validator usage for projects services (#…
Browse files Browse the repository at this point in the history
…10518)

      * fixed project services validators

* chore: Update project helper to include assetsOnly parameter
  • Loading branch information
MoizAdnan authored Jul 9, 2024
1 parent 116ff63 commit e327037
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export default {

before: {
all: [
() => schemaHooks.validateQuery(projectPermissionQueryValidator),
schemaHooks.validateQuery(projectPermissionQueryValidator),
schemaHooks.resolveQuery(projectPermissionQueryResolver)
],
find: [
Expand All @@ -222,7 +222,7 @@ export default {
get: [],
create: [
iff(isProvider('external'), verifyProjectOwner()),
() => schemaHooks.validateData(projectPermissionDataValidator),
schemaHooks.validateData(projectPermissionDataValidator),
schemaHooks.resolveData(projectPermissionDataResolver),
setLoggedInUserData('createdBy'),
ensureInviteCode,
Expand All @@ -231,7 +231,7 @@ export default {
update: [disallow()],
patch: [
iff(isProvider('external'), verifyProjectOwner()),
() => schemaHooks.validateData(projectPermissionPatchValidator),
schemaHooks.validateData(projectPermissionPatchValidator),
schemaHooks.resolveData(projectPermissionPatchResolver),
ensureTypeInPatch
],
Expand Down
6 changes: 1 addition & 5 deletions packages/server-core/src/projects/project/project-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -1483,7 +1482,6 @@ export const updateProject = async (
? // Add to DB
await app.service(projectPath).create(
{
id: uuidv4(),
name: projectName,
enabled,
repositoryPath,
Expand All @@ -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 || {}
)
Expand Down
19 changes: 6 additions & 13 deletions packages/server-core/src/projects/project/project.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -428,15 +427,9 @@ const createProjectPermission = async (context: HookContext<ProjectService>) =>
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
}
Expand Down Expand Up @@ -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),
Expand All @@ -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,
Expand All @@ -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))
],
Expand Down
5 changes: 2 additions & 3 deletions packages/server-core/src/projects/project/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})

Expand Down

0 comments on commit e327037

Please sign in to comment.