diff --git a/backend/web/server/plugins/aftral-lms/actions.js b/backend/web/server/plugins/aftral-lms/actions.js index e868000dbf..f1a6c16a57 100644 --- a/backend/web/server/plugins/aftral-lms/actions.js +++ b/backend/web/server/plugins/aftral-lms/actions.js @@ -124,6 +124,9 @@ addAction('session', getSessionAction) // TODO dev only if (!isProduction()) { const forceFinishResource = async ({value, dataId}, user) => { + if([ROLE_HELPDESK, ROLE_FORMATEUR].includes(user.role) && dataId) { + user = await User.findById(dataId) + } await Progress.findOneAndUpdate( {user, block: value._id}, {user, block: value._id, achievement_status: BLOCK_STATUS_FINISHED}, diff --git a/backend/web/tests/aftral-lms/block.test.js b/backend/web/tests/aftral-lms/block.test.js index f261a3df51..fbb6010809 100644 --- a/backend/web/tests/aftral-lms/block.test.js +++ b/backend/web/tests/aftral-lms/block.test.js @@ -294,7 +294,7 @@ describe('User', () => { //Had to copy paste from aftral-lms/actions.js const forceFinishResource = async ({value, dataId}, user) => { - if(user.role == ROLE_HELPDESK && dataId) { + if([ROLE_HELPDESK, ROLE_FORMATEUR].includes(user.role) && dataId) { user = await User.findById(dataId) } await Progress.findOneAndUpdate( @@ -317,5 +317,14 @@ describe('User', () => { await forceFinishResource({value:resource, dataId:trainee2._id}, helpdesk) prog = await Progress.findOne({user:trainee2._id}) expect(prog.achievement_status == BLOCK_STATUS_FINISHED).toBeTruthy() + + await Progress.findOneAndUpdate( + {user: trainee2, block: resource._id}, + {user: trainee2, block: resource._id, achievement_status: BLOCK_STATUS_CURRENT}, + ) + + await forceFinishResource({value:resource, dataId:trainee2._id}, trainer) + prog = await Progress.findOne({user:trainee2._id}) + expect(prog.achievement_status == BLOCK_STATUS_FINISHED).toBeTruthy() }) }) \ No newline at end of file