mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-14 07:00:01 -04:00
Added reserved word checking for names.
This commit is contained in:
parent
3a28f190a1
commit
ed556f50be
2 changed files with 17 additions and 0 deletions
|
@ -5,8 +5,11 @@ textSearch = require('mongoose-text-search')
|
|||
module.exports.PatchablePlugin = (schema) ->
|
||||
schema.is_patchable = true
|
||||
schema.index({'target.original':1, 'status':'1', 'created':-1})
|
||||
|
||||
RESERVED_NAMES = ['search', 'names']
|
||||
|
||||
module.exports.NamedPlugin = (schema) ->
|
||||
schema.uses_coco_names = true
|
||||
schema.add({name: String, slug: String})
|
||||
schema.index({'slug': 1}, {unique: true, sparse: true, name: 'slug index'})
|
||||
|
||||
|
@ -16,6 +19,11 @@ module.exports.NamedPlugin = (schema) ->
|
|||
return next() unless v.isLatestMajor and v.isLatestMinor
|
||||
|
||||
newSlug = _.str.slugify(@get('name'))
|
||||
if newSlug in RESERVED_NAMES
|
||||
err = new Error('Reserved name.')
|
||||
err.response = {message:' is a reserved name', property: 'name'}
|
||||
err.code = 422
|
||||
return next(err)
|
||||
if newSlug isnt @get('slug')
|
||||
@set('slug', newSlug)
|
||||
@checkSlugConflicts(next)
|
||||
|
|
|
@ -84,3 +84,12 @@ describe '/db/article', ->
|
|||
body = JSON.parse(body)
|
||||
expect(body.type).toBeDefined()
|
||||
done()
|
||||
|
||||
it 'does not allow naming an article a reserved word', (done) ->
|
||||
loginAdmin ->
|
||||
new_article = {name: 'Search', body:'is a reserved word'}
|
||||
request.post {uri:url, json:new_article}, (err, res, body) ->
|
||||
expect(res.statusCode).toBe(422)
|
||||
done()
|
||||
|
||||
|
Loading…
Reference in a new issue