Merge pull request #10875 from overleaf/mj-angular-settings-cleanup

[web] Clean up old angular settings templates

GitOrigin-RevId: fecc909727c60268aa039693a10ba166ae8a00a2
This commit is contained in:
Mathias Jakobsen 2022-12-20 13:02:03 +00:00 committed by Copybot
parent 38cc3394e3
commit 4c271965fe
6 changed files with 0 additions and 968 deletions

View file

@ -1,401 +0,0 @@
include ../../_mixins/reconfirm_affiliation
mixin aboutInstitutionLink()
a(href="/learn/how-to/Institutional_Login") #{translate("find_out_more_about_institution_login")}.
mixin btnMakePrimaryDisabled(tooltip)
div(
tooltip=tooltip
tooltip-enable="!ui.isMakingRequest"
)
button.btn.btn-sm.btn-primary.affiliations-table-inline-action(
disabled
type="button"
) #{translate("make_primary")}
mixin btnRemoveEmail()
.affiliations-table-inline-action-disabled-wrapper(ng-if="userEmail.default")
div(
tooltip=translate("please_change_primary_to_remove")
tooltip-enable="!ui.isMakingRequest"
tooltip-placement="left"
)
button.btn.btn-sm.btn-danger(disabled)
i.fa.fa-fw.fa-trash(aria-hidden="true")
span.sr-only #{translate("please_change_primary_to_remove")}
button.btn.btn-sm.btn-danger.affiliations-table-inline-action(
ng-if="!userEmail.default"
ng-click="removeUserEmail(userEmail)"
ng-disabled="ui.isMakingRequest"
tooltip=translate("remove")
type="button"
)
i.fa.fa-fw.fa-trash(aria-hidden="true")
span.sr-only #{translate("remove")}
form.row(
ng-controller="UserAffiliationsController"
name="affiliationsForm"
)
.col-md-12
h3 #{translate("emails_and_affiliations_title")}
p.small #{translate("emails_and_affiliations_explanation")}
p.small !{translate("change_primary_email_address_instructions", {}, [{name: "strong"}, { name: "a", attrs: { href: "/learn/how-to/Keeping_your_account_secure"}}])}
table.table.affiliations-table
thead
tr
th.affiliations-table-email #{translate("email")}
th.affiliations-table-institution #{translate("institution_and_role")}
th.affiliations-table-inline-actions
tbody
tr(
ng-repeat-start="userEmail in userEmails"
)
td
| {{ userEmail.email + (userEmail.default ? ' (primary)' : '') }}
div(ng-if="!userEmail.confirmedAt").small
strong #{translate('unconfirmed')}.
span(ng-if="!userEmail.ssoAvailable")  #{translate('please_check_your_inbox')}.
br
a(
href,
ng-click="resendConfirmationEmail(userEmail)",
ng-if="!userEmail.ssoAvailable"
) #{translate('resend_confirmation_email')}
div(ng-if="userEmail.confirmedAt && userEmail.affiliation.institution && userEmail.affiliation.institution.confirmed && userEmail.affiliation.licence && userEmail.affiliation.licence != 'free'").small
span.label.label-primary #{translate("professional")}
td
div(ng-if="userEmail.affiliation.institution")
div {{ userEmail.affiliation.institution.name }}
span.small
a(
href
ng-if="!isChangingAffiliation(userEmail.email) && !userEmail.affiliation.role && !userEmail.affiliation.department"
ng-click="changeAffiliation(userEmail);"
) #{translate("add_role_and_department")}
div.small(
ng-if="!isChangingAffiliation(userEmail.email) && (userEmail.affiliation.role || userEmail.affiliation.department)"
)
span(ng-if="userEmail.affiliation.role") {{ userEmail.affiliation.role }}
span(ng-if="userEmail.affiliation.role && userEmail.affiliation.department") , 
span(ng-if="userEmail.affiliation.department") {{ userEmail.affiliation.department }}
br
a(
href
ng-click="changeAffiliation(userEmail);"
) #{translate("change")}
.affiliation-change-container(
ng-if="isChangingAffiliation(userEmail.email)"
)
affiliation-form(
affiliation-data="affiliationToChange"
show-university-and-country="false"
show-role-and-department="true"
)
.affiliation-change-actions.small
button.btn.btn-sm.btn-primary(
ng-click="saveAffiliationChange(userEmail);"
ng-disabled="!(affiliationToChange.role && affiliationToChange.department)"
type="button"
) #{translate("save_or_cancel-save")}
|  #{translate("save_or_cancel-or" )} 
a(
href
ng-click="cancelAffiliationChange();"
) #{translate("save_or_cancel-cancel")}
td.affiliations-table-inline-actions
// Disabled buttons don't work with tooltips, due to pointer-events: none,
// so create a wrapper for the tooltip
span(ng-if="!userEmail.default && (!userEmail.confirmedAt || ui.isMakingRequest) && !institutionAlreadyLinked(userEmail) && !inReconfirmNotificationPeriod(userEmail)")
.affiliations-table-inline-action-disabled-wrapper(ng-if="userEmail.ssoAvailable")
+btnMakePrimaryDisabled(translate("please_link_before_making_primary"))
.affiliations-table-inline-action-disabled-wrapper(ng-if="!userEmail.ssoAvailable")
+btnMakePrimaryDisabled(translate("please_confirm_your_email_before_making_it_default"))
.affiliations-table-inline-action-disabled-wrapper(ng-if="!userEmail.default && inReconfirmNotificationPeriod(userEmail)")
+btnMakePrimaryDisabled(translate("please_reconfirm_your_affiliation_before_making_this_primary"))
button.btn.btn-sm.btn-primary.affiliations-table-inline-action(
tooltip=translate("make_email_primary_description")
ng-if="!userEmail.default && (userEmail.confirmedAt && !ui.isMakingRequest) && !inReconfirmNotificationPeriod(userEmail)"
ng-click="setDefaultUserEmail(userEmail)"
type="button"
) #{translate("make_primary")}
|  
+btnRemoveEmail()
tr.affiliations-table-saml-row(ng-if="userEmail.affiliation && userEmail.affiliation && userEmail.ssoAvailable")
td
td(ng-attr-colspan="{{userEmail.samlProviderId ? '2' : '1'}}" ng-class="institutionAlreadyLinked(userEmail) ? '' : 'with-border'")
p.small(ng-if="userEmail.samlProviderId")
| !{translate("acct_linked_to_institution_acct", {institutionName: '{{userEmail.affiliation.institution.name}}'})}
div(ng-if="!userEmail.samlProviderId && !institutionAlreadyLinked(userEmail)")
//- this email is not linked to institution login but
//- cannot have multiple emails at same institution linked for "institution login"
//- so check if institution is already linked
p.small
| !{translate("can_link_your_institution_acct", {institutionName: '{{userEmail.affiliation.institution.name}}'})}
p.small
| !{translate("doing_this_allow_log_in_through_institution")} 
+aboutInstitutionLink()
td.with-border.affiliations-table-inline-actions(ng-if="!userEmail.samlProviderId && !institutionAlreadyLinked(userEmail)")
button.btn-sm.btn.btn-info(
ng-click="linkInstitutionAcct(userEmail.email, userEmail.affiliation.institution.id)"
ng-disabled="ui.isMakingRequest"
type="button"
)
| #{translate("link_accounts")}
tr(
class="reconfirm-row"
ng-if="userEmail.samlIdentifier && userEmail.samlIdentifier.providerId === reconfirmedViaSAML"
)
td(colspan="3")
+reconfirmedAffiliationNotification()
tr(
class="reconfirm-row"
ng-repeat-end
)
td(
colspan="3"
ng-if="userEmail.affiliation && userEmail.affiliation.inReconfirmNotificationPeriod"
)
div(ng-class="{'alert alert-info': reconfirmationRemoveEmail === userEmail.email}")
+reconfirmAffiliationNotification('/user/settings')
tr(ng-if="showInstitutionalLeaversSurvey")
td(colspan="3")
div.alert.alert-info
button.close.pull-right(ng-click="dismissInstitutionalLeaversSurvey()")
span(aria-hidden="true") ×
span.sr-only #{translate("close")}
strong #{translate('limited_offer')}:
|
| #{translate('institutional_leavers_survey_notification')}
|
a.btn-inline-link(href="https://docs.google.com/forms/d/e/1FAIpQLSfYdeeoY5p1d31r5iUx1jw0O-Gd66vcsBi_Ntu3lJRMjV2EJA/viewform")
strong #{translate('take_short_survey')}
tr.affiliations-table-highlighted-row(
ng-if="!ui.showAddEmailUI && !ui.isMakingRequest"
)
td(colspan="3")
a(
href
ng-click="showAddEmailForm()"
) #{translate("add_another_email")}
tr.affiliations-table-highlighted-row(
ng-if="ui.showAddEmailUI && !ui.isLoadingEmails"
)
td
.affiliations-form-group
input-suggestions(
ng-model="newAffiliation.email"
ng-model-options="{ allowInvalid: true }"
get-suggestion="getEmailSuggestion(userInput)"
on-blur="handleEmailInputBlur()"
input-id="affiliations-email"
input-name="affiliationsEmail"
input-placeholder="e.g. johndoe@mit.edu"
input-type="email"
input-required="true"
focus-on-render="true"
)
td(
colspan="2"
ng-if="newAffiliation.ssoAvailable"
)
p.affiliations-table-label {{ newAffiliation.university.name }}
p !{translate("to_add_email_accounts_need_to_be_linked", {institutionName: "{{newAffiliation.university.name}}"})}
p !{translate("doing_this_will_verify_affiliation_and_allow_log_in", {institutionName: "{{newAffiliation.university.name}}"})} 
+aboutInstitutionLink()
button.btn-sm.btn.btn-primary.btn-link-accounts(
ng-click="linkInstitutionAcct(newAffiliation.email, newAffiliation.university.id)"
ng-disabled="ui.isMakingRequest"
type="button"
)
| #{translate("link_accounts_and_add_email")}
td(
ng-if="!newAffiliation.ssoAvailable"
)
p.affiliations-table-label(
ng-if="newAffiliation.university && !ui.showManualUniversitySelectionUI"
)
| {{ newAffiliation.university.name }}
span.small
| (
a(
href
ng-click="selectUniversityManually();"
) #{translate("change")}
| )
.affiliations-table-label(
ng-if="!newAffiliation.university && !ui.isValidEmail && !ui.showManualUniversitySelectionUI"
) #{translate("start_by_adding_your_email")}
.affiliations-table-label(
ng-if="!newAffiliation.university && ui.isValidEmail && !ui.isBlacklistedEmail && !ui.showManualUniversitySelectionUI"
)
| #{translate("is_email_affiliated")}
br
a(
href
ng-click="selectUniversityManually();"
) #{translate("let_us_know")}
affiliation-form(
affiliation-data="newAffiliation"
show-university-and-country="ui.showManualUniversitySelectionUI"
show-role-and-department="ui.isValidEmail && newAffiliation.university"
)
td(
ng-if="!newAffiliation.ssoAvailable"
)
button.btn.btn-sm.btn-primary(
ng-disabled="affiliationsForm.$invalid || ui.isMakingRequest"
ng-click="addNewEmail()"
)
| #{translate("add_new_email")}
tr.affiliations-table-highlighted-row(
ng-if="ui.isMakingRequest"
)
td.text-center(colspan="3", ng-if="ui.isLoadingEmails")
i.fa.fa-fw.fa-spin.fa-refresh(aria-hidden="true")
|  #{translate("loading")}…
td.text-center(colspan="3", ng-if="ui.isResendingConfirmation")
i.fa.fa-fw.fa-spin.fa-refresh(aria-hidden="true")
|  #{translate("sending")}…
td.text-center.text-capitalize(colspan="3", ng-if="ui.isProcessing")
i.fa.fa-fw.fa-spin.fa-refresh(aria-hidden="true")
|  #{translate("processing")}
td.text-center(colspan="3", ng-if="!ui.isLoadingEmails && !ui.isResendingConfirmation && !ui.isProcessing")
i.fa.fa-fw.fa-spin.fa-refresh(aria-hidden="true")
|  #{translate("saving")}
tr.affiliations-table-error-row(
ng-if="ui.hasError"
)
td.text-center(colspan="3")
div
i.fa.fa-fw.fa-exclamation-triangle(aria-hidden="true")
span(ng-if="!ui.errorMessage")  #{translate("error_performing_request")}
span(ng-if="ui.errorMessage")  {{ui.errorMessage}}
if institutionLinked
tr.affiliations-table-info-row(ng-if="!hideInstitutionNotifications.info")
td.text-center(aria-live="assertive" colspan="3")
button.close(
type="button"
data-dismiss="modal"
ng-click="closeInstitutionNotification('info')"
aria-label=translate("close")
)
span(aria-hidden="true") ×
.small(ng-non-bindable) !{translate("institution_acct_successfully_linked", {institutionName: institutionLinked.universityName})}
if institutionLinked.hasEntitlement
.small !{translate("this_grants_access_to_features", {featureType: translate("professional")})}
if institutionEmailNonCanonical
tr.affiliations-table-warning-row(ng-if="!hideInstitutionNotifications.warning")
td.text-center(aria-live="assertive" colspan="3")
button.close(
type="button"
data-dismiss="modal"
ng-click="closeInstitutionNotification('warning')"
aria-label=translate("close")
)
span(aria-hidden="true") ×
.small
i.fa.fa-exclamation-triangle(aria-hidden="true")
|  
| !{translate("in_order_to_match_institutional_metadata", {email: institutionEmailNonCanonical})}
if samlError
tr.affiliations-table-error-row(ng-if="!hideInstitutionNotifications.linkError")
td.text-center(aria-live="assertive" colspan="3")
button.close(
type="button"
data-dismiss="modal"
ng-click="closeInstitutionNotification('linkError')"
aria-label=translate("close")
)
span(aria-hidden="true") ×
.small
i.fa.fa-fw.fa-exclamation-triangle(aria-hidden="true")
|  #{translate("generic_something_went_wrong")}.
br
if samlError.translatedMessage
span(ng-non-bindable) !{samlError.translatedMessage}
else if samlError.message
span(ng-non-bindable) #{samlError.message}
if samlError.tryAgain
br
|  #{translate("try_again")}.
script(type="text/ng-template", id="affiliationFormTpl")
.affiliations-form-group(
ng-if="$ctrl.showUniversityAndCountry"
)
ui-select(
ng-model="$ctrl.affiliationData.country"
)
ui-select-match(
placeholder="Country"
) {{ $select.selected.name }}
ui-select-choices(
repeat="country in $ctrl.countries | filter: $select.search"
)
span(
ng-bind="country.name"
)
.affiliations-form-group(
ng-if="$ctrl.showUniversityAndCountry"
)
ui-select(
ng-model="$ctrl.affiliationData.university"
ng-disabled="!$ctrl.affiliationData.country"
tagging="$ctrl.addUniversityToSelection"
tagging-label="false"
)
ui-select-match(
placeholder="Institution"
) {{ $select.selected.name }}
ui-select-choices(
repeat="university in $ctrl.universities | filter: $select.search"
refresh="$ctrl.handleFreeformInputChange($select, 'name');"
refresh-delay="10"
)
span(
ng-bind="university.name"
)
.affiliations-form-group(
ng-if="$ctrl.showRoleAndDepartment"
)
ui-select(
ng-model="$ctrl.affiliationData.role"
tagging
tagging-label="false"
)
ui-select-match(
placeholder="Role"
) {{ $select.selected }}
ui-select-choices(
repeat="role in $ctrl.roles | filter: $select.search"
refresh="$ctrl.handleFreeformInputChange($select);"
refresh-delay="10"
)
span(
ng-bind="role"
)
.affiliations-form-group(
ng-if="$ctrl.showRoleAndDepartment"
)
ui-select(
ng-model="$ctrl.affiliationData.department"
tagging
tagging-label="false"
)
ui-select-match(
placeholder="Department"
) {{ $select.selected }}
ui-select-choices(
repeat="department in $ctrl.departments | filter: $select.search"
refresh="$ctrl.handleFreeformInputChange($select);"
refresh-delay="10"
)
span(
ng-bind="department"
)

View file

@ -1,41 +0,0 @@
mixin providerList()
ul.list-like-table
li(ng-repeat="(key, provider) in providers" ng-if="!provider.hideWhenNotLinked || (provider.hideWhenNotLinked && thirdPartyIds[key])")
.row
.col-xs-12.col-sm-8.col-md-10
h4 {{provider.name}}
p.small(ng-bind-html="provider.description")
.col-xs-2.col-sm-4.col-md-2.text-right
//- Unlink
button.btn.btn-default(
ng-click="unlink(key)"
ng-disabled="providers[key].ui.isProcessing"
ng-if="thirdPartyIds[key]"
)
span(ng-if="!providers[key].ui.isProcessing") #{translate("unlink")}
span(ng-if="providers[key].ui.isProcessing") #{translate("processing")}
//- Link
a.btn.btn-primary.text-capitalize(
ng-href="{{provider.linkPath}}?intent=link"
ng-if="!thirdPartyIds[key] && !provider.hideWhenNotLinked"
) #{translate("link")}
//- unlink error
.row(
ng-if="providers[key].ui.hasError"
)
.col-sm-12
//- to do: fix CSS so that we don't need inline styling
.alert.alert-danger(
ng-if="providers[key].ui.hasError"
style="display: block; margin-bottom: 10px;"
)
i.fa.fa-fw.fa-exclamation-triangle(aria-hidden="true")  
| {{providers[key].ui.errorMessage}}
.row(
ng-controller="UserOauthController"
ng-cloak
)
.col-xs-12
h3.text-capitalize#linked-accounts #{translate("linked_accounts")}
p.small #{translate("linked_accounts_explained", {appName:'{{settings.appName}}'})}
+providerList()

View file

@ -26,12 +26,9 @@ import './main/annual-upgrade'
import './main/subscription/team-invite-controller' import './main/subscription/team-invite-controller'
import './main/subscription/upgrade-subscription' import './main/subscription/upgrade-subscription'
import './main/learn' import './main/learn'
import './main/affiliations/components/affiliationForm'
import './main/affiliations/components/inputSuggestions' import './main/affiliations/components/inputSuggestions'
import './main/affiliations/controllers/UserAffiliationsController'
import './main/affiliations/factories/UserAffiliationsDataService' import './main/affiliations/factories/UserAffiliationsDataService'
import './main/affiliations/controllers/UserAffiliationsReconfirmController' import './main/affiliations/controllers/UserAffiliationsReconfirmController'
import './main/oauth/controllers/UserOauthController'
import './main/keys' import './main/keys'
import './main/importing' import './main/importing'
import './directives/autoSubmitForm' import './directives/autoSubmitForm'

View file

@ -1,108 +0,0 @@
import _ from 'lodash'
/* 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 affiliationFormController = function (
$scope,
$element,
$attrs,
UserAffiliationsDataService
) {
const ctrl = this
ctrl.roles = []
ctrl.departments = []
ctrl.countries = []
ctrl.universities = []
let _defaultDepartments = []
ctrl.addUniversityToSelection = universityName => ({
name: universityName,
isUserSuggested: true,
})
ctrl.handleFreeformInputChange = function ($select, propertyToMatch) {
if ($select.search == null || $select.search === '') {
return
}
let resultingItem = $select.search
if (($select.tagging != null ? $select.tagging.fct : undefined) != null) {
resultingItem = $select.tagging.fct($select.search)
}
if (propertyToMatch != null) {
const matchingItem = _.find(
$select.items,
item => item[propertyToMatch] === $select.search
)
if (matchingItem != null) {
resultingItem = matchingItem
}
}
return $select.searchInput.scope().$broadcast('uis:select', resultingItem)
}
// Populates the countries dropdown
UserAffiliationsDataService.getCountries().then(
countries => (ctrl.countries = countries)
)
// Populates the roles dropdown
UserAffiliationsDataService.getDefaultRoleHints().then(
roles => (ctrl.roles = roles)
)
// Fetches the default department hints
UserAffiliationsDataService.getDefaultDepartmentHints().then(
departments => (_defaultDepartments = departments)
)
// Populates the universities dropdown (after selecting a country)
$scope.$watch(
'$ctrl.affiliationData.country',
function (newSelectedCountry, prevSelectedCountry) {
if (
newSelectedCountry != null &&
newSelectedCountry !== prevSelectedCountry
) {
ctrl.affiliationData.university = null
ctrl.affiliationData.role = null
ctrl.affiliationData.department = null
return UserAffiliationsDataService.getUniversitiesFromCountry(
newSelectedCountry
).then(universities => (ctrl.universities = universities))
}
}
)
// Populates the departments dropdown (after selecting a university)
$scope.$watch(
'$ctrl.affiliationData.university',
function (newSelectedUniversity, prevSelectedUniversity) {
if (
newSelectedUniversity != null &&
newSelectedUniversity !== prevSelectedUniversity &&
(newSelectedUniversity.departments != null
? newSelectedUniversity.departments.length
: undefined) > 0
) {
return (ctrl.departments = _.uniq(newSelectedUniversity.departments))
} else {
return (ctrl.departments = _defaultDepartments)
}
}
)
}
export default App.component('affiliationForm', {
bindings: {
affiliationData: '=',
showUniversityAndCountry: '<',
showRoleAndDepartment: '<',
},
controller: affiliationFormController,
templateUrl: 'affiliationFormTpl',
})

View file

@ -1,363 +0,0 @@
import _ from 'lodash'
/* eslint-disable
max-len,
no-return-assign,
no-useless-escape,
*/
import App from '../../../base'
import getMeta from '../../../utils/meta'
export default App.controller(
'UserAffiliationsController',
function ($scope, $rootScope, UserAffiliationsDataService, $q, $window) {
$scope.userEmails = []
$scope.linkedInstitutionIds = []
$scope.hideInstitutionNotifications = {}
$scope.closeInstitutionNotification = type => {
$scope.hideInstitutionNotifications[type] = true
}
$scope.samlBetaSession = ExposedSettings.hasSamlBeta
$scope.samlInitPath = ExposedSettings.samlInitPath
$scope.reconfirmationRemoveEmail = getMeta('ol-reconfirmationRemoveEmail')
$scope.reconfirmedViaSAML = getMeta('ol-reconfirmedViaSAML')
$scope.showInstitutionalLeaversSurvey = false
$scope.dismissInstitutionalLeaversSurvey = () => {
try {
localStorage.setItem('hideInstitutionalLeaversSurvey', true)
} catch (e) {}
$scope.showInstitutionalLeaversSurvey = false
}
function maybeShowInstitutionalLeaversSurvey() {
if (localStorage.getItem('hideInstitutionalLeaversSurvey')) return
if (
localStorage.getItem('showInstitutionalLeaversSurveyUntil') > Date.now()
) {
$scope.showInstitutionalLeaversSurvey = true
}
}
maybeShowInstitutionalLeaversSurvey()
const ONE_WEEK_IN_MS = 7 * 24 * 60 * 60 * 1000
const LOCAL_AND_DOMAIN_REGEX = /([^@]+)@(.+)/
const EMAIL_REGEX =
/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\ ".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA -Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
const _matchLocalAndDomain = function (userEmailInput) {
const match = userEmailInput
? userEmailInput.match(LOCAL_AND_DOMAIN_REGEX)
: undefined
if (match) {
return { local: match[1], domain: match[2] }
} else {
return { local: null, domain: null }
}
}
const _ssoAvailableForAffiliation = affiliation => {
if (!affiliation) return false
const institution = affiliation.institution
if (!_ssoAvailableForInstitution(institution)) return false
if (!institution.confirmed) return false // domain is confirmed, not the email
return true
}
const _ssoAvailableForDomain = domain => {
if (!domain) return false
if (!domain.confirmed) return false // domain is confirmed, not the email
const institution = domain.university
if (!_ssoAvailableForInstitution(institution)) return false
return true
}
const _ssoAvailableForInstitution = institution => {
if (!ExposedSettings.hasSamlFeature) return false
if (!institution) return false
if (institution.ssoEnabled) return true
if ($scope.samlBetaSession && institution.ssoBeta) return true
return false
}
$scope.getEmailSuggestion = function (userInput) {
const userInputLocalAndDomain = _matchLocalAndDomain(userInput)
$scope.ui.isValidEmail = EMAIL_REGEX.test(userInput)
$scope.ui.isBlacklistedEmail = false
$scope.ui.showManualUniversitySelectionUI = false
if (userInputLocalAndDomain.domain) {
$scope.ui.isBlacklistedEmail =
UserAffiliationsDataService.isDomainBlacklisted(
userInputLocalAndDomain.domain
)
return UserAffiliationsDataService.getUniversityDomainFromPartialDomainInput(
userInputLocalAndDomain.domain
)
.then(function (universityDomain) {
const currentUserInputLocalAndDomain = _matchLocalAndDomain(
$scope.newAffiliation.email
)
if (
currentUserInputLocalAndDomain.domain ===
universityDomain.hostname
) {
$scope.newAffiliation.university = universityDomain.university
$scope.newAffiliation.department = universityDomain.department
$scope.newAffiliation.ssoAvailable =
_ssoAvailableForDomain(universityDomain)
} else {
_resetAffiliationSuggestion()
}
return $q.resolve(
`${userInputLocalAndDomain.local}@${universityDomain.hostname}`
)
})
.catch(function () {
_resetAffiliationSuggestion()
return $q.reject(null)
})
} else {
_resetAffiliationSuggestion()
return $q.reject(null)
}
}
$scope.linkInstitutionAcct = function (email, institutionId) {
_resetMakingRequestType()
$scope.ui.isMakingRequest = true
$scope.ui.isProcessing = true
$window.location.href = `${$scope.samlInitPath}?university_id=${institutionId}&auto=/user/settings&email=${email}`
}
$scope.selectUniversityManually = function () {
_resetAffiliationSuggestion()
$scope.ui.showManualUniversitySelectionUI = true
}
$scope.changeAffiliation = function (userEmail) {
if (_.get(userEmail, ['affiliation', 'institution', 'id'])) {
UserAffiliationsDataService.getUniversityDetails(
userEmail.affiliation.institution.id
).then(
universityDetails =>
($scope.affiliationToChange.university = universityDetails)
)
}
$scope.affiliationToChange.email = userEmail.email
$scope.affiliationToChange.role = userEmail.affiliation.role
$scope.affiliationToChange.department = userEmail.affiliation.department
}
$scope.saveAffiliationChange = function (userEmail) {
userEmail.affiliation.role = $scope.affiliationToChange.role
userEmail.affiliation.department = $scope.affiliationToChange.department
_resetAffiliationToChange()
return _monitorRequest(
UserAffiliationsDataService.addRoleAndDepartment(
userEmail.email,
userEmail.affiliation.role,
userEmail.affiliation.department
)
).then(() => setTimeout(() => _getUserEmails()))
}
$scope.cancelAffiliationChange = email => _resetAffiliationToChange()
$scope.isChangingAffiliation = email =>
$scope.affiliationToChange.email === email
$scope.showAddEmailForm = () => ($scope.ui.showAddEmailUI = true)
$scope.addNewEmail = function () {
let addEmailPromise
if (!$scope.newAffiliation.university) {
addEmailPromise = UserAffiliationsDataService.addUserEmail(
$scope.newAffiliation.email
)
} else {
if ($scope.newAffiliation.university.isUserSuggested) {
addEmailPromise =
UserAffiliationsDataService.addUserAffiliationWithUnknownUniversity(
$scope.newAffiliation.email,
$scope.newAffiliation.university.name,
$scope.newAffiliation.country.code,
$scope.newAffiliation.role,
$scope.newAffiliation.department
)
} else {
addEmailPromise = UserAffiliationsDataService.addUserAffiliation(
$scope.newAffiliation.email,
$scope.newAffiliation.university.id,
$scope.newAffiliation.role,
$scope.newAffiliation.department
)
}
}
$scope.ui.isAddingNewEmail = true
$scope.ui.showAddEmailUI = false
return _monitorRequest(addEmailPromise)
.then(function () {
_resetNewAffiliation()
_resetAddingEmail()
setTimeout(() => _getUserEmails())
})
.finally(() => ($scope.ui.isAddingNewEmail = false))
}
$scope.setDefaultUserEmail = userEmail =>
_monitorRequest(
UserAffiliationsDataService.setDefaultUserEmail(userEmail.email)
).then(function () {
for (const email of $scope.userEmails || []) {
email.default = false
}
userEmail.default = true
window.usersEmail = userEmail.email
$rootScope.usersEmail = userEmail.email
})
$scope.removeUserEmail = function (userEmail) {
$scope.userEmails = $scope.userEmails.filter(ue => ue !== userEmail)
return _monitorRequest(
UserAffiliationsDataService.removeUserEmail(userEmail.email)
)
.then(() => {
if (
userEmail.emailHasInstitutionLicence ||
(userEmail.affiliation && userEmail.affiliation.pastReconfirmDate)
) {
const stillHasLicenseAccess = $scope.userEmails.some(
ue => ue.emailHasInstitutionLicence
)
if (!stillHasLicenseAccess) {
try {
localStorage.setItem(
'showInstitutionalLeaversSurveyUntil',
Date.now() + ONE_WEEK_IN_MS
)
maybeShowInstitutionalLeaversSurvey()
} catch (e) {}
}
}
})
.catch(() => {
$scope.userEmails.push(userEmail)
})
}
$scope.resendConfirmationEmail = function (userEmail) {
_resetMakingRequestType()
$scope.ui.isResendingConfirmation = true
return _monitorRequest(
UserAffiliationsDataService.resendConfirmationEmail(userEmail.email)
).finally(() => ($scope.ui.isResendingConfirmation = false))
}
$scope.acknowledgeError = function () {
_reset()
return _getUserEmails()
}
const _resetAffiliationToChange = () =>
($scope.affiliationToChange = {
email: '',
university: null,
role: null,
department: null,
})
const _resetNewAffiliation = () =>
($scope.newAffiliation = {
email: '',
country: null,
university: null,
role: null,
department: null,
})
function _resetAddingEmail() {
$scope.ui.showAddEmailUI = false
$scope.ui.isValidEmail = false
$scope.ui.isBlacklistedEmail = false
$scope.ui.showManualUniversitySelectionUI = false
}
const _resetAffiliationSuggestion = () => {
$scope.newAffiliation = {
email: $scope.newAffiliation.email,
}
}
function _resetMakingRequestType() {
$scope.ui.isLoadingEmails = false
$scope.ui.isProcessing = false
$scope.ui.isResendingConfirmation = false
}
function _reset() {
$scope.ui = {
hasError: false,
errorMessage: '',
showChangeAffiliationUI: false,
isMakingRequest: false,
isLoadingEmails: false,
isAddingNewEmail: false,
}
_resetAffiliationToChange()
_resetNewAffiliation()
return _resetAddingEmail()
}
_reset()
$scope.ui.showAddEmailUI = window.location.hash === '#add-email'
function _monitorRequest(promise) {
$scope.ui.hasError = false
$scope.ui.isMakingRequest = true
promise
.catch(function (response) {
$scope.ui.hasError = true
$scope.ui.errorMessage = _.get(response, ['data', 'message'])
})
.finally(() => ($scope.ui.isMakingRequest = false))
return promise
}
$scope.inReconfirmNotificationPeriod = function (emailData) {
return _.get(emailData, ['affiliation', 'inReconfirmNotificationPeriod'])
}
$scope.institutionAlreadyLinked = function (emailData) {
const institutionId =
emailData.affiliation &&
emailData.affiliation.institution &&
emailData.affiliation.institution &&
emailData.affiliation.institution.id
? emailData.affiliation.institution.id.toString()
: undefined
return $scope.linkedInstitutionIds.indexOf(institutionId) !== -1
}
// Populates the emails table
function _getUserEmails() {
_resetMakingRequestType()
$scope.ui.isLoadingEmails = true
_monitorRequest(
UserAffiliationsDataService.getUserEmailsEnsureAffiliation()
)
.then(emails => {
$scope.userEmails = emails.map(email => {
email.ssoAvailable = _ssoAvailableForAffiliation(email.affiliation)
return email
})
$scope.linkedInstitutionIds = emails
.filter(email => {
return !!email.samlProviderId
})
.map(email => email.samlProviderId)
})
.finally(() => ($scope.ui.isLoadingEmails = false))
}
_getUserEmails()
}
)

View file

@ -1,52 +0,0 @@
import App from '../../../base'
export default App.controller(
'UserOauthController',
function ($http, $scope, $q) {
const _reset = function () {
$scope.ui = {
hasError: false,
errorMessage: '',
}
$scope.providers = window.oauthProviders
$scope.thirdPartyIds = window.thirdPartyIds
}
const _unlinkError = (providerId, err) => {
$scope.providers[providerId].ui.hasError = true
$scope.providers[providerId].ui.errorMessage =
err && err.data && err.data.message ? err.data.message : 'error'
}
$scope.unlink = providerId => {
if (window.ExposedSettings.isOverleaf) {
// UI
$scope.providers[providerId].ui = {
hasError: false,
isProcessing: true,
}
// Data for update
const data = {
_csrf: window.csrfToken,
link: false,
providerId,
}
$http
.post('/user/oauth-unlink', data)
.catch(error => {
$scope.providers[providerId].ui.isProcessing = false
_unlinkError(providerId, error)
})
.then(response => {
$scope.providers[providerId].ui.isProcessing = false
if (response.status === 200) {
$scope.thirdPartyIds[providerId] = null
} else {
_unlinkError(providerId, response)
}
})
}
}
_reset()
}
)