2014-02-12 05:23:40 -05:00
|
|
|
ProjectGetter = require("./ProjectGetter")
|
2014-03-28 08:47:15 -04:00
|
|
|
UserGetter = require("../User/UserGetter")
|
2014-02-12 05:23:40 -05:00
|
|
|
Project = require('../../models/Project').Project
|
|
|
|
logger = require("logger-sharelatex")
|
2014-04-07 10:37:40 -04:00
|
|
|
tpdsUpdateSender = require '../ThirdPartyDataStore/TpdsUpdateSender'
|
2014-04-07 11:07:44 -04:00
|
|
|
_ = require("underscore")
|
2014-02-12 05:23:40 -05:00
|
|
|
|
|
|
|
module.exports =
|
|
|
|
|
|
|
|
getDetails: (project_id, callback)->
|
2016-02-29 08:05:17 -05:00
|
|
|
ProjectGetter.getProject project_id, {name:true, description:true, compiler:true, features:true, owner_ref:true}, (err, project)->
|
2014-02-12 05:23:40 -05:00
|
|
|
if err?
|
|
|
|
logger.err err:err, project_id:project_id, "error getting project"
|
|
|
|
return callback(err)
|
2014-03-28 08:47:15 -04:00
|
|
|
UserGetter.getUser project.owner_ref, (err, user) ->
|
|
|
|
return callback(err) if err?
|
|
|
|
details =
|
|
|
|
name : project.name
|
|
|
|
description: project.description
|
|
|
|
compiler: project.compiler
|
|
|
|
features: user.features
|
|
|
|
logger.log project_id:project_id, details:details, "getting project details"
|
|
|
|
callback(err, details)
|
2014-02-12 05:23:40 -05:00
|
|
|
|
2014-07-16 06:27:47 -04:00
|
|
|
getProjectDescription: (project_id, callback)->
|
2014-07-16 06:56:22 -04:00
|
|
|
Project.findOne _id:project_id, "description", (err, project)->
|
|
|
|
callback(err, project?.description)
|
2014-07-16 06:27:47 -04:00
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
setProjectDescription: (project_id, description, callback)->
|
|
|
|
conditions = _id:project_id
|
|
|
|
update = description:description
|
|
|
|
logger.log conditions:conditions, update:update, project_id:project_id, description:description, "setting project description"
|
|
|
|
Project.update conditions, update, (err)->
|
|
|
|
if err?
|
|
|
|
logger.err err:err, "something went wrong setting project description"
|
|
|
|
callback(err)
|
2014-04-07 10:37:40 -04:00
|
|
|
|
|
|
|
renameProject: (project_id, newName, callback = ->)->
|
|
|
|
logger.log project_id: project_id, newName:newName, "renaming project"
|
2016-02-29 08:05:17 -05:00
|
|
|
ProjectGetter.getProject project_id, {name:true}, (err, project)->
|
2014-04-07 10:37:40 -04:00
|
|
|
if err? or !project?
|
|
|
|
logger.err err:err, project_id:project_id, "error getting project or could not find it todo project rename"
|
|
|
|
return callback(err)
|
|
|
|
oldProjectName = project.name
|
|
|
|
Project.update _id:project_id, {name: newName}, (err, project)=>
|
|
|
|
if err?
|
|
|
|
return callback(err)
|
|
|
|
tpdsUpdateSender.moveEntity {project_id:project_id, project_name:oldProjectName, newProjectName:newName}, callback
|
2014-04-07 11:07:44 -04:00
|
|
|
|
|
|
|
setPublicAccessLevel : (project_id, newAccessLevel, callback = ->)->
|
|
|
|
logger.log project_id: project_id, level: newAccessLevel, "set public access level"
|
|
|
|
if project_id? && newAccessLevel? and _.include ['readOnly', 'readAndWrite', 'private'], newAccessLevel
|
|
|
|
Project.update {_id:project_id},{publicAccesLevel:newAccessLevel}, (err)->
|
|
|
|
callback()
|