🐛Restrict course level progress to course levels

This commit is contained in:
Matt Lott 2015-10-07 16:58:59 -07:00
parent 50f7391e76
commit 3eb450631a

View file

@ -1,5 +1,6 @@
async = require 'async' async = require 'async'
Handler = require '../commons/Handler' Handler = require '../commons/Handler'
Campaign = require '../campaigns/Campaign'
Course = require './Course' Course = require './Course'
CourseInstance = require './CourseInstance' CourseInstance = require './CourseInstance'
LevelSession = require '../levels/sessions/LevelSession' LevelSession = require '../levels/sessions/LevelSession'
@ -88,11 +89,19 @@ CourseInstanceHandler = class CourseInstanceHandler extends Handler
CourseInstance.findById courseInstanceID, (err, courseInstance) => CourseInstance.findById courseInstanceID, (err, courseInstance) =>
return @sendDatabaseError(res, err) if err return @sendDatabaseError(res, err) if err
return @sendNotFoundError(res) unless courseInstance return @sendNotFoundError(res) unless courseInstance
memberIDs = _.map courseInstance.get('members') ? [], (memberID) -> memberID.toHexString?() or memberID Course.findById courseInstance.get('courseID'), (err, course) =>
LevelSession.find {creator: {$in: memberIDs}}, (err, documents) => return @sendDatabaseError(res, err) if err
return @sendDatabaseError(res, err) if err? return @sendNotFoundError(res) unless course
cleandocs = (LevelSessionHandler.formatEntity(req, doc) for doc in documents) Campaign.findById course.get('campaignID'), (err, campaign) =>
@sendSuccess(res, cleandocs) return @sendDatabaseError(res, err) if err
return @sendNotFoundError(res) unless campaign
levelIDs = (levelID for levelID of campaign.get('levels'))
memberIDs = _.map courseInstance.get('members') ? [], (memberID) -> memberID.toHexString?() or memberID
query = {$and: [{creator: {$in: memberIDs}}, {'level.original': {$in: levelIDs}}]}
LevelSession.find query, (err, documents) =>
return @sendDatabaseError(res, err) if err?
cleandocs = (LevelSessionHandler.formatEntity(req, doc) for doc in documents)
@sendSuccess(res, cleandocs)
getMembersAPI: (req, res, courseInstanceID) -> getMembersAPI: (req, res, courseInstanceID) ->
CourseInstance.findById courseInstanceID, (err, courseInstance) => CourseInstance.findById courseInstanceID, (err, courseInstance) =>