Use _.defaults to simplify assigning default features

This commit is contained in:
James Allen 2016-03-15 14:44:06 +00:00
parent b7d226f434
commit 75d9912449

View file

@ -16,15 +16,6 @@ module.exports = ProjectEditorHandler =
deletedDocs: project.deletedDocs deletedDocs: project.deletedDocs
members: [] members: []
result.features = # defaults
collaborators: -1 # Infinite
versioning: false
dropbox:false
compileTimeout: 60
compileGroup:"standard"
templates: false
references: false
owner = null owner = null
for member in members for member in members
if member.privilegeLevel == "owner" if member.privilegeLevel == "owner"
@ -34,21 +25,15 @@ module.exports = ProjectEditorHandler =
if owner? if owner?
result.owner = @buildUserModelView owner, "owner" result.owner = @buildUserModelView owner, "owner"
if owner?.features? result.features = _.defaults(owner?.features or {}, {
if owner.features.collaborators? collaborators: -1 # Infinite
result.features.collaborators = owner.features.collaborators versioning: false
if owner.features.versioning? dropbox:false
result.features.versioning = owner.features.versioning compileTimeout: 60
if owner.features.dropbox? compileGroup:"standard"
result.features.dropbox = owner.features.dropbox templates: false
if owner.features.compileTimeout? references: false
result.features.compileTimeout = owner.features.compileTimeout })
if owner.features.compileGroup?
result.features.compileGroup = owner.features.compileGroup
if owner.features.templates?
result.features.templates = owner.features.templates
if owner.features.references?
result.features.references = owner.features.references
return result return result