mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #4659 from overleaf/jel-em-duplicate-subscription-message
One Pro message per current commons institutions GitOrigin-RevId: 21b74af8b9da1b6647a0384115f5d268b80e4bdf
This commit is contained in:
parent
c0b27c4524
commit
379d9ac41c
6 changed files with 86 additions and 30 deletions
|
@ -29,6 +29,19 @@ async function getCurrentInstitutionIds(userId) {
|
|||
return [...institutionIds]
|
||||
}
|
||||
|
||||
async function getCurrentInstitutionsWithLicence(userId) {
|
||||
// current are those confirmed and not with lapsed reconfirmations
|
||||
// only 1 record returned per current institution
|
||||
const institutions = {}
|
||||
const currentAffiliations = await _getCurrentAffiliations(userId)
|
||||
currentAffiliations.forEach(affiliation => {
|
||||
if (affiliation.licence && affiliation.licence !== 'free') {
|
||||
institutions[affiliation.institution.id] = affiliation.institution
|
||||
}
|
||||
})
|
||||
return Object.values(institutions)
|
||||
}
|
||||
|
||||
const InstitutionsGetter = {
|
||||
getConfirmedAffiliations(userId, callback) {
|
||||
UserGetter.getUserFullEmails(userId, function (error, emailsData) {
|
||||
|
@ -51,6 +64,9 @@ const InstitutionsGetter = {
|
|||
},
|
||||
|
||||
getCurrentInstitutionIds: callbackify(getCurrentInstitutionIds),
|
||||
getCurrentInstitutionsWithLicence: callbackify(
|
||||
getCurrentInstitutionsWithLicence
|
||||
),
|
||||
|
||||
getManagedInstitutions(userId, callback) {
|
||||
UserMembershipsHandler.getEntitiesByUser(
|
||||
|
@ -63,6 +79,7 @@ const InstitutionsGetter = {
|
|||
|
||||
InstitutionsGetter.promises = {
|
||||
getCurrentInstitutionIds,
|
||||
getCurrentInstitutionsWithLicence,
|
||||
}
|
||||
|
||||
module.exports = InstitutionsGetter
|
||||
|
|
|
@ -19,7 +19,6 @@ const AnalyticsManager = require('../Analytics/AnalyticsManager')
|
|||
const RecurlyEventHandler = require('./RecurlyEventHandler')
|
||||
const { expressify } = require('../../util/promises')
|
||||
const OError = require('@overleaf/o-error')
|
||||
const _ = require('lodash')
|
||||
|
||||
const SUBSCRIPTION_PAGE_SPLIT_TEST = 'subscription-page'
|
||||
|
||||
|
@ -103,7 +102,7 @@ async function userSubscriptionPage(req, res) {
|
|||
personalSubscription,
|
||||
memberGroupSubscriptions,
|
||||
managedGroupSubscriptions,
|
||||
confirmedMemberAffiliations,
|
||||
currentInstitutionsWithLicence,
|
||||
managedInstitutions,
|
||||
managedPublishers,
|
||||
v1SubscriptionStatus,
|
||||
|
@ -121,11 +120,7 @@ async function userSubscriptionPage(req, res) {
|
|||
personalSubscription ||
|
||||
hasSubscription ||
|
||||
(memberGroupSubscriptions && memberGroupSubscriptions.length > 0) ||
|
||||
(confirmedMemberAffiliations &&
|
||||
confirmedMemberAffiliations.length > 0 &&
|
||||
_.find(confirmedMemberAffiliations, affiliation => {
|
||||
return affiliation.licence && affiliation.licence !== 'free'
|
||||
}))
|
||||
currentInstitutionsWithLicence.length > 0
|
||||
) {
|
||||
AnalyticsManager.recordEvent(user._id, 'subscription-page-view')
|
||||
} else {
|
||||
|
@ -163,10 +158,10 @@ async function userSubscriptionPage(req, res) {
|
|||
personalSubscription,
|
||||
memberGroupSubscriptions,
|
||||
managedGroupSubscriptions,
|
||||
confirmedMemberAffiliations,
|
||||
managedInstitutions,
|
||||
managedPublishers,
|
||||
v1SubscriptionStatus,
|
||||
currentInstitutionsWithLicence,
|
||||
}
|
||||
res.render('subscriptions/dashboard', data)
|
||||
}
|
||||
|
|
|
@ -88,8 +88,8 @@ function buildUsersSubscriptionViewModel(user, callback) {
|
|||
managedGroupSubscriptions(cb) {
|
||||
SubscriptionLocator.getManagedGroupSubscriptions(user, cb)
|
||||
},
|
||||
confirmedMemberAffiliations(cb) {
|
||||
InstitutionsGetter.getConfirmedAffiliations(user._id, cb)
|
||||
currentInstitutionsWithLicence(cb) {
|
||||
InstitutionsGetter.getCurrentInstitutionsWithLicence(user._id, cb)
|
||||
},
|
||||
managedInstitutions(cb) {
|
||||
InstitutionsGetter.getManagedInstitutions(user._id, cb)
|
||||
|
@ -117,7 +117,7 @@ function buildUsersSubscriptionViewModel(user, callback) {
|
|||
personalSubscription,
|
||||
memberGroupSubscriptions,
|
||||
managedGroupSubscriptions,
|
||||
confirmedMemberAffiliations,
|
||||
currentInstitutionsWithLicence,
|
||||
managedInstitutions,
|
||||
managedPublishers,
|
||||
v1SubscriptionStatus,
|
||||
|
@ -125,15 +125,13 @@ function buildUsersSubscriptionViewModel(user, callback) {
|
|||
recurlyCoupons,
|
||||
plan,
|
||||
} = results
|
||||
|
||||
if (memberGroupSubscriptions == null) {
|
||||
memberGroupSubscriptions = []
|
||||
}
|
||||
if (managedGroupSubscriptions == null) {
|
||||
managedGroupSubscriptions = []
|
||||
}
|
||||
if (confirmedMemberAffiliations == null) {
|
||||
confirmedMemberAffiliations = []
|
||||
}
|
||||
if (managedInstitutions == null) {
|
||||
managedInstitutions = []
|
||||
}
|
||||
|
@ -269,7 +267,7 @@ function buildUsersSubscriptionViewModel(user, callback) {
|
|||
personalSubscription,
|
||||
managedGroupSubscriptions,
|
||||
memberGroupSubscriptions,
|
||||
confirmedMemberAffiliations,
|
||||
currentInstitutionsWithLicence,
|
||||
managedInstitutions,
|
||||
managedPublishers,
|
||||
v1SubscriptionStatus,
|
||||
|
|
|
@ -43,8 +43,7 @@ block content
|
|||
-hasDisplayedSubscription = true
|
||||
include ./dashboard/_group_memberships
|
||||
|
||||
if (confirmedMemberAffiliations && confirmedMemberAffiliations.length > 0)
|
||||
include ./dashboard/_institution_memberships
|
||||
include ./dashboard/_institution_memberships
|
||||
|
||||
if (v1SubscriptionStatus)
|
||||
include ./dashboard/_v1_subscription_status
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
each affiliation in confirmedMemberAffiliations
|
||||
if (affiliation.licence && affiliation.licence != 'free')
|
||||
-hasDisplayedSubscription = true
|
||||
p
|
||||
| You have a
|
||||
|
|
||||
strong(ng-non-bindable) Professional
|
||||
|
|
||||
| #{settings.appName} account as a confirmed member of
|
||||
|
|
||||
strong(ng-non-bindable)= affiliation.institution.name
|
||||
hr
|
||||
|
||||
each institution in currentInstitutionsWithLicence
|
||||
-hasDisplayedSubscription = true
|
||||
p
|
||||
| You have a
|
||||
|
|
||||
strong(ng-non-bindable) Professional
|
||||
|
|
||||
| #{settings.appName} account as a confirmed member of
|
||||
|
|
||||
strong(ng-non-bindable)= institution.name
|
||||
hr
|
||||
|
|
|
@ -37,6 +37,36 @@ describe('InstitutionsGetter', function () {
|
|||
pastReconfirmDate: true,
|
||||
},
|
||||
}
|
||||
this.licencedAffiliation = {
|
||||
confirmedAt: new Date(),
|
||||
affiliation: {
|
||||
licence: 'pro_plus',
|
||||
institution: { id: 777, confirmed: true },
|
||||
pastReconfirmDate: false,
|
||||
},
|
||||
}
|
||||
this.licencedAffiliationPastReconfirmation = {
|
||||
confirmedAt: new Date('2000-01-01'),
|
||||
affiliation: {
|
||||
licence: 'pro_plus',
|
||||
institution: { id: 888, confirmed: true },
|
||||
pastReconfirmDate: true,
|
||||
},
|
||||
}
|
||||
this.unconfirmedEmailLicensedAffiliation = {
|
||||
confirmedAt: null,
|
||||
affiliation: {
|
||||
licence: 'pro_plus',
|
||||
institution: { id: 123, confirmed: true, pastReconfirmDate: false },
|
||||
},
|
||||
}
|
||||
this.unconfirmedDomainLicensedAffiliation = {
|
||||
confirmedAt: new Date(),
|
||||
affiliation: {
|
||||
licence: 'pro_plus',
|
||||
institution: { id: 789, confirmed: false, pastReconfirmDate: false },
|
||||
},
|
||||
}
|
||||
this.userEmails = [
|
||||
{
|
||||
confirmedAt: null,
|
||||
|
@ -90,4 +120,23 @@ describe('InstitutionsGetter', function () {
|
|||
expect(e.message).to.equal('oops')
|
||||
})
|
||||
})
|
||||
|
||||
describe('getCurrentInstitutionsWithLicence', function () {
|
||||
it('returns one result per institution and filters out affiliations without license', async function () {
|
||||
this.UserGetter.promises.getUserFullEmails.resolves([
|
||||
this.licencedAffiliation,
|
||||
this.licencedAffiliation,
|
||||
this.licencedAffiliationPastReconfirmation,
|
||||
this.confirmedAffiliation,
|
||||
this.unconfirmedDomainLicensedAffiliation,
|
||||
this.unconfirmedEmailLicensedAffiliation,
|
||||
])
|
||||
const institutions = await this.InstitutionsGetter.promises.getCurrentInstitutionsWithLicence(
|
||||
this.userId
|
||||
)
|
||||
expect(institutions.map(institution => institution.id)).to.deep.equal([
|
||||
this.licencedAffiliation.affiliation.institution.id,
|
||||
])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue