Merge pull request #13384 from overleaf/mj-unused-angular-settings

[web] Remove unused angular settings

GitOrigin-RevId: 84621044f83654c2290119f7203c8aa68e03392f
This commit is contained in:
Mathias Jakobsen 2023-06-26 10:33:14 +02:00 committed by Copybot
parent af76768eb7
commit ddf62722b1
6 changed files with 0 additions and 882 deletions

View file

@ -1,38 +0,0 @@
mixin reconfirmAffiliationNotification(location)
.reconfirm-notification(ng-controller="UserAffiliationsReconfirmController")
div(ng-if="!reconfirm[userEmail.email].reconfirmationSent" style="width:100%;")
i.fa.fa-warning
button.btn-reconfirm.btn.btn-sm.btn-info(
data-location=location
ng-if="!ui.sentReconfirmation"
ng-click="requestReconfirmation($event, userEmail)"
ng-disabled="ui.isMakingRequest"
) #{translate("confirm_affiliation")}
| !{translate("are_you_still_at", {institutionName: '{{userEmail.affiliation.institution.name}}'}, ['strong'])} 
if location == '/user/settings'
| !{translate('please_reconfirm_institutional_email', {}, [{ name: 'span' }])}
span(ng-if="userEmail.default")  #{translate('need_to_add_new_primary_before_remove')}
else
| !{translate("please_reconfirm_institutional_email", {}, [{name: 'a', attrs: {href: '/user/settings?remove={{userEmail.email}}' }}])}
|  
a(href="/learn/how-to/Institutional_Email_Reconfirmation") #{translate("learn_more")}
div(ng-if="reconfirm[userEmail.email].reconfirmationSent")
| !{translate("please_check_your_inbox_to_confirm", {institutionName: '{{userEmail.affiliation.institution.name}}'}, ['strong'])}
|  
button(
class="btn-inline-link"
ng-click="requestReconfirmation($event, userEmail)"
ng-disabled="ui.isMakingRequest"
) #{translate('resend_confirmation_email')}
mixin reconfirmedAffiliationNotification()
.alert.alert-info
.reconfirm-notification
div(style="width:100%;")
//- extra div for flex styling
| !{translate("your_affiliation_is_confirmed", {institutionName: '{{userEmail.affiliation.institution.name}}'}, ['strong'])} #{translate('thank_you_exclamation')}

View file

@ -10,7 +10,6 @@
*/
import './main/token-access'
import './main/project-list/index'
import './main/account-settings'
import './main/clear-sessions'
import './main/account-upgrade-angular'
import './main/plans'
@ -22,9 +21,6 @@ import './main/translations'
import './main/annual-upgrade'
import './main/subscription/team-invite-controller'
import './main/learn'
import './main/affiliations/components/inputSuggestions'
import './main/affiliations/factories/UserAffiliationsDataService'
import './main/affiliations/controllers/UserAffiliationsReconfirmController'
import './main/keys'
import './main/importing'
import './directives/autoSubmitForm'

View file

@ -1,116 +0,0 @@
import App from '../base'
App.controller(
'AccountSettingsController',
function (
$scope,
$http,
$modal,
// eslint-disable-next-line camelcase
eventTracking,
UserAffiliationsDataService
) {
$scope.subscribed = true
$scope.unsubscribe = function () {
$scope.unsubscribing = true
return $http({
method: 'DELETE',
url: '/user/newsletter/unsubscribe',
headers: {
'X-CSRF-Token': window.csrfToken,
},
})
.then(function () {
$scope.unsubscribing = false
$scope.subscribed = false
})
.catch(() => ($scope.unsubscribing = true))
}
$scope.deleteAccount = function () {
$modal.open({
templateUrl: 'deleteAccountModalTemplate',
controller: 'DeleteAccountModalController',
resolve: {
userDefaultEmail() {
return UserAffiliationsDataService.getUserDefaultEmail()
.then(
defaultEmailDetails =>
(defaultEmailDetails != null
? defaultEmailDetails.email
: undefined) || null
)
.catch(() => null)
},
},
})
}
$scope.upgradeIntegration = service =>
eventTracking.send('subscription-funnel', 'settings-page', service)
}
)
App.controller(
'DeleteAccountModalController',
function ($scope, $modalInstance, $timeout, $http, userDefaultEmail) {
$scope.state = {
isValid: false,
deleteText: '',
password: '',
confirmSharelatexDelete: false,
inflight: false,
error: null,
}
$scope.userDefaultEmail = userDefaultEmail
$modalInstance.opened.then(() =>
$timeout(() => $scope.$broadcast('open'), 700)
)
$scope.checkValidation = () =>
($scope.state.isValid =
userDefaultEmail != null &&
$scope.state.deleteText.toLowerCase() ===
userDefaultEmail.toLowerCase() &&
$scope.state.password.length > 0 &&
$scope.state.confirmSharelatexDelete)
$scope.delete = function () {
$scope.state.inflight = true
$scope.state.error = null
return $http({
method: 'POST',
url: '/user/delete',
headers: {
'X-CSRF-Token': window.csrfToken,
'Content-Type': 'application/json',
},
data: {
password: $scope.state.password,
},
disableAutoLoginRedirect: true, // we want to handle errors ourselves
})
.then(function () {
$modalInstance.close()
$scope.state.inflight = false
$scope.state.error = null
setTimeout(() => (window.location = '/login'), 1000)
})
.catch(function (response) {
const { data, status } = response
$scope.state.inflight = false
if (status === 403) {
$scope.state.error = { code: 'InvalidCredentialsError' }
} else if (data.error) {
$scope.state.error = { code: data.error }
} else {
$scope.state.error = { code: 'UserDeletionError' }
}
})
}
$scope.cancel = () => $modalInstance.dismiss('cancel')
}
)

View file

@ -1,98 +0,0 @@
/* eslint-disable
max-len,
no-return-assign,
*/
// TODO: This file was created by bulk-decaffeinate.
// Fix any style issues and re-enable lint.
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
import App from '../../../base'
const inputSuggestionsController = function ($scope, $element, $attrs, Keys) {
const ctrl = this
ctrl.showHint = false
ctrl.hasFocus = false
ctrl.handleFocus = function () {
ctrl.hasFocus = true
return (ctrl.suggestion = null)
}
ctrl.handleBlur = function () {
ctrl.showHint = false
ctrl.hasFocus = false
ctrl.suggestion = null
return ctrl.onBlur()
}
ctrl.handleKeyDown = function ($event) {
if (
($event.which === Keys.TAB || $event.which === Keys.ENTER) &&
ctrl.suggestion != null &&
ctrl.suggestion !== ''
) {
$event.preventDefault()
ctrl.localNgModel += ctrl.suggestion
}
ctrl.suggestion = null
return (ctrl.showHint = false)
}
$scope.$watch('$ctrl.localNgModel', function (newVal, oldVal) {
if (ctrl.hasFocus && newVal !== oldVal) {
ctrl.suggestion = null
ctrl.showHint = false
return ctrl
.getSuggestion({ userInput: newVal })
.then(function (suggestion) {
if (suggestion != null && newVal === ctrl.localNgModel) {
ctrl.showHint = true
return (ctrl.suggestion = suggestion.replace(newVal, ''))
}
})
.catch(() => (ctrl.suggestion = null))
}
})
}
export default App.component('inputSuggestions', {
bindings: {
localNgModel: '=ngModel',
localNgModelOptions: '=?ngModelOptions',
getSuggestion: '&',
onBlur: '&?',
inputId: '@?',
inputName: '@?',
inputPlaceholder: '@?',
inputType: '@?',
inputRequired: '=?',
},
controller: inputSuggestionsController,
template: [
'<div class="input-suggestions">',
'<div class="form-control input-suggestions-shadow">',
'<span ng-bind="$ctrl.localNgModel"',
' class="input-suggestions-shadow-existing"',
' ng-show="$ctrl.showHint">',
'</span>',
'<span ng-bind="$ctrl.suggestion"',
' class="input-suggestions-shadow-suggested"',
' ng-show="$ctrl.showHint">',
'</span>',
'</div>',
'<input type="text"',
' class="form-control input-suggestions-main"',
' ng-focus="$ctrl.handleFocus()"',
' ng-keyDown="$ctrl.handleKeyDown($event)"',
' ng-blur="$ctrl.handleBlur()"',
' ng-model="$ctrl.localNgModel"',
' ng-model-options="$ctrl.localNgModelOptions"',
' ng-model-options="{ debounce: 50 }"',
' ng-attr-id="{{ ::$ctrl.inputId }}"',
' ng-attr-placeholder="{{ ::$ctrl.inputPlaceholder }}"',
' ng-attr-type="{{ ::$ctrl.inputType }}"',
' ng-attr-name="{{ ::$ctrl.inputName }}"',
' autofocus="::$ctrl.focusOnRender"',
' ng-required="::$ctrl.inputRequired">',
'</div>',
].join(''),
})

View file

@ -1,74 +0,0 @@
import _ from 'lodash'
import App from '../../../base'
import getMeta from '../../../utils/meta'
export default App.controller(
'UserAffiliationsReconfirmController',
function ($scope, $http, $window) {
const samlInitPath = ExposedSettings.samlInitPath
$scope.reconfirm = {}
$scope.ui = $scope.ui || {} // $scope.ui inherited on settings page
$scope.userEmails = getMeta('ol-userEmails')
$scope.reconfirmedViaSAML = getMeta('ol-reconfirmedViaSAML')
// For portals:
const portalAffiliation = getMeta('ol-portalAffiliation')
if (portalAffiliation) {
$scope.portalInReconfirmNotificationPeriod =
portalAffiliation && portalAffiliation.inReconfirmNotificationPeriod
$scope.userEmail = $scope.portalInReconfirmNotificationPeriod // mixin to show notification uses userEmail
}
// For settings page:
$scope.reconfirmationRemoveEmail = getMeta('ol-reconfirmationRemoveEmail')
// For dashboard:
$scope.allInReconfirmNotificationPeriods = getMeta(
'ol-allInReconfirmNotificationPeriods'
)
function sendReconfirmEmail(email) {
$scope.ui.hasError = false
$scope.ui.isMakingRequest = true
$http
.post('/user/emails/send-reconfirmation', {
email,
_csrf: window.csrfToken,
})
.then(() => {
$scope.reconfirm[email].reconfirmationSent = true
})
.catch(_ => {
$scope.ui.hasError = true
})
.finally(() => ($scope.ui.isMakingRequest = false))
}
$scope.requestReconfirmation = function (obj, userEmail) {
const email = userEmail.email
// For the settings page, disable other parts of affiliation UI
$scope.ui.isMakingRequest = true
$scope.ui.isProcessing = true
// create UI scope for requested email
$scope.reconfirm[email] = $scope.reconfirm[email] || {} // keep existing scope for resend email requests
const location = obj.currentTarget.getAttribute('data-location')
const institutionId = _.get(userEmail, [
'affiliation',
'institution',
'id',
])
const ssoEnabled = _.get(userEmail, [
'affiliation',
'institution',
'ssoEnabled',
])
if (ssoEnabled) {
$window.location.href = `${samlInitPath}?university_id=${institutionId}&reconfirm=${location}`
} else {
sendReconfirmEmail(email)
}
}
}
)

View file

@ -1,552 +0,0 @@
import _ from 'lodash'
import App from '../../../base'
const 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' },
{ code: 'im', name: 'Isle of Man' },
{ code: 'il', name: 'Israel' },
{ code: 'it', name: 'Italy' },
{ code: 'jm', name: 'Jamaica' },
{ code: 'jp', name: 'Japan' },
{ code: 'je', name: 'Jersey' },
{ code: 'jo', name: 'Jordan' },
{ code: 'kz', name: 'Kazakhstan' },
{ code: 'ke', name: 'Kenya' },
{ code: 'ki', name: 'Kiribati' },
{ code: 'xk', name: 'Kosovo' },
{ code: 'kw', name: 'Kuwait' },
{ code: 'kg', name: 'Kyrgyzstan' },
{ code: 'la', name: 'Laos' },
{ code: 'lv', name: 'Latvia' },
{ code: 'lb', name: 'Lebanon' },
{ code: 'ls', name: 'Lesotho' },
{ code: 'lr', name: 'Liberia' },
{ code: 'ly', name: 'Libya' },
{ code: 'li', name: 'Liechtenstein' },
{ code: 'lt', name: 'Lithuania' },
{ code: 'lu', name: 'Luxembourg' },
{ code: 'mo', name: 'Macao' },
{ code: 'mk', name: 'Macedonia' },
{ code: 'mg', name: 'Madagascar' },
{ code: 'mw', name: 'Malawi' },
{ code: 'my', name: 'Malaysia' },
{ code: 'mv', name: 'Maldives' },
{ code: 'ml', name: 'Mali' },
{ code: 'mt', name: 'Malta' },
{ code: 'mh', name: 'Marshall Islands' },
{ code: 'mq', name: 'Martinique' },
{ code: 'mr', name: 'Mauritania' },
{ code: 'mu', name: 'Mauritius' },
{ code: 'yt', name: 'Mayotte' },
{ code: 'mx', name: 'Mexico' },
{ code: 'fm', name: 'Micronesia' },
{ code: 'md', name: 'Moldova' },
{ code: 'mc', name: 'Monaco' },
{ code: 'mn', name: 'Mongolia' },
{ code: 'me', name: 'Montenegro' },
{ code: 'ms', name: 'Montserrat' },
{ code: 'ma', name: 'Morocco' },
{ code: 'mz', name: 'Mozambique' },
{ code: 'mm', name: 'Myanmar' },
{ code: 'na', name: 'Namibia' },
{ code: 'nr', name: 'Nauru' },
{ code: 'np', name: 'Nepal' },
{ code: 'nl', name: 'Netherlands' },
{ code: 'an', name: 'Netherlands Antilles' },
{ code: 'nc', name: 'New Caledonia' },
{ code: 'nz', name: 'New Zealand' },
{ code: 'ni', name: 'Nicaragua' },
{ code: 'ne', name: 'Niger' },
{ code: 'ng', name: 'Nigeria' },
{ code: 'nu', name: 'Niue' },
{ code: 'nf', name: 'Norfolk Island' },
{ code: 'mp', name: 'Northern Mariana Islands' },
{ code: 'no', name: 'Norway' },
{ code: 'om', name: 'Oman' },
{ code: 'pk', name: 'Pakistan' },
{ code: 'pw', name: 'Palau' },
{ code: 'ps', name: 'Palestine' },
{ code: 'pa', name: 'Panama' },
{ code: 'pg', name: 'Papua New Guinea' },
{ code: 'py', name: 'Paraguay' },
{ code: 'pe', name: 'Peru' },
{ code: 'ph', name: 'Philippines' },
{ code: 'pn', name: 'Pitcairn' },
{ code: 'pl', name: 'Poland' },
{ code: 'pt', name: 'Portugal' },
{ code: 'pr', name: 'Puerto Rico' },
{ code: 'qa', name: 'Qatar' },
{ code: 'kr', name: 'Republic of Korea' },
{ code: 're', name: 'Réunion' },
{ code: 'ro', name: 'Romania' },
{ code: 'ru', name: 'Russia' },
{ code: 'rw', name: 'Rwanda' },
{ code: 'bl', name: 'Saint Barthélemy' },
{ code: 'sh', name: 'Saint Helena, Ascension and Tristan da Cunha' },
{ code: 'kn', name: 'Saint Kitts and Nevis' },
{ code: 'lc', name: 'Saint Lucia' },
{ code: 'mf', name: 'Saint Martin' },
{ code: 'pm', name: 'Saint Pierre and Miquelon' },
{ code: 'vc', name: 'Saint Vincent and the Grenadines' },
{ code: 'ws', name: 'Samoa' },
{ code: 'sm', name: 'San Marino' },
{ code: 'st', name: 'Sao Tome and Principe' },
{ code: 'sa', name: 'Saudi Arabia' },
{ code: 'sn', name: 'Senegal' },
{ code: 'rs', name: 'Serbia' },
{ code: 'sc', name: 'Seychelles' },
{ code: 'sl', name: 'Sierra Leone' },
{ code: 'sg', name: 'Singapore' },
{ code: 'sx', name: 'Sint Maarten' },
{ code: 'sk', name: 'Slovakia' },
{ code: 'si', name: 'Slovenia' },
{ code: 'sb', name: 'Solomon Islands' },
{ code: 'so', name: 'Somalia' },
{ code: 'za', name: 'South Africa' },
{ code: 'gs', name: 'South Georgia and the South Sandwich Islands' },
{ code: 'ss', name: 'South Sudan' },
{ code: 'es', name: 'Spain' },
{ code: 'lk', name: 'Sri Lanka' },
{ code: 'sd', name: 'Sudan' },
{ code: 'sr', name: 'Suriname' },
{ code: 'sj', name: 'Svalbard and Jan Mayen' },
{ code: 'sz', name: 'Swaziland' },
{ code: 'se', name: 'Sweden' },
{ code: 'ch', name: 'Switzerland' },
{ code: 'sy', name: 'Syria' },
{ code: 'tw', name: 'Taiwan' },
{ code: 'tj', name: 'Tajikistan' },
{ code: 'tz', name: 'Tanzania' },
{ code: 'th', name: 'Thailand' },
{ code: 'tl', name: 'Timor-Leste' },
{ code: 'tg', name: 'Togo' },
{ code: 'tk', name: 'Tokelau' },
{ code: 'to', name: 'Tonga' },
{ code: 'tt', name: 'Trinidad and Tobago' },
{ code: 'tn', name: 'Tunisia' },
{ code: 'tr', name: 'Turkey' },
{ code: 'tm', name: 'Turkmenistan' },
{ code: 'tc', name: 'Turks and Caicos Islands' },
{ code: 'tv', name: 'Tuvalu' },
{ code: 'vi', name: 'U.S. Virgin Islands' },
{ code: 'ug', name: 'Uganda' },
{ code: 'ua', name: 'Ukraine' },
{ code: 'ae', name: 'United Arab Emirates' },
{ code: 'gb', name: 'United Kingdom' },
{ code: 'us', name: 'United States of America' },
{ code: 'um', name: 'United States Minor Outlying Islands' },
{ code: 'uy', name: 'Uruguay' },
{ code: 'uz', name: 'Uzbekistan' },
{ code: 'vu', name: 'Vanuatu' },
{ code: 've', name: 'Venezuela' },
{ code: 'vn', name: 'Vietnam' },
{ code: 'wf', name: 'Wallis and Futuna' },
{ code: 'eh', name: 'Western Sahara' },
{ code: 'ye', name: 'Yemen' },
{ code: 'zm', name: 'Zambia' },
{ code: 'zw', name: 'Zimbabwe' },
]
const universities = {}
const universitiesByDomain = {}
const defaultRoleHints = [
'Undergraduate Student',
'Masters Student (MSc, MA, ...)',
'Doctoral Student (PhD, EngD, ...)',
'Postdoc',
'Lecturer',
'Senior Lecturer',
'Reader',
'Associate Professor ',
'Assistant Professor ',
'Professor',
'Emeritus Professor',
]
const 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',
]
const domainsBlackList = { 'overleaf.com': true }
const 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',
]
const commonDomains = [
'gmail',
'googlemail',
'icloud',
'me',
'yahoo',
'ymail',
'yahoomail',
'hotmail',
'live',
'msn',
'outlook',
'gmx',
'mail',
'aol',
'163',
'mac',
'qq',
'o2',
'libero',
'126',
'protonmail',
'yandex',
'yeah',
'web',
'foxmail',
]
for (const domain of commonDomains) {
for (const tld of commonTLDs) {
domainsBlackList[`${domain}.${tld}`] = true
}
}
App.factory('UserAffiliationsDataService', function ($http, $q) {
const getCountries = () => $q.resolve(countriesList)
const getDefaultRoleHints = () => $q.resolve(defaultRoleHints)
const getDefaultDepartmentHints = () => $q.resolve(defaultDepartmentHints)
const getUserEmails = () =>
$http.get('/user/emails').then(response => response.data)
const getUserEmailsEnsureAffiliation = () =>
$http
.get('/user/emails?ensureAffiliation=true')
.then(response => response.data)
const getUserDefaultEmail = () =>
getUserEmails().then(userEmails =>
_.find(userEmails, userEmail => userEmail.default)
)
const getUniversitiesFromCountry = function (country) {
let universitiesFromCountry
if (universities[country.code] != null) {
universitiesFromCountry = universities[country.code]
} else {
universitiesFromCountry = $http
.get('/institutions/list', {
params: { country_code: country.code },
})
.then(response => (universities[country.code] = response.data))
}
return $q.resolve(universitiesFromCountry)
}
const getUniversityDomainFromPartialDomainInput = function (
partialDomainInput
) {
if (universitiesByDomain[partialDomainInput] != null) {
return $q.resolve(universitiesByDomain[partialDomainInput])
} else {
return $http
.get('/institutions/domains', {
params: { hostname: partialDomainInput, limit: 1 },
})
.then(function (response) {
const university = response.data[0]
if (university != null && !isDomainBlacklisted(university.hostname)) {
universitiesByDomain[university.hostname] = university
return $q.resolve(university)
} else {
return $q.reject(null)
}
})
}
}
const getUniversityDetails = universityId =>
$http
.get(`/institutions/list/${universityId}`)
.then(response => response.data)
const addUserEmail = email =>
$http.post('/user/emails', {
email,
_csrf: window.csrfToken,
})
const addUserAffiliationWithUnknownUniversity = (
email,
unknownUniversityName,
unknownUniversityCountryCode,
role,
department
) =>
$http.post('/user/emails', {
email,
university: {
name: unknownUniversityName,
country_code: unknownUniversityCountryCode,
},
role,
department,
_csrf: window.csrfToken,
})
const addUserAffiliation = (email, universityId, role, department) =>
$http.post('/user/emails', {
email,
university: {
id: universityId,
},
role,
department,
_csrf: window.csrfToken,
})
const addRoleAndDepartment = (email, role, department) =>
$http.post('/user/emails/endorse', {
email,
role,
department,
_csrf: window.csrfToken,
})
const setDefaultUserEmail = email =>
$http.post('/user/emails/default', {
email,
_csrf: window.csrfToken,
})
const removeUserEmail = email =>
$http.post('/user/emails/delete', {
email,
_csrf: window.csrfToken,
})
const resendConfirmationEmail = email =>
$http.post('/user/emails/resend_confirmation', {
email,
_csrf: window.csrfToken,
})
const isDomainBlacklisted = domain => domain.toLowerCase() in domainsBlackList
return {
getCountries,
getDefaultRoleHints,
getDefaultDepartmentHints,
getUserEmails,
getUserEmailsEnsureAffiliation,
getUserDefaultEmail,
getUniversitiesFromCountry,
getUniversityDomainFromPartialDomainInput,
getUniversityDetails,
addUserEmail,
addUserAffiliationWithUnknownUniversity,
addUserAffiliation,
addRoleAndDepartment,
setDefaultUserEmail,
removeUserEmail,
resendConfirmationEmail,
isDomainBlacklisted,
}
})