Skip to content

Commit

Permalink
Aftral[premieroctet#75]: changed homeworks to not depend of max attem…
Browse files Browse the repository at this point in the history
…pts, and max attempts only if resource type is SCORM
  • Loading branch information
SeghirOumo committed Sep 5, 2024
1 parent e09da5f commit 083f8a8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
9 changes: 8 additions & 1 deletion backend/web/server/plugins/aftral-lms/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const mongoose=require('mongoose')
const Block = require('../../models/Block')
const { ForbiddenError, NotFoundError, BadRequestError } = require('../../utils/errors')
const {addAction, setAllowActionFn}=require('../../utils/studio/actions')
const { BLOCK_TYPE, ROLE_CONCEPTEUR, ROLE_FORMATEUR, ROLES, BLOCK_STATUS_FINISHED, BLOCK_STATUS_CURRENT, BLOCK_STATUS_TO_COME, BLOCK_STATUS_UNAVAILABLE, ROLE_ADMINISTRATEUR } = require('./consts')
const { BLOCK_TYPE, ROLE_CONCEPTEUR, ROLE_FORMATEUR, ROLES, BLOCK_STATUS_FINISHED, BLOCK_STATUS_CURRENT, BLOCK_STATUS_TO_COME, BLOCK_STATUS_UNAVAILABLE, ROLE_ADMINISTRATEUR, RESOURCE_TYPE_SCORM } = require('./consts')
const { cloneTree, onBlockFinished, getNextResource, getPreviousResource, getParentBlocks, getSession } = require('./block')
const { lockSession } = require('./functions')
const Progress = require('../../models/Progress')
Expand Down Expand Up @@ -145,6 +145,13 @@ const isActionAllowed = async ({ action, dataId, user }) => {
}
const actionFn={'play': canPlay, 'resume': canResume, 'replay': canReplay}[action]
if (actionFn) {
// const block = await Block.findById(dataId, {resource_type: 1, max_attempts: 1})
//if(block.max_attempts && block.resource_type == RESOURCE_TYPE_SCORM) {
// const progress = await Progress.findOne({block: dataId, user}, {attempts_count: 1})
// if (progress.attempts_count >= block.max_attempts) {
// throw new ForbiddenError(`Vous avez atteint le nombre limite de tentatives`)
// }
//}
return actionFn({action, dataId, user})
}
if (action=='next') {
Expand Down
12 changes: 9 additions & 3 deletions backend/web/server/plugins/aftral-lms/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const {
declareVirtualField, setPreCreateData, setPreprocessGet, setMaxPopulateDepth, setFilterDataUser, declareComputedField, declareEnumField, idEqual, getModel, declareFieldDependencies, setPostPutData, setPreDeleteData, setPrePutData, loadFromDb,
setPostCreateData,
} = require('../../utils/database')
const { RESOURCE_TYPE, PROGRAM_STATUS, ROLES, MAX_POPULATE_DEPTH, BLOCK_STATUS, ROLE_CONCEPTEUR, ROLE_FORMATEUR,ROLE_APPRENANT, FEED_TYPE_GENERAL, FEED_TYPE_SESSION, FEED_TYPE_GROUP, FEED_TYPE, ACHIEVEMENT_RULE, SCALE, RESOURCE_TYPE_LINK, DEFAULT_ACHIEVEMENT_RULE, BLOCK_STATUS_TO_COME, BLOCK_STATUS_CURRENT, TICKET_STATUS, TICKET_TAG, PERMISSIONS, ROLE_HELPDESK } = require('./consts')
const { RESOURCE_TYPE, PROGRAM_STATUS, ROLES, MAX_POPULATE_DEPTH, BLOCK_STATUS, ROLE_CONCEPTEUR, ROLE_FORMATEUR,ROLE_APPRENANT, FEED_TYPE_GENERAL, FEED_TYPE_SESSION, FEED_TYPE_GROUP, FEED_TYPE, ACHIEVEMENT_RULE, SCALE, RESOURCE_TYPE_LINK, DEFAULT_ACHIEVEMENT_RULE, BLOCK_STATUS_TO_COME, BLOCK_STATUS_CURRENT, TICKET_STATUS, TICKET_TAG, PERMISSIONS, ROLE_HELPDESK, RESOURCE_TYPE_SCORM } = require('./consts')
const mongoose = require('mongoose')
require('../../models/Resource')
const Session = require('../../models/Session')
Expand Down Expand Up @@ -230,6 +230,9 @@ const preCreate = async ({model, params, user}) => {
params.trainee=user
}
if (model=='resource') {
if (params.max_attempts && params.resource_type != RESOURCE_TYPE_SCORM) {
throw new Error(`Vous ne pouvez pas mettre de nombre de tentatives maximum sur une ressource autre qu'un SCORM`)
}
if (!params.url && !params.plain_url) {
throw new Error(`Vous devez télécharger un fichier ou saisir une URL`)
}
Expand Down Expand Up @@ -296,7 +299,7 @@ const preCreate = async ({model, params, user}) => {
if (model == `homework` ){
const [block] = await loadFromDb({model: `resource`, id: params.parent, user, fields:[`can_upload_homework`]})
if(!block.can_upload_homework) {
throw new ForbiddenError(`Vous avez atteint la limite de tentatives`)
throw new ForbiddenError(`Vous ne pouvez plus importer de devoir`)
}
}
return Promise.resolve({model, params})
Expand Down Expand Up @@ -489,7 +492,10 @@ const preprocessGet = async ({model, fields, id, user, params}) => {
if (block._locked && user.role==ROLE_APPRENANT) {
await Progress.findOneAndUpdate(
{block, user},
{block, user, consult: true, consult_partial: true, join_partial: true, download: true, $inc: { attempts_count: 1 }},
{block, user, consult: true, consult_partial: true, join_partial: true, download: true,
//if scorm, increment attempts count
...block.resource_type == RESOURCE_TYPE_SCORM ? {$inc: { attempts_count: 1 }} : {}
},
{upsert: true},
)
await onBlockAction(user, block)
Expand Down
7 changes: 1 addition & 6 deletions backend/web/tests/aftral-lms/block.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ describe('User', () => {
homeworks:[homework1._id],
achievement_status: BLOCK_STATUS_FINISHED,
note: 10,
attempts_count: 10,
})
let result = await loadFromDb({model:`block`,user:trainee1._id, id:res._id, fields:[`can_upload_homework`]})
expect(result[0].can_upload_homework).not.toBeTruthy()
Expand All @@ -356,11 +355,7 @@ describe('User', () => {
result = await loadFromDb({model:`block`,user:trainee1._id, id:res._id, fields:[`can_upload_homework`]})
expect(result[0].can_upload_homework).toBeTruthy()

await Block.findByIdAndUpdate(res._id, {max_attempts: 10})
result = await loadFromDb({model:`block`,user:trainee1._id, id:res._id, fields:[`can_upload_homework`]})
expect(result[0].can_upload_homework).not.toBeTruthy()

await Block.findByIdAndUpdate(res._id, {max_attempts: 20, homework_limit_date: new Date(`02-02-2022`)})
await Block.findByIdAndUpdate(res._id, {homework_limit_date: new Date(`02-02-2022`)})
result = await loadFromDb({model:`block`,user:trainee1._id, id:res._id, fields:[`can_upload_homework`]})
expect(result[0].can_upload_homework).not.toBeTruthy()
})
Expand Down

0 comments on commit 083f8a8

Please sign in to comment.