@@ -20,12 +20,14 @@ const esClient = helper.getESClient()
2020 * Ensures user is permitted for the operation.
2121 *
2222 * @param {Object } currentUser the user who perform this operation.
23+ * @param {String } jobCandidateId the job candidate id
2324 * @throws {errors.ForbiddenError }
2425 */
25- function ensureUserIsPermitted ( currentUser ) {
26- const isUserPermitted = currentUser . hasManagePermission || currentUser . isMachine
27- if ( isUserPermitted !== true ) {
28- throw new errors . ForbiddenError ( 'You are not allowed to perform this action!' )
26+ async function ensureUserIsPermitted ( currentUser , jobCandidateId ) {
27+ if ( ! currentUser . hasManagePermission && ! currentUser . isMachine ) {
28+ const jobCandidate = await models . JobCandidate . findById ( jobCandidateId )
29+ const job = jobCandidate . getJob ( )
30+ await helper . checkIsMemberOfProject ( currentUser . userId , job . projectId )
2931 }
3032}
3133
@@ -58,7 +60,7 @@ function handleSequelizeError (err, jobCandidateId) {
5860 */
5961async function getInterviewByRound ( currentUser , jobCandidateId , round , fromDb = false ) {
6062 // check permission
61- ensureUserIsPermitted ( currentUser )
63+ await ensureUserIsPermitted ( currentUser , jobCandidateId )
6264 if ( ! fromDb ) {
6365 try {
6466 // get job candidate from ES
@@ -113,7 +115,7 @@ getInterviewByRound.schema = Joi.object().keys({
113115 */
114116async function requestInterview ( currentUser , jobCandidateId , interview ) {
115117 // check permission
116- ensureUserIsPermitted ( currentUser )
118+ await ensureUserIsPermitted ( currentUser , jobCandidateId )
117119
118120 interview . id = uuid ( )
119121 interview . jobCandidateId = jobCandidateId
@@ -168,7 +170,7 @@ requestInterview.schema = Joi.object().keys({
168170 */
169171async function partiallyUpdateInterview ( currentUser , jobCandidateId , round , data ) {
170172 // check permission
171- ensureUserIsPermitted ( currentUser )
173+ await ensureUserIsPermitted ( currentUser , jobCandidateId )
172174
173175 const interview = await Interview . findOne ( {
174176 where : {
@@ -234,7 +236,7 @@ partiallyUpdateInterview.schema = Joi.object().keys({
234236 */
235237async function searchInterviews ( currentUser , jobCandidateId , criteria ) {
236238 // check permission
237- ensureUserIsPermitted ( currentUser )
239+ await ensureUserIsPermitted ( currentUser , jobCandidateId )
238240
239241 const { page, perPage } = criteria
240242
0 commit comments