@@ -20,12 +20,14 @@ const esClient = helper.getESClient()
20
20
* Ensures user is permitted for the operation.
21
21
*
22
22
* @param {Object } currentUser the user who perform this operation.
23
+ * @param {String } jobCandidateId the job candidate id
23
24
* @throws {errors.ForbiddenError }
24
25
*/
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 )
29
31
}
30
32
}
31
33
@@ -58,7 +60,7 @@ function handleSequelizeError (err, jobCandidateId) {
58
60
*/
59
61
async function getInterviewByRound ( currentUser , jobCandidateId , round , fromDb = false ) {
60
62
// check permission
61
- ensureUserIsPermitted ( currentUser )
63
+ await ensureUserIsPermitted ( currentUser , jobCandidateId )
62
64
if ( ! fromDb ) {
63
65
try {
64
66
// get job candidate from ES
@@ -113,7 +115,7 @@ getInterviewByRound.schema = Joi.object().keys({
113
115
*/
114
116
async function requestInterview ( currentUser , jobCandidateId , interview ) {
115
117
// check permission
116
- ensureUserIsPermitted ( currentUser )
118
+ await ensureUserIsPermitted ( currentUser , jobCandidateId )
117
119
118
120
interview . id = uuid ( )
119
121
interview . jobCandidateId = jobCandidateId
@@ -168,7 +170,7 @@ requestInterview.schema = Joi.object().keys({
168
170
*/
169
171
async function partiallyUpdateInterview ( currentUser , jobCandidateId , round , data ) {
170
172
// check permission
171
- ensureUserIsPermitted ( currentUser )
173
+ await ensureUserIsPermitted ( currentUser , jobCandidateId )
172
174
173
175
const interview = await Interview . findOne ( {
174
176
where : {
@@ -234,7 +236,7 @@ partiallyUpdateInterview.schema = Joi.object().keys({
234
236
*/
235
237
async function searchInterviews ( currentUser , jobCandidateId , criteria ) {
236
238
// check permission
237
- ensureUserIsPermitted ( currentUser )
239
+ await ensureUserIsPermitted ( currentUser , jobCandidateId )
238
240
239
241
const { page, perPage } = criteria
240
242
0 commit comments