overleaf/services/web/app/coffee/Features/Project/ProjectEditorHandler.coffee

92 lines
2.7 KiB
CoffeeScript
Raw Normal View History

_ = require("underscore")
2014-02-12 05:23:40 -05:00
module.exports = ProjectEditorHandler =
trackChangesAvailable: false
2017-10-19 09:42:17 -04:00
buildProjectModelView: (project, members, invites, tokenMembers=[]) ->
2014-02-12 05:23:40 -05: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
deletedDocs: project.deletedDocs
members: []
2017-10-19 09:42:17 -04:00
tokenMembers: []
invites: invites
tokens: project.tokens
if !result.invites?
result.invites = []
2017-10-19 09:42:17 -04:00
{owner, ownerFeatures, members, tokenMembers} = @buildOwnerAndMembersViews(
members,
tokenMembers
)
result.owner = owner
result.members = members
2017-10-19 09:42:17 -04:00
result.tokenMembers = tokenMembers
2014-02-12 05:23:40 -05:00
result.features = _.defaults(ownerFeatures or {}, {
collaborators: -1 # Infinite
versioning: false
dropbox:false
compileTimeout: 60
compileGroup:"standard"
templates: false
references: false
2017-02-13 06:09:47 -05:00
trackChanges: false
trackChangesVisible: ProjectEditorHandler.trackChangesAvailable
})
2014-02-12 05:23:40 -05:00
return result
2017-10-19 09:42:17 -04:00
buildOwnerAndMembersViews: (members, tokenMembers) ->
owner = null
ownerFeatures = null
filteredMembers = []
2017-10-19 09:42:17 -04:00
filteredTokenMembers = []
2017-10-25 05:34:18 -04:00
for member in (members || [])
if member.privilegeLevel == "owner"
ownerFeatures = member.user.features
owner = @buildUserModelView member.user, "owner"
else
filteredMembers.push @buildUserModelView member.user, member.privilegeLevel
2017-10-25 05:34:18 -04:00
for tokenMember in (tokenMembers || [])
2017-10-19 09:42:17 -04:00
filteredTokenMembers.push @buildUserModelView tokenMember.user, tokenMember.privilegeLevel
return {
owner: owner,
ownerFeatures: ownerFeatures,
members: filteredMembers,
tokenMembers: filteredTokenMembers
}
2014-02-12 05:23:40 -05: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) ->
fileRefs = _.filter (folder.fileRefs or []), (file)-> file?
2014-02-12 05:23:40 -05:00
_id : folder._id
name : folder.name
folders : @buildFolderModelView childFolder for childFolder in (folder.folders or [])
fileRefs : @buildFileModelView file for file in fileRefs
docs : @buildDocModelView doc for doc in (folder.docs or [])
2014-02-12 05:23:40 -05:00
buildFileModelView: (file) ->
_id : file._id
name : file.name
buildDocModelView: (doc) ->
_id : doc._id
name : doc.name