lib/routes/collaborators/api.js
function add(project, email, accessLevel, inviter, done) {
  User.findOne({email: email}, function (err, user) {
    if (err) {
      return done(err);
    }

    if (user) {
      var p = _.find(user.projects, function (p) {
        return p.name === project.toLowerCase();
      });
      if (p) {
        return done('user already a collaborator', true);
      }
      User.update({email: email}, {
        $push: {
          'projects': {
            name: project.toLowerCase(),
            display_name: project,
            access_level: accessLevel
          }
        }
      }, function (err) {
        if (err) return done(err, true);
        done(null, true);
      });
    } else {
      var collaboration = {
        project: project,
        invited_by: inviter._id,
        access_level: accessLevel
      };
      InviteCode.findOne({emailed_to: email, consumed_timestamp: null}, function (err, invite) {
        if (err) return done(err);
        if (invite) {
          return updateInvite(invite, collaboration, done);
        }
        sendInvite(inviter, email, collaboration, done);
      });
    }
  });
}
function add(project, email, accessLevel, inviter, done) {
  User.findOne({email: email}, function (err, user) {
    if (err) {
      return done(err);
    }

    if (user) {
      var p = _.find(user.projects, function (p) {
        return p.name === project.toLowerCase();
      });
      if (p) {
        return done('user already a collaborator', true);
      }
      User.update({email: email}, {
        $push: {
          'projects': {
            name: project.toLowerCase(),
            display_name: project,
            access_level: accessLevel
          }
        }
      }, function (err) {
        if (err) return done(err, true);
        done(null, true);
      });
    } else {
      var collaboration = {
        project: project,
        invited_by: inviter._id,
        access_level: accessLevel
      };
      InviteCode.findOne({emailed_to: email, consumed_timestamp: null}, function (err, invite) {
        if (err) return done(err);
        if (invite) {
          return updateInvite(invite, collaboration, done);
        }
        sendInvite(inviter, email, collaboration, done);
      });
    }
  });
}
done(err, userExisted, inviteExisted)