Skip to content

Commit 765d3fa

Browse files
authored
Merge pull request #228 from cagdas001/dev
fix(interview-scheduler): fix interview permissions & mail feature
2 parents 14715c6 + 2a079f5 commit 765d3fa

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

src/common/helper.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1350,6 +1350,24 @@ function extractWorkPeriods (start, end) {
13501350
return periods
13511351
}
13521352

1353+
/**
1354+
* Returns the email address of specified (via handle) user.
1355+
*
1356+
* @param {String} userHandle user handle
1357+
* @returns {String} email address of the user
1358+
*/
1359+
async function getUserEmailByHandle (userHandle) {
1360+
const token = await getM2MToken()
1361+
const url = `${config.TC_API}/members/${userHandle}`
1362+
const res = await request
1363+
.get(url)
1364+
.set('Authorization', `Bearer ${token}`)
1365+
.set('Content-Type', 'application/json')
1366+
.set('Accept', 'application/json')
1367+
localLogger.debug({ context: 'getUserEmailByHandle', message: `response body: ${JSON.stringify(res.body)}` })
1368+
return _.get(res, 'body.email')
1369+
}
1370+
13531371
module.exports = {
13541372
getParamFromCliArgs,
13551373
promptUser,
@@ -1398,5 +1416,6 @@ module.exports = {
13981416
createChallenge,
13991417
updateChallenge,
14001418
createChallengeResource,
1401-
extractWorkPeriods
1419+
extractWorkPeriods,
1420+
getUserEmailByHandle
14021421
}

src/eventHandlers/InterviewEventHandler.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,19 @@ async function sendInvitationEmail (payload) {
1919

2020
// get job candidate user details
2121
const jobCandidate = await models.JobCandidate.findById(interview.jobCandidateId)
22-
const jobCandidateUser = await helper.getUserById(jobCandidate.userId, true)
22+
const jobCandidateUser = await helper.getUserById(jobCandidate.userId)
23+
const jobCandidateUserEmail = await helper.getUserEmailByHandle(jobCandidateUser.handle)
2324
// get customer details
2425
const job = await jobCandidate.getJob()
25-
const interviewerList = interview.attendeesList
2626

2727
teamService.sendEmail({}, {
2828
template: 'interview-invitation',
29-
cc: interview.attendeesList,
29+
cc: [jobCandidateUserEmail, ...interview.attendeesList],
3030
data: {
3131
interviewType: interview.xaiTemplate,
3232
interviewRound: interview.round,
3333
interviewDuration: Interviews.XaiTemplate[interview.xaiTemplate],
34+
interviewerList: interview.attendeesList,
3435
jobName: job.title,
3536
candidateName: `${jobCandidateUser.firstName} ${jobCandidateUser.lastName}`,
3637
candidateId: interview.jobCandidateId

src/services/InterviewService.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
5961
async 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
*/
114116
async 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
*/
169171
async 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
*/
235237
async 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

Comments
 (0)