@@ -43,6 +43,7 @@ const updateProjectValdiations = {
43
43
name : Joi . string ( ) ,
44
44
description : Joi . string ( ) . allow ( null ) . allow ( '' ) . optional ( ) ,
45
45
billingAccountId : Joi . number ( ) . positive ( ) ,
46
+ directProjectId : Joi . number ( ) . positive ( ) . allow ( null ) ,
46
47
status : Joi . any ( ) . valid ( _ . values ( PROJECT_STATUS ) ) ,
47
48
estimatedPrice : Joi . number ( ) . precision ( 2 ) . positive ( ) . allow ( null ) ,
48
49
actualPrice : Joi . number ( ) . precision ( 2 ) . positive ( ) ,
@@ -79,7 +80,7 @@ const updateProjectValdiations = {
79
80
} ;
80
81
81
82
// NOTE- decided to disable all additional checks for now.
82
- const validateUpdates = ( existingProject ) => {
83
+ const validateUpdates = ( existingProject , updatedProps , authUser ) => {
83
84
const errors = [ ] ;
84
85
switch ( existingProject . status ) {
85
86
case PROJECT_STATUS . COMPLETED :
@@ -97,6 +98,12 @@ const validateUpdates = (existingProject) => {
97
98
// }
98
99
// }
99
100
}
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
+
100
107
return errors ;
101
108
} ;
102
109
@@ -113,8 +120,7 @@ module.exports = [
113
120
let updatedProps = req . body . param ;
114
121
const projectId = _ . parseInt ( req . params . projectId ) ;
115
122
// 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' ] ) ;
118
124
119
125
let previousValue ;
120
126
models . sequelize . transaction ( ( ) => models . Project . findOne ( {
@@ -133,7 +139,7 @@ module.exports = [
133
139
}
134
140
previousValue = _ . clone ( project . get ( { plain : true } ) ) ;
135
141
// run additional validations
136
- const validationErrors = validateUpdates ( previousValue , updatedProps ) ;
142
+ const validationErrors = validateUpdates ( previousValue , updatedProps , req . authUser ) ;
137
143
if ( validationErrors . length > 0 ) {
138
144
const err = new Error ( 'Unable to update project' ) ;
139
145
_ . assign ( err , {
0 commit comments