Skip to content

Commit

Permalink
Aftral: [premieroctet#155] Enforce program code for production status
Browse files Browse the repository at this point in the history
  • Loading branch information
sebaauvray committed Sep 20, 2024
1 parent 850c2d2 commit 657e9cb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion backend/web/server/plugins/aftral-lms/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
10 changes: 5 additions & 5 deletions backend/web/server/plugins/aftral-lms/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 657e9cb

Please sign in to comment.