2018-06-15 06:30:15 -04:00
define [
" base "
] , (App) ->
countriesList = [ { code : " af " , name: " Afghanistan " } , { code : " ax " , name: " Åland Islands " } , { code : " al " , name: " Albania " } , { code : " dz " , name: " Algeria " } , { code : " as " , name: " American Samoa " } , { code : " ad " , name: " Andorra " } , { code : " ao " , name: " Angola " } , { code : " ai " , name: " Anguilla " } , { code : " aq " , name: " Antarctica " } , { code : " ag " , name: " Antigua and Barbuda " } , { code : " ar " , name: " Argentina " } , { code : " am " , name: " Armenia " } , { code : " aw " , name: " Aruba " } , { code : " au " , name: " Australia " } , { code : " at " , name: " Austria " } , { code : " az " , name: " Azerbaijan " } , { code : " bs " , name: " Bahamas " } , { code : " bh " , name: " Bahrain " } , { code : " bd " , name: " Bangladesh " } , { code : " bb " , name: " Barbados " } , { code : " by " , name: " Belarus " } , { code : " be " , name: " Belgium " } , { code : " bz " , name: " Belize " } , { code : " bj " , name: " Benin " } , { code : " bm " , name: " Bermuda " } , { code : " bt " , name: " Bhutan " } , { code : " bo " , name: " Bolivia " } , { code : " bq " , name: " Bonaire, Saint Eustatius and Saba " } , { code : " ba " , name: " Bosnia and Herzegovina " } , { code : " bw " , name: " Botswana " } , { code : " bv " , name: " Bouvet Island " } , { code : " br " , name: " Brazil " } , { code : " io " , name: " British Indian Ocean Territory " } , { code : " vg " , name: " British Virgin Islands " } , { code : " bn " , name: " Brunei " } , { code : " bg " , name: " Bulgaria " } , { code : " bf " , name: " Burkina Faso " } , { code : " bi " , name: " Burundi " } , { code : " kh " , name: " Cambodia " } , { code : " cm " , name: " Cameroon " } , { code : " ca " , name: " Canada " } , { code : " cv " , name: " Cabo Verde " } , { code : " ky " , name: " Cayman Islands " } , { code : " cf " , name: " Central African Republic " } , { code : " td " , name: " Chad " } , { code : " cl " , name: " Chile " } , { code : " cn " , name: " China " } , { code : " cx " , name: " Christmas Island " } , { code : " cc " , name: " Cocos (Keeling) Islands " } , { code : " co " , name: " Colombia " } , { code : " km " , name: " Comoros " } , { code : " cg " , name: " Congo " } , { code : " ck " , name: " Cook Islands " } , { code : " cr " , name: " Costa Rica " } , { code : " ci " , name: " Côte d ' Ivoire " } , { code : " hr " , name: " Croatia " } , { code : " cu " , name: " Cuba " } , { code : " cw " , name: " Curaçao " } , { code : " cy " , name: " Cyprus " } , { code : " cz " , name: " Czech Republic " } , { code : " kp " , name: " Democratic People ' s Republic of Korea " } , { code : " cd " , name: " Democratic Republic of the Congo " } , { code : " dk " , name: " Denmark " } , { code : " dj " , name: " Djibouti " } , { code : " dm " , name: " Dominica " } , { code : " do " , name: " Dominican Republic " } , { code : " ec " , name: " Ecuador " } , { code : " eg " , name: " Egypt " } , { code : " sv " , name: " El Salvador " } , { code : " gq " , name: " Equatorial Guinea " } , { code : " er " , name: " Eritrea " } , { code : " ee " , name: " Estonia " } , { code : " et " , name: " Ethiopia " } , { code : " fk " , name: " Falkland Islands (Malvinas) " } , { code : " fo " , name: " Faroe Islands " } , { code : " fj " , name: " Fiji " } , { code : " fi " , name: " Finland " } , { code : " fr " , name: " France " } , { code : " gf " , name: " French Guiana " } , { code : " pf " , name: " French Polynesia " } , { code : " tf " , name: " French Southern Territories " } , { code : " ga " , name: " Gabon " } , { code : " gm " , name: " Gambia " } , { code : " ge " , name: " Georgia " } , { code : " de " , name: " Germany " } , { code : " gh " , name: " Ghana " } , { code : " gi " , name: " Gibraltar " } , { code : " gr " , name: " Greece " } , { code : " gl " , name: " Greenland " } , { code : " gd " , name: " Grenada " } , { code : " gp " , name: " Guadeloupe " } , { code : " gu " , name: " Guam " } , { code : " gt " , name: " Guatemala " } , { code : " gg " , name: " Guernsey " } , { code : " gn " , name: " Guinea " } , { code : " gw " , name: " Guinea-Bissau " } , { code : " gy " , name: " Guyana " } , { code : " ht " , name: " Haiti " } , { code : " hm " , name: " Heard Island and McDonald Islands " } , { code : " va " , name: " Holy See (Vatican City) " } , { code : " hn " , name: " Honduras " } , { code : " hk " , name: " Hong Kong " } , { code : " hu " , name: " Hungary " } , { code : " is " , name: " Iceland " } , { code : " in " , name: " India " } , { code : " id " , name: " Indonesia " } , { code : " ir " , name: " Iran " } , { code : " iq " , name: " Iraq " } , { code : " ie " , name: " Ireland " } ,
2018-06-19 12:10:55 -04:00
universities = { }
2018-06-15 06:30:15 -04:00
universitiesByDomain = { }
2018-06-28 11:37:36 -04:00
defaultRoleHints = [ " Undergraduate Student " , " Masters Student (MSc, MA, ...) " , " Doctoral Student (PhD, EngD, ...) " , " Postdoc " , " Lecturer " , " Senior Lecturer " , " Reader " , " Associate Professor " , " Assistant Professor " , " Professor " , " Emeritus Professor " ]
defaultDepartmentHints = [ " Aeronautics & Astronautics " , " Anesthesia " , " Anthropology " , " Applied Physics " , " Art & Art History " , " Biochemistry " , " Bioengineering " , " Biology " , " Business School Library " , " Business, Graduate School of " , " Cardiothoracic Surgery " , " Chemical and Systems Biology " , " Chemical Engineering " , " Chemistry " , " Civil & Environmental Engineering " , " Classics " , " Communication " , " Comparative Literature " , " Comparative Medicine " , " Computer Science " , " Dermatology " , " Developmental Biology " , " Earth System Science " , " East Asian Languages and Cultures " , " Economics " , " Education, School of " , " Electrical Engineering " , " Energy Resources Engineering " , " English " , " French and Italian " , " Genetics " , " Geological Sciences " , " Geophysics " , " German Studies " , " Health Research & Policy " , " History " , " Iberian & Latin American Cultures " , " Law Library " , " Law School " , " Linguistics " , " Management Science & Engineering " , " Materials Science & Engineering " , " Mathematics " , " Mechanical Engineering " , " Medical Library " , " Medicine " , " Microbiology & Immunology " , " Molecular & Cellular Physiology " , " Music " , " Neurobiology " , " Neurology & Neurological Sciences " , " Neurosurgery " , " Obstetrics and Gynecology " , " Ophthalmology " , " Orthopaedic Surgery " , " Otolaryngology (Head and Neck Surgery) " , " Pathology " , " Pediatrics " , " Philosophy " , " Physics " , " Political Science " , " Psychiatry and Behavioral Sciences " , " Psychology " , " Radiation Oncology " , " Radiology " , " Religious Studies " , " Slavic Languages and Literature " , " Sociology " , " University Libraries " , " Statistics " , " Structural Biology " , " Surgery " , " Theater and Performance Studies " , " Urology " ]
2018-06-19 12:10:55 -04:00
domainsBlackList = { " overleaf.com " : true }
commonTLDs = [ " br " , " cn " , " co " , " co.jp " , " co.uk " , " com " , " com.au " , " de " , " fr " , " in " , " info " , " io " , " net " , " no " , " ru " , " se " , " us " , " com.tw " , " com.br " , " pl " , " it " , " co.in " , " com.mx " ]
2018-06-22 06:24:14 -04:00
commonDomains = [ " gmail " , " googlemail " , " icloud " , " me " , " yahoo " , " ymail " , " yahoomail " , " hotmail " , " live " , " msn " , " outlook " , " gmx " , " mail " , " aol " , " 163 " , " mac " , " qq " , " o2 " , " libero " , " 126 " ]
2018-06-19 12:10:55 -04:00
for domain in commonDomains
for tld in commonTLDs
domainsBlackList [ " #{ domain } . #{ tld } " ] = true
2018-06-15 06:30:15 -04:00
App . factory " UserAffiliationsDataService " , [ " $http " , " $q " , " _ " , ($http, $q, _) ->
getCountries = () ->
2018-06-28 11:37:36 -04:00
$q . resolve countriesList
getDefaultRoleHints = () ->
$q . resolve defaultRoleHints
getDefaultDepartmentHints = () ->
$q . resolve defaultDepartmentHints
2018-06-15 06:30:15 -04:00
2018-06-19 12:10:55 -04:00
getUserEmails = () ->
$http . get " /user/emails "
. then (response) -> response . data
2018-06-15 06:30:15 -04:00
getUniversitiesFromCountry = (country) ->
if universities [ country . code ] ?
universitiesFromCountry = universities [ country . code ]
else
universitiesFromCountry = $http
2018-06-25 11:13:43 -04:00
. get " /institutions/list " , { params: { country_code: country . code } }
2018-06-15 06:30:15 -04:00
. then (response) -> universities [ country . code ] = response . data
$q . resolve ( universitiesFromCountry )
getUniversityDomainFromPartialDomainInput = (partialDomainInput) ->
if universitiesByDomain [ partialDomainInput ] ?
$q . resolve universitiesByDomain [ partialDomainInput ]
else
2018-06-25 11:13:43 -04:00
$http . get " /institutions/domains " , { params: { hostname: partialDomainInput , limit: 1 } }
2018-06-15 06:30:15 -04:00
. then (response) ->
university = response . data [ 0 ]
2018-06-26 11:50:55 -04:00
if university ? and ! isDomainBlacklisted university . hostname
2018-06-15 06:30:15 -04:00
universitiesByDomain [ university . hostname ] = university
$q . resolve university
else
$q . reject null
2018-06-19 12:10:55 -04:00
addUserEmail = (email) ->
$http . post " /user/emails " , {
2018-06-20 09:22:06 -04:00
email ,
_csrf: window . csrfToken
2018-06-19 12:10:55 -04:00
}
addUserAffiliationWithUnknownUniversity = (email, unknownUniversityName, unknownUniversityCountryCode, role, department) ->
$http . post " /user/emails " , {
email ,
university:
name: unknownUniversityName
country_code: unknownUniversityCountryCode
role ,
2018-06-20 09:22:06 -04:00
department ,
_csrf: window . csrfToken
2018-06-19 12:10:55 -04:00
}
addUserAffiliation = (email, universityId, role, department) ->
$http . post " /user/emails " , {
email ,
university:
id: universityId
role ,
2018-06-20 09:22:06 -04:00
department ,
_csrf: window . csrfToken
2018-06-19 12:10:55 -04:00
}
2018-07-04 11:37:40 -04:00
addRoleAndDepartment = (email, role, department) ->
$http . post " /endorse " , {
email ,
role ,
department ,
_csrf: window . csrfToken
}
2018-06-21 12:18:01 -04:00
setDefaultUserEmail = (email) ->
$http . post " /user/emails/default " , {
2018-07-04 05:56:43 -04:00
email ,
2018-06-21 12:18:01 -04:00
_csrf: window . csrfToken
}
removeUserEmail = (email) ->
2018-06-26 13:50:12 -04:00
$http . post " /user/emails/delete " , {
email ,
_csrf: window . csrfToken
2018-06-21 12:18:01 -04:00
}
2018-06-19 12:10:55 -04:00
isDomainBlacklisted = (domain) ->
domain . toLowerCase ( ) of domainsBlackList
2018-06-15 06:30:15 -04:00
return {
getCountries
2018-06-28 11:37:36 -04:00
getDefaultRoleHints
getDefaultDepartmentHints
2018-06-19 12:10:55 -04:00
getUserEmails
2018-06-15 06:30:15 -04:00
getUniversitiesFromCountry
getUniversityDomainFromPartialDomainInput
2018-06-19 12:10:55 -04:00
addUserEmail
addUserAffiliationWithUnknownUniversity
addUserAffiliation
2018-07-04 11:37:40 -04:00
addRoleAndDepartment
2018-06-21 12:18:01 -04:00
setDefaultUserEmail
removeUserEmail
2018-06-19 12:10:55 -04:00
isDomainBlacklisted
2018-06-15 06:30:15 -04:00
}
]