mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 23:58:02 -05:00
Merge pull request #344 from smoratinos/master
delete unused code on server
This commit is contained in:
commit
d28f162c52
18 changed files with 1 additions and 340 deletions
|
@ -1,22 +0,0 @@
|
|||
mongoose = require('mongoose')
|
||||
plugins = require('../plugins/plugins')
|
||||
|
||||
NestedLevelSchema = new mongoose.Schema(
|
||||
name: String
|
||||
description: String
|
||||
thumbnail: Buffer
|
||||
original: {type: mongoose.Schema.ObjectId, ref: 'level'}
|
||||
majorVersion: Number
|
||||
)
|
||||
|
||||
CampaignSchema = new mongoose.Schema(
|
||||
description: String
|
||||
levels: [NestedLevelSchema]
|
||||
)
|
||||
|
||||
CampaignSchema.plugin(plugins.NamedPlugin)
|
||||
CampaignSchema.plugin(plugins.PermissionsPlugin)
|
||||
CampaignSchema.plugin(plugins.SearchablePlugin, {searchable: ['name', 'description']})
|
||||
|
||||
module.exports = Campaign = mongoose.model('campaign', CampaignSchema)
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
mongoose = require('mongoose')
|
||||
|
||||
LevelStatusSchema = new mongoose.Schema(
|
||||
lastPlayed: Date
|
||||
victorious: Boolean
|
||||
original: {type: mongoose.Schema.ObjectId, ref: 'level'}
|
||||
majorVersion: Number
|
||||
)
|
||||
|
||||
CampaignStatusSchema = new mongoose.Schema(
|
||||
user: {type: mongoose.Schema.ObjectId, ref: 'User'}
|
||||
campaign: {type: mongoose.Schema.ObjectId, ref: 'campaign'}
|
||||
levelStatuses: [LevelStatusSchema]
|
||||
)
|
||||
CampaignStatusSchema.index {user: 1, campaign: 1}, {unique: true}
|
||||
|
||||
module.exports = CampaignStatus = mongoose.model('campaign.status', CampaignStatusSchema)
|
|
@ -1,10 +0,0 @@
|
|||
Campaign = require('./Campaign')
|
||||
Handler = require('../commons/Handler')
|
||||
|
||||
CampaignHandler = class CampaignHandler extends Handler
|
||||
modelClass: Campaign
|
||||
editableProperties: ['name', 'description', 'levels']
|
||||
|
||||
|
||||
|
||||
module.exports = new CampaignHandler()
|
|
@ -1,13 +0,0 @@
|
|||
CampaignStatus = require('./CampaignStatus')
|
||||
Handler = require('../commons/Handler')
|
||||
|
||||
CampaignStatusHandler = class CampaignStatusHandler extends Handler
|
||||
modelClass: CampaignStatus
|
||||
editableProperties: ['levelStatuses']
|
||||
postEditableProperties: ['campaign', 'user']
|
||||
|
||||
post: (req, res) ->
|
||||
req.body.user = req.user._id
|
||||
super(req, res)
|
||||
|
||||
module.exports = new CampaignStatusHandler()
|
|
@ -1,12 +1,8 @@
|
|||
|
||||
module.exports.handlers =
|
||||
'article': 'articles/article_handler'
|
||||
'campaign': 'campaigns/campaign_handler'
|
||||
'campaign_status': 'campaigns/campaign_status_handler'
|
||||
'file': 'files/file_handler'
|
||||
'level': 'levels/level_handler'
|
||||
'level_component': 'levels/components/level_component_handler'
|
||||
'level_draft': 'levels/drafts/level_draft_handler'
|
||||
'level_feedback': 'levels/feedbacks/level_feedback_handler'
|
||||
'level_session': 'levels/sessions/level_session_handler'
|
||||
'level_system': 'levels/systems/level_system_handler'
|
||||
|
@ -16,7 +12,6 @@ module.exports.handlers =
|
|||
module.exports.schemas =
|
||||
'article': 'articles/article_schema'
|
||||
'common': 'commons/schemas'
|
||||
#'file': 'files/file_schema'
|
||||
'i18n': 'commons/i18n_schema'
|
||||
'level': 'levels/level_schema'
|
||||
'level_component': 'levels/components/level_component_schema'
|
||||
|
@ -38,4 +33,4 @@ module.exports.routes =
|
|||
'routes/languages'
|
||||
'routes/mail'
|
||||
'routes/sprites'
|
||||
]
|
||||
]
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
mongoose = require('mongoose')
|
||||
plugins = require('../plugins/plugins')
|
||||
|
||||
FileSchema = new mongoose.Schema()
|
||||
|
||||
FileSchema.plugin(plugins.SearchablePlugin, {searchable: ['metadata.description', 'metadata.name']})
|
||||
|
||||
module.exports = mongoose.model('media.files', FileSchema)
|
|
@ -1,13 +0,0 @@
|
|||
File = require('./File')
|
||||
Handler = require('../commons/Handler')
|
||||
|
||||
FileHandler = class FileHandler extends Handler
|
||||
modelClass: File
|
||||
editableProperties: ['metadata']
|
||||
|
||||
hasAccess: (req) ->
|
||||
req.method is 'GET'
|
||||
|
||||
# TODO: once we're building the clients, need special GET handler, search handler
|
||||
|
||||
module.exports = new FileHandler()
|
|
@ -1,25 +0,0 @@
|
|||
c = require '../commons/schemas'
|
||||
|
||||
FileSchema = c.baseSchema()
|
||||
|
||||
_.extend(FileSchema.properties, {
|
||||
filename: c.shortStringProp()
|
||||
contentType: c.shortStringProp()
|
||||
length: { type: 'number' }
|
||||
chunkSize: { type: 'number', format: 'hidden' }
|
||||
uploadDate: { type: 'string' }
|
||||
aliases: {}
|
||||
metadata:
|
||||
type: 'object'
|
||||
additionalProperties: false
|
||||
name: c.shortStringArrayProp()
|
||||
description: { type: 'string' }
|
||||
createdFor: { type: 'array', items: {}}
|
||||
path: { type: 'string' }
|
||||
creator: { type: 'string' }
|
||||
})
|
||||
|
||||
c.extendSearchableProperties(FileSchema.properties.metadata)
|
||||
FileSchema.format = 'file'
|
||||
|
||||
module.exports = FileSchema
|
|
@ -1,9 +0,0 @@
|
|||
mongoose = require('mongoose')
|
||||
Level = require('../Level')
|
||||
|
||||
LevelDraftSchema = new mongoose.Schema(
|
||||
user: {type: mongoose.Schema.ObjectId, ref: 'User'}
|
||||
level: {}
|
||||
)
|
||||
|
||||
module.exports = LevelDraft = mongoose.model('level.draft', LevelDraftSchema)
|
|
@ -1,13 +0,0 @@
|
|||
LevelDraft = require('./LevelDraft')
|
||||
Handler = require('../../commons/Handler')
|
||||
|
||||
LevelDraftHandler = class LevelDraftHandler extends Handler
|
||||
modelClass: LevelDraft
|
||||
editableProperties: ['level']
|
||||
postEditableProperties: ['user']
|
||||
|
||||
post: (req, res) ->
|
||||
req.body.user = req.user._id
|
||||
super(req, res)
|
||||
|
||||
module.exports = new LevelDraftHandler()
|
|
@ -10,12 +10,9 @@ path = require('path')
|
|||
|
||||
models_path = [
|
||||
'../../server/articles/Article'
|
||||
'../../server/campaigns/Campaign'
|
||||
'../../server/campaigns/CampaignStatus'
|
||||
'../../server/levels/Level'
|
||||
'../../server/levels/components/LevelComponent'
|
||||
'../../server/levels/systems/LevelSystem'
|
||||
'../../server/levels/drafts/LevelDraft'
|
||||
'../../server/levels/sessions/LevelSession'
|
||||
'../../server/levels/thangs/LevelThangType'
|
||||
'../../server/users/User'
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
require '../common'
|
||||
|
||||
describe '/db/campaign', ->
|
||||
request = require 'request'
|
||||
it 'clears the db first', (done) ->
|
||||
clearModels [User, Campaign], (err) ->
|
||||
throw err if err
|
||||
done()
|
||||
|
||||
campaign = {name: 'A', description:'B'}
|
||||
url = getURL('/db/campaign')
|
||||
campaigns = {}
|
||||
|
||||
it 'allows making Campaigns.', (done) ->
|
||||
loginJoe (user) ->
|
||||
campaign.permissions = [access: 'owner', target: user._id]
|
||||
request.post {uri:url, json:campaign}, (err, res, body) ->
|
||||
expect(res.statusCode).toBe(200)
|
||||
expect(body.permissions).toBeDefined()
|
||||
campaigns[0] = body
|
||||
done()
|
||||
|
||||
it 'does not allow other users access', (done) ->
|
||||
loginSam ->
|
||||
request.get {uri:url+'/'+campaigns[0]._id}, (err, res, body) ->
|
||||
expect(res.statusCode).toBe(403)
|
||||
done()
|
||||
|
||||
it 'allows editing permissions.', (done) ->
|
||||
loginJoe ->
|
||||
campaigns[0].permissions.push(access: 'read', target: 'public')
|
||||
request.put {uri:url, json:campaigns[0]}, (err, res, body) ->
|
||||
expect(res.statusCode).toBe(200)
|
||||
expect(body.permissions.length).toBe(2)
|
||||
campaigns[0] = body
|
||||
done()
|
||||
|
||||
it 'allows anyone to access it through public permissions', (done) ->
|
||||
loginSam ->
|
||||
request.get {uri:url+'/'+campaigns[0]._id}, (err, res, body) ->
|
||||
expect(res.statusCode).toBe(200)
|
||||
done()
|
|
@ -1,21 +0,0 @@
|
|||
require '../common'
|
||||
|
||||
describe '/db/campaign_status', ->
|
||||
request = require 'request'
|
||||
it 'clears the db first', (done) ->
|
||||
clearModels [Campaign, CampaignStatus], (err) ->
|
||||
throw err if err
|
||||
done()
|
||||
|
||||
user = new User(name:'sup')
|
||||
campaign = new Campaign(name:'Project Vengeance.', permissions: simplePermissions)
|
||||
stat = {campaign: campaign._id, user: user._id}
|
||||
url = getURL('/db/campaign_status')
|
||||
|
||||
it 'can make a CampaignStatus, and ignores the user property given.', (done) ->
|
||||
loginJoe (joe) ->
|
||||
request.post {uri:url, json:stat}, (err, res, body) ->
|
||||
expect(res.statusCode).toBe(200)
|
||||
expect(body.user).toBe(joe._id.toString())
|
||||
expect(body.user).not.toBe(user._id.toString())
|
||||
done()
|
|
@ -1,23 +0,0 @@
|
|||
require '../common'
|
||||
|
||||
describe '/db/campaign_draft', ->
|
||||
|
||||
draft = {
|
||||
level: {}
|
||||
user: 'yoyoyo'
|
||||
}
|
||||
|
||||
request = require 'request'
|
||||
it 'clears the db first', (done) ->
|
||||
clearModels [LevelDraft], (err) ->
|
||||
throw err if err
|
||||
done()
|
||||
|
||||
url = getURL('/db/level_draft')
|
||||
|
||||
it 'can make a LevelDraft, and ignores the user property given.', (done) ->
|
||||
loginJoe (joe) ->
|
||||
request.post {uri:url, json:draft}, (err, res, body) ->
|
||||
expect(res.statusCode).toBe(200)
|
||||
expect(body.user).toBe(joe._id.toString())
|
||||
done()
|
|
@ -1,34 +0,0 @@
|
|||
require '../../common'
|
||||
|
||||
describe 'CampaignStatus', ->
|
||||
|
||||
user = new User(name:'sup')
|
||||
campaign = new Campaign(name:'Project Vengeance.', permissions: simplePermissions)
|
||||
stat = new CampaignStatus(user: user._id, campaign: campaign._id)
|
||||
|
||||
it 'clears things first', (done) ->
|
||||
clearModels [User, Campaign, CampaignStatus], (err) ->
|
||||
expect(err).toBeNull()
|
||||
done()
|
||||
|
||||
it 'can be saved', (done) ->
|
||||
saveModels [user, campaign, stat], (err) ->
|
||||
expect(err).toBeNull()
|
||||
done()
|
||||
|
||||
it 'can populate', (done) ->
|
||||
CampaignStatus
|
||||
.findOne({_id:stat._id})
|
||||
.populate('user')
|
||||
.populate('campaign')
|
||||
.exec (err, c) ->
|
||||
expect(err).toBe(null)
|
||||
expect(c.user.get('name')).toBeDefined()
|
||||
expect(c.campaign.get('name')).toBeDefined()
|
||||
done()
|
||||
|
||||
it 'rejects duplicates', (done) ->
|
||||
stat2 = new CampaignStatus(user: user._id, campaign: campaign._id)
|
||||
stat2.save (err) ->
|
||||
expect(err).not.toBe(null)
|
||||
done()
|
|
@ -1,31 +0,0 @@
|
|||
require '../../common'
|
||||
|
||||
describe 'LevelDraft', ->
|
||||
|
||||
level = new Level(
|
||||
name: "King's Peak Redux"
|
||||
description: 'Climb a mountain.'
|
||||
permissions: simplePermissions
|
||||
original: new ObjectId()
|
||||
)
|
||||
|
||||
it 'clears things first', (done) ->
|
||||
clearModels [Level, LevelDraft], (err) ->
|
||||
expect(err).toBeNull()
|
||||
done()
|
||||
|
||||
it 'saves', (done) ->
|
||||
level.save (err) ->
|
||||
throw err if err
|
||||
|
||||
draft = new LevelDraft(
|
||||
user: new ObjectId()
|
||||
level: level
|
||||
)
|
||||
|
||||
draft.save (err) ->
|
||||
throw err if err
|
||||
|
||||
LevelDraft.findOne {_id:draft._id}, (err, fetched) ->
|
||||
expect(fetched.level.original).toBeDefined()
|
||||
done()
|
|
@ -1,26 +0,0 @@
|
|||
require '../../common'
|
||||
|
||||
describe 'Campaign', ->
|
||||
|
||||
raw =
|
||||
name:'Battlefield 1942'
|
||||
description:'Vacation all over the world!'
|
||||
levels: []
|
||||
permissions:[
|
||||
target:'not_the_public'
|
||||
access:'owner'
|
||||
]
|
||||
|
||||
campaign = new Campaign(raw)
|
||||
|
||||
it 'clears things first', (done) ->
|
||||
Campaign.remove {}, (err) ->
|
||||
expect(err).toBeNull()
|
||||
done()
|
||||
|
||||
it 'can be saved', (done) ->
|
||||
campaign.save (err) ->
|
||||
expect(err).toBeNull()
|
||||
done()
|
||||
|
||||
|
|
@ -328,27 +328,3 @@ describe 'SearchablePlugin', ->
|
|||
target:'not_the_public'
|
||||
access:'owner'
|
||||
]
|
||||
|
||||
campaign = new Campaign(raw)
|
||||
|
||||
it 'clears things first', (done) ->
|
||||
Campaign.remove {}, (err) ->
|
||||
expect(err).toBeNull()
|
||||
done()
|
||||
|
||||
it 'hides private entities from public searches', (done) ->
|
||||
campaign.save (err) ->
|
||||
throw err if err
|
||||
done()
|
||||
|
||||
Campaign.textSearch 'battlefield', {filter:{ index: true}}, (err, results) ->
|
||||
expect(results.results.length).toBe(0)
|
||||
done()
|
||||
|
||||
it 'allows private searches for owning users', (done) ->
|
||||
campaign.save (err) ->
|
||||
throw err if err
|
||||
|
||||
Campaign.textSearch 'battlefield', {filter: { index: 'not_the_public' }}, (err, results) ->
|
||||
expect(results.results.length).toBeGreaterThan(0)
|
||||
done()
|
||||
|
|
Loading…
Reference in a new issue