From 7653b46719b2227c1addbc1030b84a6ffec1c6da Mon Sep 17 00:00:00 2001 From: Jessica Lawshe Date: Tue, 25 Jan 2022 09:22:00 -0600 Subject: [PATCH] Merge pull request #6356 from overleaf/jel-user-admin-panel [web] v2 admin affiliations tab shows data used for licenses GitOrigin-RevId: 1038b042a0728b118d3204515ed9f69e35746b18 --- .../web/app/src/Features/User/UserGetter.js | 12 ++++ .../frontend/stylesheets/app/admin-hub.less | 7 ++ .../web/test/unit/src/User/UserGetterTests.js | 70 +++++++++++++++++++ 3 files changed, 89 insertions(+) diff --git a/services/web/app/src/Features/User/UserGetter.js b/services/web/app/src/Features/User/UserGetter.js index 621f265cb0..66d2f8ceec 100644 --- a/services/web/app/src/Features/User/UserGetter.js +++ b/services/web/app/src/Features/User/UserGetter.js @@ -257,10 +257,18 @@ const decorateFullEmails = ( role, department, licence, + cached_confirmed_at: cachedConfirmedAt, + cached_reconfirmed_at: cachedReconfirmedAt, past_reconfirm_date: cachedPastReconfirmDate, + entitlement: cachedEntitlement, portal, } = affiliation const lastDayToReconfirm = _lastDayToReconfirm(emailData, institution) + let { last_day_to_reconfirm: cachedLastDayToReconfirm } = affiliation + if (institution.ssoEnabled && !emailData.samlProviderId) { + // only SSO linked emails are reconfirmed at SSO institutions + cachedLastDayToReconfirm = undefined + } const pastReconfirmDate = _pastReconfirmDate(lastDayToReconfirm) const inReconfirmNotificationPeriod = _emailInReconfirmNotificationPeriod( lastDayToReconfirm, @@ -271,6 +279,10 @@ const decorateFullEmails = ( inferred, inReconfirmNotificationPeriod, lastDayToReconfirm, + cachedConfirmedAt, + cachedLastDayToReconfirm, + cachedReconfirmedAt, + cachedEntitlement, cachedPastReconfirmDate, pastReconfirmDate, role, diff --git a/services/web/frontend/stylesheets/app/admin-hub.less b/services/web/frontend/stylesheets/app/admin-hub.less index 633400d0c6..d27a899536 100644 --- a/services/web/frontend/stylesheets/app/admin-hub.less +++ b/services/web/frontend/stylesheets/app/admin-hub.less @@ -98,3 +98,10 @@ .superscript { font-size: @font-size-large; } + +.admin-page { + summary { + // firefox does not show markers for block items + display: list-item; + } +} diff --git a/services/web/test/unit/src/User/UserGetterTests.js b/services/web/test/unit/src/User/UserGetterTests.js index 9015388992..6c6ddabbea 100644 --- a/services/web/test/unit/src/User/UserGetterTests.js +++ b/services/web/test/unit/src/User/UserGetterTests.js @@ -173,7 +173,10 @@ describe('UserGetter', function () { { email: 'email1@foo.bar', role: 'Prof', + cached_confirmed_at: '2019-07-11T18:25:01.639Z', + cached_reconfirmed_at: '2021-07-11T18:25:01.639Z', department: 'Maths', + entitlement: false, inferred: false, licence: 'pro_plus', institution: { @@ -181,6 +184,7 @@ describe('UserGetter', function () { isUniversity: true, confirmed: true, }, + last_day_to_reconfirm: undefined, past_reconfirm_date: false, portal: undefined, }, @@ -205,6 +209,10 @@ describe('UserGetter', function () { lastDayToReconfirm: undefined, licence: affiliationsData[0].licence, inReconfirmNotificationPeriod: false, + cachedConfirmedAt: '2019-07-11T18:25:01.639Z', + cachedReconfirmedAt: '2021-07-11T18:25:01.639Z', + cachedEntitlement: false, + cachedLastDayToReconfirm: undefined, cachedPastReconfirmDate: false, pastReconfirmDate: false, portal: undefined, @@ -807,6 +815,7 @@ describe('UserGetter', function () { email, licence: 'free', institution: institutionNonSSO, + last_day_to_reconfirm: '2020-07-11T18:25:01.639Z', past_reconfirm_date: true, }, ] @@ -834,6 +843,67 @@ describe('UserGetter', function () { } ) }) + + describe('cachedLastDayToReconfirm', function () { + const email = 'abc123@test.com' + const confirmedAt = new Date('2019-07-11T18:25:01.639Z') + const lastDay = '2020-07-11T18:25:01.639Z' + const affiliationsData = [ + { + email, + licence: 'professional', + institution: institutionSSO, + last_day_to_reconfirm: lastDay, + past_reconfirm_date: true, + }, + ] + const user = { + _id: '12390i', + email, + emails: [ + { + email, + confirmedAt, + default: true, + }, + ], + } + + it('should set cachedLastDayToReconfirm for SSO institutions if email is linked to SSO', async function () { + const userLinked = Object.assign({}, user) + userLinked.emails[0].samlProviderId = institutionSSO.id.toString() + this.getUserAffiliations.resolves(affiliationsData) + this.UserGetter.promises.getUser = sinon.stub().resolves(userLinked) + const fullEmails = await this.UserGetter.promises.getUserFullEmails( + this.fakeUser._id + ) + expect(fullEmails[0].affiliation.cachedLastDayToReconfirm).to.equal( + lastDay + ) + }) + + it('should NOT set cachedLastDayToReconfirm for SSO institutions if email is NOT linked to SSO', async function () { + this.getUserAffiliations.resolves(affiliationsData) + this.UserGetter.promises.getUser = sinon.stub().resolves(user) + const fullEmails = await this.UserGetter.promises.getUserFullEmails( + this.fakeUser._id + ) + expect(fullEmails[0].affiliation.cachedLastDayToReconfirm).to.equal( + lastDay + ) + }) + + it('should set cachedLastDayToReconfirm for non-SSO institutions', async function () { + this.getUserAffiliations.resolves(affiliationsData) + this.UserGetter.promises.getUser = sinon.stub().resolves(user) + const fullEmails = await this.UserGetter.promises.getUserFullEmails( + this.fakeUser._id + ) + expect(fullEmails[0].affiliation.cachedLastDayToReconfirm).to.equal( + lastDay + ) + }) + }) }) })