diff --git a/services/web/app/src/Features/Project/ProjectController.js b/services/web/app/src/Features/Project/ProjectController.js index 3344955bc5..3b74c83981 100644 --- a/services/web/app/src/Features/Project/ProjectController.js +++ b/services/web/app/src/Features/Project/ProjectController.js @@ -497,7 +497,11 @@ const ProjectController = { // Notification: After SSO Linked or Logging in // The requested email does not match primary email returned from // the institution - if (samlSession.emailNonCanonical && !samlSession.linkedToAnother) { + if ( + samlSession.requestedEmail && + samlSession.emailNonCanonical && + !samlSession.linkedToAnother + ) { notificationsInstitution.push({ institutionEmail: samlSession.emailNonCanonical, requestedEmail: samlSession.requestedEmail, diff --git a/services/web/app/src/Features/User/UserPagesController.js b/services/web/app/src/Features/User/UserPagesController.js index b2bd462a6a..5176ca74c2 100644 --- a/services/web/app/src/Features/User/UserPagesController.js +++ b/services/web/app/src/Features/User/UserPagesController.js @@ -132,6 +132,10 @@ const UserPagesController = { 'saml', 'emailNonCanonical' ]) + const institutionRequestedEmail = _.get(req.session, [ + 'saml', + 'requestedEmail' + ]) delete req.session.saml logger.log({ user: userId }, 'loading settings page') let shouldAllowEditingDetails = true @@ -161,7 +165,10 @@ const UserPagesController = { oauthUseV2: Settings.oauthUseV2 || false, institutionLinked, institutionLinkedToAnother, - institutionEmailNonCanonical, + institutionEmailNonCanonical: + institutionEmailNonCanonical && institutionRequestedEmail + ? institutionEmailNonCanonical + : undefined, samlBeta: req.session.samlBeta, ssoError: ssoError, thirdPartyIds: UserPagesController._restructureThirdPartyIds(user) diff --git a/services/web/test/unit/src/Project/ProjectControllerTests.js b/services/web/test/unit/src/Project/ProjectControllerTests.js index 545a506d7f..ce9ab55ed9 100644 --- a/services/web/test/unit/src/Project/ProjectControllerTests.js +++ b/services/web/test/unit/src/Project/ProjectControllerTests.js @@ -800,6 +800,28 @@ describe('ProjectController', function() { } this.ProjectController.projectListPage(this.req, this.res) }) + describe('when linking/logging in initiated on institution side', function() { + it('should not show a linked another email notification', function() { + // this is only used when initated on Overleaf, + // because we keep track of the requested email they tried to link + this.res.render = (pageName, opts) => { + expect(opts.notificationsInstitution).to.not.deep.include({ + institutionEmail: this.institutionEmail, + requestedEmail: undefined, + templateKey: 'notification_institution_sso_non_canonical' + }) + } + this.req.session.saml = { + emailNonCanonical: this.institutionEmail, + institutionEmail: this.institutionEmail, + linked: { + hasEntitlement: false, + universityName: this.institutionName + } + } + this.ProjectController.projectListPage(this.req, this.res) + }) + }) }) describe('When Institution SSO is not released', function() {