diff --git a/backend/web/server/plugins/aftral-lms/consts.js b/backend/web/server/plugins/aftral-lms/consts.js index 44f6f39154..8441a652c2 100644 --- a/backend/web/server/plugins/aftral-lms/consts.js +++ b/backend/web/server/plugins/aftral-lms/consts.js @@ -217,5 +217,5 @@ module.exports={ ACHIEVEMENT_RULE, ACHIEVEMENT_RULE_SUCCESS, ACHIEVEMENT_RULE_CONSULT, ACHIEVEMENT_RULE_DOWNLOAD, SCALE, RESOURCE_TYPE_EXT, RESOURCE_TYPE_LINK, DEFAULT_ACHIEVEMENT_RULE, AVAILABLE_ACHIEVEMENT_RULES, ACHIEVEMENT_RULE_CHECK, DURATION_UNIT, TICKET_TAG, TICKET_STATUS, TICKET_STATUS_NOT_TREATED, - PERMISSIONS, SCALE_NOT_ACQUIRED, RESOURCE_TYPE_FOLDER, + PERMISSIONS, SCALE_NOT_ACQUIRED, RESOURCE_TYPE_FOLDER,PROGRAM_STATUS_AVAILABLE, } \ No newline at end of file diff --git a/backend/web/server/plugins/aftral-lms/functions.js b/backend/web/server/plugins/aftral-lms/functions.js index 3e1eaffe66..549eee08bb 100644 --- a/backend/web/server/plugins/aftral-lms/functions.js +++ b/backend/web/server/plugins/aftral-lms/functions.js @@ -349,11 +349,11 @@ const prePut = async ({model, id, params, user, skip_validation}) => { )} } - if(model == `program`) { - const program = await Program.findById(id) - params.codes = program.codes - params.duration_unit = program.duration_unit - } + // if(model == `program`) { + // const program = await Program.findById(id) + // params.codes = program.codes + // params.duration_unit = program.duration_unit + // } if (model == `group`){ if(params.sessions) { diff --git a/backend/web/server/plugins/aftral-lms/schemas/ProgramSchema.js b/backend/web/server/plugins/aftral-lms/schemas/ProgramSchema.js index 0f1f9a9109..b46d8e5c03 100644 --- a/backend/web/server/plugins/aftral-lms/schemas/ProgramSchema.js +++ b/backend/web/server/plugins/aftral-lms/schemas/ProgramSchema.js @@ -2,7 +2,8 @@ const mongoose = require('mongoose') const lodash = require('lodash') const {schemaOptions} = require('../../../utils/schemas') const Schema = mongoose.Schema -const {BLOCK_DISCRIMINATOR, PROGRAM_STATUS, PROGRAM_STATUS_DRAFT, DURATION_UNIT}=require('../consts') +const {BLOCK_DISCRIMINATOR, PROGRAM_STATUS, PROGRAM_STATUS_DRAFT, DURATION_UNIT, PROGRAM_STATUS_AVAILABLE}=require('../consts') +const { BadRequestError } = require('../../../utils/errors') const ProgramSchema = new Schema({ status: { @@ -44,6 +45,10 @@ ProgramSchema.pre('validate', function(next) { if (!!this.origin) { return next() } + //#155 Enforce code for production program + if (this.status==PROGRAM_STATUS_AVAILABLE && lodash.isEmpty(this.codes)) { + return next(new BadRequestError(`Un code est requis pour passer en production`)) + } //#155 If the program has code(s), check it's not already used if (!this._locked && !this.origin && !lodash.isEmpty(this.codes)) { return mongoose.models['program'].findOne(