Merge branch 'master' into production

This commit is contained in:
Nick Winter 2016-07-15 13:28:47 -07:00
commit 8a074b7777
5 changed files with 21 additions and 8 deletions

View file

@ -22,6 +22,7 @@ before_install:
- npm install -g npm@latest - npm install -g npm@latest
before_script: before_script:
- npm update
- export DISPLAY=:99.0 - export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start - sh -e /etc/init.d/xvfb start
- "node index.js --unittest &" - "node index.js --unittest &"

View file

@ -11,6 +11,7 @@ _.extend CourseSchema.properties,
pricePerSeat: {type: 'number', description: 'Price per seat in USD cents.'} # deprecated pricePerSeat: {type: 'number', description: 'Price per seat in USD cents.'} # deprecated
free: { type: 'boolean' } free: { type: 'boolean' }
screenshot: c.url {title: 'URL', description: 'Link to course screenshot.'} screenshot: c.url {title: 'URL', description: 'Link to course screenshot.'}
adminOnly: {type: 'boolean', description: 'Whether the course is in admin-only testing mode still and will not show up for normal users.'}
c.extendBasicProperties CourseSchema, 'Course' c.extendBasicProperties CourseSchema, 'Course'

View file

@ -140,9 +140,11 @@ module.exports =
classroom.set 'ownerID', req.user._id classroom.set 'ownerID', req.user._id
classroom.set 'members', [] classroom.set 'members', []
database.assignBody(req, classroom) database.assignBody(req, classroom)
# Copy over data from how courses are right now # Copy over data from how courses are right now
courses = yield Course.find() query = {}
query = {adminOnly: {$ne: true}} unless req.user?.isAdmin()
courses = yield Course.find(query)
campaigns = yield Campaign.find({_id: {$in: (course.get('campaignID') for course in courses)}}) campaigns = yield Campaign.find({_id: {$in: (course.get('campaignID') for course in courses)}})
campaignMap = {} campaignMap = {}
campaignMap[campaign.id] = campaign for campaign in campaigns campaignMap[campaign.id] = campaign for campaign in campaigns

View file

@ -34,18 +34,27 @@ module.exports =
foundLevelOriginal = true foundLevelOriginal = true
nextLevelOriginal = levels[index+1]?.original nextLevelOriginal = levels[index+1]?.original
break break
if not foundLevelOriginal if not foundLevelOriginal
throw new errors.NotFound('Level original ObjectId not found in that course') throw new errors.NotFound('Level original ObjectId not found in that course')
if not nextLevelOriginal if not nextLevelOriginal
return res.status(200).send({}) return res.status(200).send({})
dbq = Level.findOne({original: mongoose.Types.ObjectId(nextLevelOriginal)}) dbq = Level.findOne({original: mongoose.Types.ObjectId(nextLevelOriginal)})
dbq.sort({ 'version.major': -1, 'version.minor': -1 }) dbq.sort({ 'version.major': -1, 'version.minor': -1 })
dbq.select(parse.getProjectFromReq(req)) dbq.select(parse.getProjectFromReq(req))
level = yield dbq level = yield dbq
level = level.toObject({req: req}) level = level.toObject({req: req})
res.status(200).send(level) res.status(200).send(level)
get: (Model, options={}) -> wrap (req, res) ->
# Don't use standard rest middleware get, because we want to filter out adminOnly courses for non-admins
query = {}
query = {adminOnly: {$ne: true}} unless req.user?.isAdmin()
dbq = Model.find(query)
dbq.select(parse.getProjectFromReq(req))
results = yield database.viewSearch(dbq, req)
res.send(results)

View file

@ -79,7 +79,7 @@ module.exports.setup = (app) ->
app.get('/db/codelogs', mw.auth.checkHasPermission(['admin']), mw.rest.get(CodeLog)) app.get('/db/codelogs', mw.auth.checkHasPermission(['admin']), mw.rest.get(CodeLog))
Course = require '../models/Course' Course = require '../models/Course'
app.get('/db/course', mw.rest.get(Course)) app.get('/db/course', mw.courses.get(Course))
app.get('/db/course/:handle', mw.rest.getByHandle(Course)) app.get('/db/course/:handle', mw.rest.getByHandle(Course))
app.get('/db/course/:handle/levels/:levelOriginal/next', mw.courses.fetchNextLevel) app.get('/db/course/:handle/levels/:levelOriginal/next', mw.courses.fetchNextLevel)