diff options
| author | Jules Laplace <jules@okfoc.us> | 2014-08-25 18:15:40 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2014-08-25 18:15:40 -0400 |
| commit | 9257818363269a2893c1a7ee61adb497f749e38f (patch) | |
| tree | 4c387fd37bbe93d2bdd529757a055101c4ab6884 /server/lib/api/collaborator.js | |
| parent | 124a698130f39992a1b47dcc8f32ef30c61a00eb (diff) | |
collab stuff 90% there
Diffstat (limited to 'server/lib/api/collaborator.js')
| -rw-r--r-- | server/lib/api/collaborator.js | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/server/lib/api/collaborator.js b/server/lib/api/collaborator.js index f39022f..c080070 100644 --- a/server/lib/api/collaborator.js +++ b/server/lib/api/collaborator.js @@ -1,20 +1,22 @@ /* jshint node: true */ var _ = require('lodash'), + auth = require('../auth'), util = require('../util'), upload = require('../upload'), config = require('../../../config.json'), + User = require('../schemas/User'), Collaborator = require('../schemas/Collaborator'), Project = require('../schemas/Project'); var collaborator = { join: function(req, res){ - var nonce = req.query.nonce + var nonce = req.params.nonce if (! nonce || ! nonce.length) { return res.json({ error: "invalid invite code" }) } Collaborator.findOne({ nonce: nonce }, function(err, collaborator){ if (err || ! collaborator) { return res.json({ error: "can't find collaborator" }) } - collaborator.user_id = req.user.user_id + collaborator.user_id = req.user._id collaborator.nonce = "" collaborator.save(function(err, collaborator){ Project.findOne({ _id: collaborator.project_id }, function(err, project){ @@ -31,7 +33,7 @@ var collaborator = { if (! req.project) { return res.json({ error: "can't find project" }) } - if (req.project.user_id !== req.user._id) { return res.json({ error: "insufficient permission" }) } + if (String(req.project.user_id) !== String(req.user._id)) { return res.json({ error: "insufficient permission" }) } Collaborator.find({ project_id: req.project._id }, function(err, collaborators){ var user_ids = _.pluck(collaborators, "user_id").filter(function(id){ return !! id }) User.find({ _id: user_ids }, "username displayName photo", function(err, users){ @@ -44,6 +46,7 @@ var collaborator = { obj.user = userIndex[ obj.user_id ] return obj }) + collaborators.unshift( { user: req.user.toObject(), owner: true } ) res.json(collaborators) }) }) @@ -60,11 +63,12 @@ var collaborator = { Collaborator.makeNonce(function(nonce){ data.nonce = nonce + new Collaborator(data).save(function(err, collaborator){ if (err || ! collaborator) { return res.json({ error: err }) } - auth.mail.forgotPassword(req.project, req.user, collaborator, function(){ - res.json(collaborator) - }) + console.log(collaborator) + res.json(collaborator) + auth.mail.collaborator(req.project, req.user, collaborator, function(){}) }) }) }, @@ -73,10 +77,10 @@ var collaborator = { if (! req.project) { return res.json({ error: "can't find project" }) } - if (req.project.user_id !== req.user._id) { + if (String(req.project.user_id) !== String(req.user._id)) { return res.json({ error: "insufficient permission" }) } - Collaborator.remove({ _id: _id }, function(err){ + Collaborator.remove({ _id: req.body._id }, function(err){ res.json({ status: "OK" }) }) } |
