codecombat/server/routes/index.coffee

111 lines
5.8 KiB
CoffeeScript
Raw Normal View History

2015-12-16 20:09:22 -05:00
mw = require '../middleware'
2015-12-14 14:10:37 -05:00
module.exports.setup = (app) ->
passport = require('passport')
app.post('/auth/login', passport.authenticate('local'), mw.auth.afterLogin)
app.post('/auth/login-facebook', mw.auth.loginByFacebook, mw.auth.afterLogin)
app.post('/auth/login-gplus', mw.auth.loginByGPlus, mw.auth.afterLogin)
app.post('/auth/logout', mw.auth.logout)
app.get('/auth/name/?(:name)?', mw.auth.name)
app.post('/auth/reset', mw.auth.reset)
app.post('/auth/spy', mw.auth.spy)
app.post('/auth/stop-spying', mw.auth.stopSpying)
app.get('/auth/unsubscribe', mw.auth.unsubscribe)
app.get('/auth/whoami', mw.auth.whoAmI)
2016-04-11 14:59:51 -04:00
Achievement = require '../models/Achievement'
app.get('/db/achievement', mw.achievements.fetchByRelated, mw.rest.get(Achievement))
app.post('/db/achievement', mw.auth.checkHasPermission(['admin', 'artisan']), mw.rest.post(Achievement))
app.get('/db/achievement/:handle', mw.rest.getByHandle(Achievement))
app.put('/db/achievement/:handle', mw.auth.checkLoggedIn(), mw.achievements.put)
app.delete('/db/achievement/:handle', mw.auth.checkHasPermission(['admin', 'artisan']), mw.rest.delete(Achievement))
app.get('/db/achievement/names', mw.named.names(Achievement))
app.get('/db/achievement/:handle/patches', mw.patchable.patches(Achievement))
app.post('/db/achievement/:handle/watchers', mw.patchable.joinWatchers(Achievement))
app.delete('/db/achievement/:handle/watchers', mw.patchable.leaveWatchers(Achievement))
2015-12-16 20:09:22 -05:00
Article = require '../models/Article'
app.get('/db/article', mw.rest.get(Article))
app.post('/db/article', mw.auth.checkHasPermission(['admin', 'artisan']), mw.rest.post(Article))
app.get('/db/article/names', mw.named.names(Article))
app.post('/db/article/names', mw.named.names(Article))
app.get('/db/article/:handle', mw.rest.getByHandle(Article))
app.put('/db/article/:handle', mw.auth.checkHasPermission(['admin']), mw.rest.put(Article))
app.patch('/db/article/:handle', mw.auth.checkHasPermission(['admin']), mw.rest.put(Article))
app.post('/db/article/:handle/new-version', mw.auth.checkLoggedIn(), mw.versions.postNewVersion(Article, { hasPermissionsOrTranslations: 'artisan' }))
app.get('/db/article/:handle/versions', mw.versions.versions(Article))
app.get('/db/article/:handle/version/?(:version)?', mw.versions.getLatestVersion(Article))
app.get('/db/article/:handle/files', mw.files.files(Article, {module: 'article'}))
app.get('/db/article/:handle/patches', mw.patchable.patches(Article))
app.post('/db/article/:handle/watchers', mw.patchable.joinWatchers(Article))
app.delete('/db/article/:handle/watchers', mw.patchable.leaveWatchers(Article))
app.get('/db/campaign', mw.campaigns.fetchByType)
app.put('/db/campaign/:handle', mw.campaigns.put)
app.post('/db/classroom', mw.classrooms.post)
2016-03-30 16:57:19 -04:00
app.get('/db/classroom', mw.classrooms.getByOwner)
2016-04-13 12:54:24 -04:00
app.get('/db/classroom/:handle/levels', mw.classrooms.fetchAllLevels)
app.get('/db/classroom/:handle/courses/:courseID/levels', mw.classrooms.fetchLevelsForCourse)
2016-03-30 16:57:19 -04:00
app.get('/db/classroom/:handle/member-sessions', mw.classrooms.fetchMemberSessions)
app.get('/db/classroom/:handle/members', mw.classrooms.fetchMembers) # TODO: Use mw.auth?
app.get('/db/classroom/:handle', mw.auth.checkLoggedIn()) # TODO: Finish migrating route, adding now so 401 is returned
CodeLog = require ('../models/CodeLog')
app.post('/db/codelogs', mw.auth.checkHasUser(), mw.codelogs.post)
app.get('/db/codelogs', mw.auth.checkHasPermission(['admin']), mw.rest.get(CodeLog))
2016-03-30 16:57:19 -04:00
Course = require '../models/Course'
app.get('/db/course', mw.rest.get(Course))
app.get('/db/course/:handle', mw.rest.getByHandle(Course))
2016-04-13 12:54:24 -04:00
app.get('/db/course_instance/:handle/levels/:levelOriginal/next', mw.courseInstances.fetchNextLevel)
2016-03-30 16:57:19 -04:00
app.post('/db/course_instance/:handle/members', mw.auth.checkLoggedIn(), mw.courseInstances.addMembers)
2016-04-13 12:54:24 -04:00
app.get('/db/course_instance/:handle/classroom', mw.auth.checkLoggedIn(), mw.courseInstances.fetchClassroom)
2016-03-30 16:57:19 -04:00
Stuff Partially fix ActivateLicensesModal.spec [IN PROGRESS] Don't display deleted users Move userID to classroom.deletedMembers on user delete (not retroactive) Fix PDF links for course guides, remove old PDFs from repo Remove deprecated SalesView Remove underline for not-yet-linked student names Only show class select when there's more than one Ignore case when sorting student names Use student.broadName instead of name for display and sorting Fix initial load not showing progress after joining a course (hacky) Fix text entry for enrollment number input Fix enrollment statistics Fix enrollment stats completely (and add back in per-class unenrolled count) Add deletedMembers to classroom schema More fixes to enrollment stats (don't count nonmember prepaids) Don't use 0 as implicit false for openSpots Update suggested number of credit to buy automatically Fix classroom edit form ignoring cleared values Add alert text when more users selected than enrollments available Alert user when trying to assign course to unenrolled students Alert user when assigning course to nobody Add some tests for TeacherClassView bulk assign alerts Fix TeacherClassView tests failing without demos Use model/collection.fakeRequests :D Remove unused comment Fix handling of improperly sorted deleted users on clientside Add test for moving deleted users to deletedMembers Add script for moving all deleted classroom members to classroom.deletedMembers Completely rewrite tallying up enrollment statistics Fix some tests to not be dependent on logged-in user Address PR comments Fix default number of enrollments to buy Fix i18n for not enough enrollments Use custom error message for classroom name length
2016-04-07 17:55:42 -04:00
app.delete('/db/user/:handle', mw.users.removeFromClassrooms)
app.get('/db/user', mw.users.fetchByGPlusID, mw.users.fetchByFacebookID)
2015-12-16 20:09:22 -05:00
2015-12-29 00:03:43 -05:00
app.get '/db/products', require('./db/product').get
2016-03-09 19:59:25 -05:00
TrialRequest = require '../models/TrialRequest'
app.get('/db/trial.request', mw.trialRequests.fetchByApplicant, mw.auth.checkHasPermission(['admin']), mw.rest.get(TrialRequest))
app.post('/db/trial.request', mw.trialRequests.post)
2016-03-09 19:59:25 -05:00
app.get('/db/trial.request/:handle', mw.auth.checkHasPermission(['admin']), mw.rest.getByHandle(TrialRequest))
app.put('/db/trial.request/:handle', mw.auth.checkHasPermission(['admin']), mw.trialRequests.put)
2015-12-29 00:03:43 -05:00
app.get '/healthcheck', (req, res) ->
try
async = require 'async'
User = require '../models/User'
2015-12-29 00:03:43 -05:00
async.waterfall [
(callback) ->
User.find({}).limit(1).exec(callback)
, (last, callback) ->
return("No users found") unless callback.length > 0
User.findOne(slug: 'healthcheck').exec(callback)
, (hcuser, callback) ->
# Create health check user if it doesnt exist
return callback(null, hcuser) if hcuser
user = new User
anonymous: false
name: 'healthcheck'
nameLower: 'healthcheck'
slug: 'healthcheck'
email: 'rob+healthcheck@codecombat.com'
emailLower: 'rob+healthcheck@codecombat.com'
user.set 'testGroupNumber', Math.floor(Math.random() * 256) # also in app/core/auth
user.save (err) ->
return callback(err) if err
callback(null, user)
, (hcuser, callback) ->
activity = hcuser.trackActivity 'healthcheck', 1
hcuser.update {activity: activity}, callback
], (err) ->
return res.status(500).send(err.toString()) if err
res.send("OK")
catch error
res.status(500).send(error.toString())