@@ -43,6 +43,7 @@ const updateProjectValdiations = {
4343 name : Joi . string ( ) ,
4444 description : Joi . string ( ) . allow ( null ) . allow ( '' ) . optional ( ) ,
4545 billingAccountId : Joi . number ( ) . positive ( ) ,
46+ directProjectId : Joi . number ( ) . positive ( ) . allow ( null ) ,
4647 status : Joi . any ( ) . valid ( _ . values ( PROJECT_STATUS ) ) ,
4748 estimatedPrice : Joi . number ( ) . precision ( 2 ) . positive ( ) . allow ( null ) ,
4849 actualPrice : Joi . number ( ) . precision ( 2 ) . positive ( ) ,
@@ -79,7 +80,7 @@ const updateProjectValdiations = {
7980} ;
8081
8182// NOTE- decided to disable all additional checks for now.
82- const validateUpdates = ( existingProject ) => {
83+ const validateUpdates = ( existingProject , updatedProps , authUser ) => {
8384 const errors = [ ] ;
8485 switch ( existingProject . status ) {
8586 case PROJECT_STATUS . COMPLETED :
@@ -97,6 +98,12 @@ const validateUpdates = (existingProject) => {
9798 // }
9899 // }
99100 }
101+ console . log ( _ . intersection ( authUser . roles , [ USER_ROLE . MANAGER , USER_ROLE . TOPCODER_ADMIN ] ) ) ;
102+ if ( _ . has ( updatedProps , 'directProjectId' ) &&
103+ _ . intersection ( authUser . roles , [ USER_ROLE . MANAGER , USER_ROLE . TOPCODER_ADMIN ] ) . length === 0 ) {
104+ errors . push ( 'Don\'t have permission to update \'directProjectId\' property' ) ;
105+ }
106+
100107 return errors ;
101108} ;
102109
@@ -113,8 +120,7 @@ module.exports = [
113120 let updatedProps = req . body . param ;
114121 const projectId = _ . parseInt ( req . params . projectId ) ;
115122 // prune any fields that cannot be updated directly
116- updatedProps = _ . omit ( updatedProps , [ 'createdBy' , 'createdAt' , 'updatedBy' , 'updatedAt' ,
117- 'id' , 'directProjectId' ] ) ;
123+ updatedProps = _ . omit ( updatedProps , [ 'createdBy' , 'createdAt' , 'updatedBy' , 'updatedAt' , 'id' ] ) ;
118124
119125 let previousValue ;
120126 models . sequelize . transaction ( ( ) => models . Project . findOne ( {
@@ -133,7 +139,7 @@ module.exports = [
133139 }
134140 previousValue = _ . clone ( project . get ( { plain : true } ) ) ;
135141 // run additional validations
136- const validationErrors = validateUpdates ( previousValue , updatedProps ) ;
142+ const validationErrors = validateUpdates ( previousValue , updatedProps , req . authUser ) ;
137143 if ( validationErrors . length > 0 ) {
138144 const err = new Error ( 'Unable to update project' ) ;
139145 _ . assign ( err , {
0 commit comments