2014-10-31 10:34:18 +00:00
|
|
|
_ = require("underscore")
|
2018-08-13 09:22:23 +00:00
|
|
|
Path = require 'path'
|
2018-06-01 14:16:27 +00:00
|
|
|
|
2014-02-12 10:23:40 +00:00
|
|
|
module.exports = ProjectEditorHandler =
|
2017-03-02 16:45:24 +00:00
|
|
|
trackChangesAvailable: false
|
|
|
|
|
2017-10-25 10:29:05 +00:00
|
|
|
buildProjectModelView: (project, members, invites) ->
|
2014-02-12 10:23:40 +00:00
|
|
|
result =
|
|
|
|
_id : project._id
|
|
|
|
name : project.name
|
|
|
|
rootDoc_id : project.rootDoc_id
|
|
|
|
rootFolder : [@buildFolderModelView project.rootFolder[0]]
|
|
|
|
publicAccesLevel : project.publicAccesLevel
|
|
|
|
dropboxEnabled : !!project.existsInDropbox
|
|
|
|
compiler : project.compiler
|
|
|
|
description: project.description
|
|
|
|
spellCheckLanguage: project.spellCheckLanguage
|
|
|
|
deletedByExternalDataSource : project.deletedByExternalDataSource || false
|
2014-06-05 12:11:39 +00:00
|
|
|
deletedDocs: project.deletedDocs
|
2016-03-07 15:25:10 +00:00
|
|
|
members: []
|
2016-08-15 14:22:23 +00:00
|
|
|
invites: invites
|
2017-09-28 15:06:08 +00:00
|
|
|
tokens: project.tokens
|
2018-08-13 09:22:23 +00:00
|
|
|
imageName: if project.imageName? then Path.basename(project.imageName) else undefined
|
2016-08-15 14:22:23 +00:00
|
|
|
|
|
|
|
if !result.invites?
|
|
|
|
result.invites = []
|
2017-10-19 13:42:17 +00:00
|
|
|
|
2017-10-25 10:29:05 +00:00
|
|
|
{owner, ownerFeatures, members} = @buildOwnerAndMembersViews(members)
|
2016-08-04 15:47:48 +00:00
|
|
|
result.owner = owner
|
|
|
|
result.members = members
|
2014-02-12 10:23:40 +00:00
|
|
|
|
2016-08-04 15:47:48 +00:00
|
|
|
result.features = _.defaults(ownerFeatures or {}, {
|
2016-03-15 14:44:06 +00:00
|
|
|
collaborators: -1 # Infinite
|
|
|
|
versioning: false
|
|
|
|
dropbox:false
|
|
|
|
compileTimeout: 60
|
|
|
|
compileGroup:"standard"
|
|
|
|
templates: false
|
2018-03-28 12:47:34 +00:00
|
|
|
references: false
|
2018-03-28 16:11:41 +00:00
|
|
|
referencesSearch: false
|
|
|
|
mendeley: false
|
2017-02-13 11:09:47 +00:00
|
|
|
trackChanges: false
|
2017-03-08 11:57:33 +00:00
|
|
|
trackChangesVisible: ProjectEditorHandler.trackChangesAvailable
|
2016-03-15 14:44:06 +00:00
|
|
|
})
|
2014-10-20 11:21:40 +00:00
|
|
|
|
2018-03-28 16:11:41 +00:00
|
|
|
# Originally these two feature flags were both signalled by the now-deprecated `references` flag.
|
|
|
|
# For older users, the presence of the `references` feature flag should still turn on these features.
|
|
|
|
result.features.referencesSearch = result.features.referencesSearch or result.features.references
|
|
|
|
result.features.mendeley = result.features.mendeley or result.features.references
|
|
|
|
|
2014-02-12 10:23:40 +00:00
|
|
|
return result
|
|
|
|
|
2017-10-25 10:29:05 +00:00
|
|
|
buildOwnerAndMembersViews: (members) ->
|
2016-08-04 15:47:48 +00:00
|
|
|
owner = null
|
|
|
|
ownerFeatures = null
|
|
|
|
filteredMembers = []
|
2017-10-25 09:34:18 +00:00
|
|
|
for member in (members || [])
|
2016-08-04 15:47:48 +00:00
|
|
|
if member.privilegeLevel == "owner"
|
|
|
|
ownerFeatures = member.user.features
|
|
|
|
owner = @buildUserModelView member.user, "owner"
|
|
|
|
else
|
|
|
|
filteredMembers.push @buildUserModelView member.user, member.privilegeLevel
|
2017-10-19 13:42:17 +00:00
|
|
|
return {
|
|
|
|
owner: owner,
|
|
|
|
ownerFeatures: ownerFeatures,
|
|
|
|
members: filteredMembers,
|
|
|
|
}
|
2016-08-04 15:47:48 +00:00
|
|
|
|
2014-02-12 10:23:40 +00:00
|
|
|
buildUserModelView: (user, privileges) ->
|
|
|
|
_id : user._id
|
|
|
|
first_name : user.first_name
|
|
|
|
last_name : user.last_name
|
|
|
|
email : user.email
|
|
|
|
privileges : privileges
|
|
|
|
signUpDate : user.signUpDate
|
|
|
|
|
|
|
|
buildFolderModelView: (folder) ->
|
2016-03-23 10:54:36 +00:00
|
|
|
fileRefs = _.filter (folder.fileRefs or []), (file)-> file?
|
2014-02-12 10:23:40 +00:00
|
|
|
_id : folder._id
|
|
|
|
name : folder.name
|
2016-03-23 10:54:36 +00:00
|
|
|
folders : @buildFolderModelView childFolder for childFolder in (folder.folders or [])
|
2014-10-31 10:34:18 +00:00
|
|
|
fileRefs : @buildFileModelView file for file in fileRefs
|
2016-03-23 10:54:36 +00:00
|
|
|
docs : @buildDocModelView doc for doc in (folder.docs or [])
|
2014-02-12 10:23:40 +00:00
|
|
|
|
|
|
|
buildFileModelView: (file) ->
|
|
|
|
_id : file._id
|
|
|
|
name : file.name
|
2018-02-20 10:37:55 +00:00
|
|
|
linkedFileData: file.linkedFileData
|
|
|
|
created: file.created
|
2014-02-12 10:23:40 +00:00
|
|
|
|
|
|
|
buildDocModelView: (doc) ->
|
|
|
|
_id : doc._id
|
|
|
|
name : doc.name
|