|
|
@@ -30,26 +30,34 @@ module.exports = CollaboratorsHandler =
|
|
|
return callback null, user._id
|
|
|
|
|
|
addUserIdToProject: (project_id, adding_user_id, user_id, privilegeLevel, callback = (error) ->)->
|
|
|
- if privilegeLevel == 'readAndWrite'
|
|
|
- level = {"collaberator_refs":user_id}
|
|
|
- logger.log {privileges: "readAndWrite", user_id, project_id}, "adding user"
|
|
|
- else if privilegeLevel == 'readOnly'
|
|
|
- level = {"readOnly_refs":user_id}
|
|
|
- logger.log {privileges: "readOnly", user_id, project_id}, "adding user"
|
|
|
- else
|
|
|
- return callback(new Error("unknown privilegeLevel: #{privilegeLevel}"))
|
|
|
-
|
|
|
- # Do these in the background
|
|
|
- UserGetter.getUser user_id, {email: 1}, (error, user) ->
|
|
|
- if error?
|
|
|
- logger.error {err: error, project_id, user_id}, "error getting user while adding to project"
|
|
|
- CollaboratorsEmailHandler.notifyUserOfProjectShare project_id, user.email
|
|
|
- ContactManager.addContact adding_user_id, user_id
|
|
|
-
|
|
|
- Project.update { _id: project_id }, { $push:level }, (error) ->
|
|
|
+ Project.findOne { _id: project_id }, { collaberator_refs: 1, readOnly_refs: 1 }, (error, project) ->
|
|
|
return callback(error) if error?
|
|
|
- # Flush to TPDS in background to add files to collaborator's Dropbox
|
|
|
- ProjectEntityHandler.flushProjectToThirdPartyDataStore project_id, (error) ->
|
|
|
+ existing_users = (project.collaberator_refs or [])
|
|
|
+ existing_users = existing_users.concat(project.readOnly_refs or [])
|
|
|
+ existing_users = existing_users.map (u) -> u.toString()
|
|
|
+ if existing_users.indexOf(user_id.toString()) > -1
|
|
|
+ return callback null # User already in Project
|
|
|
+
|
|
|
+ if privilegeLevel == 'readAndWrite'
|
|
|
+ level = {"collaberator_refs":user_id}
|
|
|
+ logger.log {privileges: "readAndWrite", user_id, project_id}, "adding user"
|
|
|
+ else if privilegeLevel == 'readOnly'
|
|
|
+ level = {"readOnly_refs":user_id}
|
|
|
+ logger.log {privileges: "readOnly", user_id, project_id}, "adding user"
|
|
|
+ else
|
|
|
+ return callback(new Error("unknown privilegeLevel: #{privilegeLevel}"))
|
|
|
+
|
|
|
+ # Do these in the background
|
|
|
+ UserGetter.getUser user_id, {email: 1}, (error, user) ->
|
|
|
if error?
|
|
|
- logger.error {err: error, project_id, user_id}, "error flushing to TPDS after adding collaborator"
|
|
|
- callback()
|
|
|
+ logger.error {err: error, project_id, user_id}, "error getting user while adding to project"
|
|
|
+ CollaboratorsEmailHandler.notifyUserOfProjectShare project_id, user.email
|
|
|
+ ContactManager.addContact adding_user_id, user_id
|
|
|
+
|
|
|
+ Project.update { _id: project_id }, { $addToSet: level }, (error) ->
|
|
|
+ return callback(error) if error?
|
|
|
+ # Flush to TPDS in background to add files to collaborator's Dropbox
|
|
|
+ ProjectEntityHandler.flushProjectToThirdPartyDataStore project_id, (error) ->
|
|
|
+ if error?
|
|
|
+ logger.error {err: error, project_id, user_id}, "error flushing to TPDS after adding collaborator"
|
|
|
+ callback()
|