| 102 | } |
| 103 | |
| 104 | function checkInfoValid(idName, info, infoFile, courseInfo, logger, cache) { |
| 105 | var myError = null; |
| 106 | |
| 107 | // check assessments all have a valid assessmentSet |
| 108 | if (idName == 'tid') { |
| 109 | let { validAssessmentSets } = cache; |
| 110 | if (!validAssessmentSets) { |
| 111 | validAssessmentSets = new Set(courseInfo.assessmentSets.map(as => as.name)); |
| 112 | cache.validAssessmentSets = validAssessmentSets; |
| 113 | } |
| 114 | if (courseInfo.assessmentSets && !validAssessmentSets.has(info.set)) { |
| 115 | return new Error(infoFile + ': invalid "set": "' + info.set + '" (must be a "name" of the "assessmentSets" listed in infoCourse.json)'); |
| 116 | } |
| 117 | // check assessment access rules |
| 118 | if (_(info).has('allowAccess')) { |
| 119 | _(info.allowAccess).forEach(function(rule) { |
| 120 | if ('startDate' in rule) { |
| 121 | var startDate = moment(rule.startDate, moment.ISO_8601); |
| 122 | if (startDate.isValid() == false) { |
| 123 | myError = new Error(`${infoFile}: invalid allowAccess startDate: ${rule.startDate}`); |
| 124 | return false; |
| 125 | } |
| 126 | } |
| 127 | if ('endDate' in rule) { |
| 128 | var endDate = moment(rule.endDate, moment.ISO_8601); |
| 129 | if (endDate.isValid() == false) { |
| 130 | myError = new Error(`${infoFile}: invalid allowAccess endDate: ${rule.startDate}`); |
| 131 | return false; |
| 132 | } |
| 133 | } |
| 134 | if ('startDate' in rule && 'endDate' in rule) { |
| 135 | if (startDate.isAfter(endDate)) { |
| 136 | myError = new Error(`${infoFile}: invalid allowAccess rule: startDate (${rule.startDate}) must not be after endDate (${rule.endDate})`); |
| 137 | return false; |
| 138 | } |
| 139 | } |
| 140 | }); |
| 141 | } |
| 142 | if (myError) { |
| 143 | return myError; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | // checks for infoCourseInstance.json |
| 148 | if (idName == 'ciid') { |
| 149 | if (_(info).has('allowIssueReporting')) { |
| 150 | if (info.allowIssueReporting) { |
| 151 | logger.warn(`WARNING: ${infoFile}: "allowIssueReporting" is no longer needed.`); |
| 152 | } else { |
| 153 | return new Error(`${infoFile}: "allowIssueReporting" is no longer permitted in "infoCourseInstance.json". Instead, set "allowIssueReporting" in "infoAssessment.json" files.`); |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | return null; |
| 159 | } |
| 160 | |
| 161 | function loadInfoDB(db, idName, parentDir, infoFilename, defaultInfo, schema, optionSchemaPrefix, courseInfo, logger, callback) { |