overleaf/services/web/app/coffee/Features/Project/ProjectCollabratecDetailsHandler.coffee
Ersun Warncke 28c934e8ff Merge pull request #1194 from sharelatex/ew-collabratec-link-project-apis
collabratec link/unlink apis, auth refactor

GitOrigin-RevId: dc901494197334e87d3e6702c789654ccef5e56a
2018-12-04 11:38:57 +00:00

54 lines
1.7 KiB
CoffeeScript

ObjectId = require("mongojs").ObjectId
Project = require("../../models/Project").Project
module.exports = ProjectCollabratecDetailsHandler =
initializeCollabratecProject: (project_id, user_id, collabratec_document_id, collabratec_privategroup_id, callback=(err)->) ->
try
project_id = ObjectId(project_id)
user_id = ObjectId(user_id)
catch err
return callback err
update = $set: { collabratecUsers: [ { user_id, collabratec_document_id, collabratec_privategroup_id } ] }
Project.update { _id: project_id }, update, callback
isLinkedCollabratecUserProject: (project_id, user_id, callback=(err, isLinked)->) ->
try
project_id = ObjectId(project_id)
user_id = ObjectId(user_id)
catch err
return callback err
query =
_id: project_id
collabratecUsers: $elemMatch:
user_id: user_id
Project.findOne query, {_id: 1}, (err, project) ->
callback err if err?
callback null, project?
linkCollabratecUserProject: (project_id, user_id, collabratec_document_id, callback=(err)->) ->
try
project_id = ObjectId(project_id)
user_id = ObjectId(user_id)
catch err
return callback err
query =
_id: project_id
collabratecUsers: $not: $elemMatch:
collabratec_document_id: collabratec_document_id
user_id: user_id
update = $push: collabratecUsers:
collabratec_document_id: collabratec_document_id
user_id: user_id
Project.update query, update, callback
unlinkCollabratecUserProject: (project_id, user_id, callback=(err)->) ->
try
project_id = ObjectId(project_id)
user_id = ObjectId(user_id)
catch err
return callback err
query =
_id: project_id
update = $pull: collabratecUsers:
user_id: user_id
Project.update query, update, callback