From 042c959d3acb5e701d03a2ff1b2ceff5306944cc Mon Sep 17 00:00:00 2001 From: Paulo Reis Date: Mon, 20 Aug 2018 12:15:15 +0100 Subject: [PATCH] Move default email checking logic into the data service. --- services/web/public/coffee/main/account-settings.coffee | 5 ++--- .../factories/UserAffiliationsDataService.coffee | 5 +++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/services/web/public/coffee/main/account-settings.coffee b/services/web/public/coffee/main/account-settings.coffee index b12b8f3dde..cac35394a1 100644 --- a/services/web/public/coffee/main/account-settings.coffee +++ b/services/web/public/coffee/main/account-settings.coffee @@ -25,9 +25,8 @@ define [ resolve: userDefaultEmail: () -> UserAffiliationsDataService - .getUserEmails() - .then (userEmails) -> - defaultEmailDetails = _.find userEmails, (userEmail) -> userEmail.default + .getUserDefaultEmail() + .then (defaultEmailDetails) -> return defaultEmailDetails?.email or null .catch () -> null ) diff --git a/services/web/public/coffee/main/affiliations/factories/UserAffiliationsDataService.coffee b/services/web/public/coffee/main/affiliations/factories/UserAffiliationsDataService.coffee index cbcadf7e67..ca1ffef168 100644 --- a/services/web/public/coffee/main/affiliations/factories/UserAffiliationsDataService.coffee +++ b/services/web/public/coffee/main/affiliations/factories/UserAffiliationsDataService.coffee @@ -31,6 +31,10 @@ define [ $http.get "/user/emails" .then (response) -> response.data + getUserDefaultEmail = () -> + getUserEmails().then (userEmails) -> + _.find userEmails, (userEmail) -> userEmail.default + getUniversitiesFromCountry = (country) -> if universities[country.code]? universitiesFromCountry = universities[country.code] @@ -118,6 +122,7 @@ define [ getDefaultRoleHints getDefaultDepartmentHints getUserEmails + getUserDefaultEmail getUniversitiesFromCountry getUniversityDomainFromPartialDomainInput getUniversityDetails