mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 06:03:45 +01:00
store reversed hostname and review fixes for v2 university domain confirmation
This commit is contained in:
@@ -5,12 +5,19 @@ async = require('async')
|
||||
|
||||
module.exports = InstitutionsController =
|
||||
confirmDomain: (req, res, next) ->
|
||||
hostname = req.body.hostname
|
||||
hostname = req.body.hostname.split('').reverse().join('')
|
||||
UserGetter.getUsersByHostname hostname, {_id:1, emails:1}, (error, 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 fetching users by hostname'
|
||||
return next(error)
|
||||
async.map users, ((user) ->
|
||||
matchingEmails = user.emails.filter (email) -> email.hostname == hostname
|
||||
for email in matchingEmails
|
||||
addAffiliation user._id, email.email, {confirmedAt: email.confirmedAt}, (error) =>
|
||||
if error?
|
||||
logger.err error: error, 'problem adding affiliation while confirming hostname'
|
||||
return next(error)
|
||||
), (error) ->
|
||||
if error?
|
||||
logger.err error: error, 'problem adding affiliation while confirming hostname'
|
||||
return next(error)
|
||||
res.sendStatus 200
|
||||
|
||||
@@ -66,7 +66,7 @@ module.exports = UserUpdater =
|
||||
logger.err error: error, 'problem adding affiliation while adding email'
|
||||
return callback(error)
|
||||
|
||||
hostname = newEmail.split('@')[1]
|
||||
hostname = newEmail.split('@')[1].split('').reverse().join('')
|
||||
update = $push: emails: email: newEmail, createdAt: new Date(), hostname: hostname
|
||||
@updateUser userId, update, (error) ->
|
||||
if error?
|
||||
|
||||
@@ -331,7 +331,7 @@ module.exports = class Router
|
||||
),
|
||||
AuthenticationController.httpAuth,
|
||||
CompileController.getFileFromClsiWithoutUser
|
||||
publicApiRouter.post '/api/institutions/confirm_affiliation_domain', AuthenticationController.httpAuth, InstitutionsController.confirmDomain
|
||||
publicApiRouter.post '/api/institutions/confirm_university_domain', AuthenticationController.httpAuth, InstitutionsController.confirmDomain
|
||||
|
||||
webRouter.get '/teams', (req, res, next) ->
|
||||
# Match v1 behaviour - if the user is signed in, show their teams list
|
||||
|
||||
@@ -10,20 +10,22 @@ describe "InstitutionsController", ->
|
||||
|
||||
beforeEach ->
|
||||
@logger = err: sinon.stub(), log: ->
|
||||
@host = "mit.edu".split('').reverse().join('')
|
||||
@stubbedUser1 =
|
||||
_id: "3131231"
|
||||
name:"bob"
|
||||
email:"hello@world.com"
|
||||
emails: [
|
||||
{"email":"stubb1@mit.edu","hostname":"mit.edu"},
|
||||
{"email":"test@test.com","hostname":"test.com"}
|
||||
{"email":"stubb1@mit.edu","hostname":@host},
|
||||
{"email":"test@test.com","hostname":"test.com"},
|
||||
{"email":"another@mit.edu","hostname":@host}
|
||||
]
|
||||
@stubbedUser2 =
|
||||
_id: "3131232"
|
||||
name:"test"
|
||||
email:"hello2@world.com"
|
||||
emails: [
|
||||
{"email":"subb2@mit.edu","hostname":"mit.edu"}
|
||||
{"email":"subb2@mit.edu","hostname":@host}
|
||||
]
|
||||
|
||||
@getUsersByHostname = sinon.stub().callsArgWith(2, null, [ @stubbedUser1, @stubbedUser2 ])
|
||||
@@ -48,7 +50,8 @@ describe "InstitutionsController", ->
|
||||
@req.body.hostname = "mit.edu"
|
||||
@res.sendStatus = (code) =>
|
||||
@getUsersByHostname.calledOnce.should.equal true
|
||||
@addAffiliation.calledTwice.should.equal true
|
||||
@addAffiliation.calledThrice.should.equal true
|
||||
@addAffiliation.calledWith(@stubbedUser1._id, @stubbedUser1.emails[0].email).should.equal true
|
||||
@addAffiliation.calledWith(@stubbedUser1._id, @stubbedUser1.emails[2].email).should.equal true
|
||||
done()
|
||||
@InstitutionsController.confirmDomain @req, @res, @next
|
||||
|
||||
@@ -90,7 +90,7 @@ describe "UserUpdater", ->
|
||||
@UserUpdater.addEmailAddress @stubbedUser._id, @newEmail, (err)=>
|
||||
@UserGetter.ensureUniqueEmailAddress.called.should.equal true
|
||||
should.not.exist(err)
|
||||
hostname = @newEmail.split('@')[1]
|
||||
hostname = @newEmail.split('@')[1].split('').reverse().join('')
|
||||
@UserUpdater.updateUser.calledWith(
|
||||
@stubbedUser._id,
|
||||
$push: { emails: { email: @newEmail, createdAt: sinon.match.date, hostname: hostname } }
|
||||
|
||||
Reference in New Issue
Block a user