2018-08-10 07:40:25 -04:00
|
|
|
UserGetter = require '../User/UserGetter'
|
2018-11-20 05:48:21 -05:00
|
|
|
UserMembershipHandler = require "../UserMembership/UserMembershipHandler"
|
|
|
|
UserMembershipEntityConfigs = require "../UserMembership/UserMembershipEntityConfigs"
|
2018-08-10 07:40:25 -04:00
|
|
|
logger = require 'logger-sharelatex'
|
|
|
|
|
|
|
|
module.exports = InstitutionsGetter =
|
|
|
|
getConfirmedInstitutions: (userId, callback = (error, institutions) ->) ->
|
|
|
|
UserGetter.getUserFullEmails userId, (error, emailsData) ->
|
|
|
|
return callback error if error?
|
|
|
|
|
|
|
|
confirmedInstitutions = emailsData.filter (emailData) ->
|
2018-08-27 05:37:59 -04:00
|
|
|
emailData.confirmedAt? and emailData.affiliation?.institution?.confirmed
|
2018-08-10 07:40:25 -04:00
|
|
|
.map (emailData) ->
|
|
|
|
emailData.affiliation?.institution
|
|
|
|
|
|
|
|
callback(null, confirmedInstitutions)
|
2018-11-20 05:48:21 -05:00
|
|
|
|
|
|
|
getManagedInstitutions: (user_id, callback = (error, managedInstitutions) ->) ->
|
|
|
|
UserMembershipHandler.getEntitiesByUser UserMembershipEntityConfigs.institution, user_id, callback
|