Skip to content

Commit 2ba0e34

Browse files
authored
Merge pull request #547 from UniversityOfHelsinkiCS/trunk
Continue #546
2 parents a6d961e + 97e4956 commit 2ba0e34

File tree

4 files changed

+38
-19
lines changed

4 files changed

+38
-19
lines changed

backend/server/controllers/courseinstances.js

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ const Checklist = require('../models').Checklist
1515
const env = process.env.NODE_ENV || 'development'
1616
const config = require('./../config/config.js')[env]
1717

18+
const overkillLogging = (req, error) => {
19+
console.log('request: ', req)
20+
console.log('error: ', error)
21+
}
22+
1823
module.exports = {
1924
/**
2025
*
@@ -265,36 +270,38 @@ module.exports = {
265270
}
266271
})
267272
if (!course) {
273+
overkillLogging(req, null)
268274
return res.status(400).send({
269275
message: 'course instance not found'
270276
})
271-
} else if (course.active === false) {
272-
console.log('course is no active')
277+
}
278+
if (course.active === false) {
279+
console.log('course is not active')
280+
overkillLogging(req, null)
273281
return res.status(400).send({
274282
message: 'course is not active'
275283
})
276284
}
277285
const user = await User.findById(req.decoded.id)
278286
if (!user) {
287+
overkillLogging(req, null)
279288
return res.status(400).send({
280-
message: 'something went wrong (clear these specific error messages later): user not found'
289+
message: 'User could not be found.'
281290
})
282291
}
283-
const webOodiStatus = await new Promise((resolve, reject) => {
292+
const webOodiStatus = await new Promise((resolve) => {
284293
helper.checkWebOodi(req, res, user, resolve) // this does not work.
285294

286295
setTimeout(function() {
296+
overkillLogging(req, null)
287297
resolve('shitaintright') // Yay! everything went to hell.
288298
}, 5000) // set a high timeout value since you really want to wait x)
289299
})
290300

291301
if (webOodiStatus !== 'found') {
292-
// Temporarily allow non-registered users past until issue with registered users being blocked is resolved.
293-
console.warn(`Expected user to be found in Kurki students. status - expected: found, actual: ${webOodiStatus}`)
294-
console.warn(`The following user was not found to have been registered in weboodi to course ${req.params.ohid}. Proceeding anyway.`, user)
295-
} else {
296-
res.status(400).send({
297-
message: 'something went wrong'
302+
overkillLogging(req, null)
303+
return res.status(403).json({
304+
message: 'You have not yet registered to this course at WebOodi. If you have already registered at WebOodi, try again in two hours.'
298305
})
299306
}
300307
let student
@@ -312,14 +319,26 @@ module.exports = {
312319
projectName: req.body.projectName || '' // model would like to validate this to alphanumeric but seems like this needs specific nulls or empties or whatever
313320
}
314321
})
315-
} catch (e) {
316-
res.status(400).send({
317-
message: error.errors
322+
} catch (error) {
323+
if (error.name === 'SequelizeValidationError') {
324+
const validationErrorMessages = {
325+
github: 'Github repository link is not a proper url.',
326+
projectName: 'Project name contains illegal characters.'
327+
}
328+
const errorMessage = error.errors.map(e => validationErrorMessages[e.path] || 'Unknown validation error.')
329+
return res.status(400).json({
330+
message: errorMessage.join('\n')
331+
})
332+
}
333+
overkillLogging(req, error)
334+
return res.status(500).json({
335+
message: 'Unexpected error.'
318336
})
319337
}
320338
if (!student) {
321-
res.status(400).send({
322-
message: 'something went wrong: if somehow we could not find or create a record we see this'
339+
overkillLogging(req, null)
340+
res.status(400).json({
341+
message: 'Student record could not be found or created.'
323342
})
324343
} else {
325344
helper.findByUserStudentInstance(req, res)

backend/server/helpers/course_instance_helper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ function checkWebOodi(req, res, user, resolve) {
4646
return
4747
} else {
4848
console.log('\ncourse_instance_helper notfound')
49-
console.info(json.students)
50-
console.info(user.studentNumber)
49+
console.info(json)
50+
console.info('studentNumber:', user.studentNumber)
5151
resolve('notfound')
5252
return
5353
}

backend/server/models/studentinstance.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = (sequelize, DataTypes) => {
1313
type: DataTypes.STRING,
1414
allowNull: false,
1515
validate: {
16-
is: ["^[a-zåäöA-ZÅÄÖ'0-9_ ]*$"]
16+
is: ['^[a-zåäöA-ZÅÄÖ\'\\-0-9]*$']
1717
}
1818
}
1919
},

labtool2.0/src/reducers/notificationReducer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const notificationReducer = (state = {}, action) => {
4545
}
4646
case 'STUDENT_COURSE_CREATE_ONE_FAILURE':
4747
return {
48-
message: 'You have not yet registered to this course at WebOodi. If you have already registered at WebOodi, try again in two hours.',
48+
message: action.response.response.data.message,
4949
error: true
5050
}
5151
case 'CI_MODIFY_ONE_SUCCESS':

0 commit comments

Comments
 (0)