cleanup and tests for v2 affiliations confirmation

This commit is contained in:
hugh-obrien
2018-10-07 16:40:26 +01:00
parent af3cc01496
commit 65ecdf84f4
3 changed files with 66 additions and 2 deletions
@@ -1,7 +1,16 @@
logger = require("logger-sharelatex")
UserGetter = require("../User/UserGetter")
{ addAffiliation } = require("../Institutions/InstitutionsAPI")
async = require('async')
module.exports = InstitutionsController =
confirmDomain: (req, res, next) ->
hostname = req.body.hostname
UserGetter.getUsersByHostname hostname, {_id:1, emails:1}, (error, users) ->
res.json {hostname: hostname, wub: users}
async.map users, (user, error) ->
email = user.emails.filter (email) -> email.hostname == hostname
addAffiliation user._id, email[0].email, {}, (error) =>
if error?
logger.err error: error, 'problem adding affiliation while confirming hostname'
return next(error)
res.sendStatus 200