mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-29 17:53:49 -05:00
Merge pull request #6837 from overleaf/jpa-drop-v1-subscription-lookup
[web] drop support for v1 subscriptions GitOrigin-RevId: ddffa60398d5319959f9e5455520a61fa58fab37
This commit is contained in:
parent
7e41fbf81b
commit
c192002f53
4 changed files with 12 additions and 131 deletions
|
@ -70,9 +70,13 @@ async function computeFeatures(userId) {
|
||||||
const groupFeatureSets = await _getGroupFeatureSets(userId)
|
const groupFeatureSets = await _getGroupFeatureSets(userId)
|
||||||
const institutionFeatures =
|
const institutionFeatures =
|
||||||
await InstitutionsFeatures.promises.getInstitutionsFeatures(userId)
|
await InstitutionsFeatures.promises.getInstitutionsFeatures(userId)
|
||||||
const v1Features = await _getV1Features(userId)
|
const user = await UserGetter.promises.getUser(userId, {
|
||||||
|
featuresOverrides: 1,
|
||||||
|
'overleaf.id': 1,
|
||||||
|
})
|
||||||
|
const v1Features = await _getV1Features(user)
|
||||||
const bonusFeatures = await ReferalFeatures.promises.getBonusFeatures(userId)
|
const bonusFeatures = await ReferalFeatures.promises.getBonusFeatures(userId)
|
||||||
const featuresOverrides = await _getFeaturesOverrides(userId)
|
const featuresOverrides = await _getFeaturesOverrides(user)
|
||||||
logger.log(
|
logger.log(
|
||||||
{
|
{
|
||||||
userId,
|
userId,
|
||||||
|
@ -114,10 +118,7 @@ async function _getGroupFeatureSets(userId) {
|
||||||
return (subs || []).map(_subscriptionToFeatures)
|
return (subs || []).map(_subscriptionToFeatures)
|
||||||
}
|
}
|
||||||
|
|
||||||
async function _getFeaturesOverrides(userId) {
|
async function _getFeaturesOverrides(user) {
|
||||||
const user = await UserGetter.promises.getUser(userId, {
|
|
||||||
featuresOverrides: 1,
|
|
||||||
})
|
|
||||||
if (!user || !user.featuresOverrides || user.featuresOverrides.length === 0) {
|
if (!user || !user.featuresOverrides || user.featuresOverrides.length === 0) {
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
@ -138,22 +139,9 @@ async function _getFeaturesOverrides(userId) {
|
||||||
return features
|
return features
|
||||||
}
|
}
|
||||||
|
|
||||||
async function _getV1Features(userId) {
|
async function _getV1Features(user) {
|
||||||
let planCode, v1Id
|
const v1Id = user?.overleaf?.id
|
||||||
try {
|
return V1SubscriptionManager.getGrandfatheredFeaturesForV1User(v1Id) || {}
|
||||||
;({ planCode, v1Id } =
|
|
||||||
await V1SubscriptionManager.promises.getPlanCodeFromV1(userId))
|
|
||||||
} catch (err) {
|
|
||||||
if (err.name === 'NotFoundError') {
|
|
||||||
return {}
|
|
||||||
} else {
|
|
||||||
throw err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return FeaturesHelper.mergeFeatures(
|
|
||||||
V1SubscriptionManager.getGrandfatheredFeaturesForV1User(v1Id) || {},
|
|
||||||
_planCodeToFeatures(planCode)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function _subscriptionToFeatures(subscription) {
|
function _subscriptionToFeatures(subscription) {
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
||||||
*/
|
*/
|
||||||
let V1SubscriptionManager
|
let V1SubscriptionManager
|
||||||
const logger = require('@overleaf/logger')
|
|
||||||
const UserGetter = require('../User/UserGetter')
|
const UserGetter = require('../User/UserGetter')
|
||||||
const request = require('requestretry')
|
const request = require('requestretry')
|
||||||
const settings = require('@overleaf/settings')
|
const settings = require('@overleaf/settings')
|
||||||
|
@ -20,46 +19,6 @@ const { V1ConnectionError, NotFoundError } = require('../Errors/Errors')
|
||||||
const { promisifyAll } = require('../../util/promises')
|
const { promisifyAll } = require('../../util/promises')
|
||||||
|
|
||||||
module.exports = V1SubscriptionManager = {
|
module.exports = V1SubscriptionManager = {
|
||||||
// Returned planCode = 'v1_pro' | 'v1_pro_plus' | 'v1_student' | 'v1_free' | null
|
|
||||||
// For this to work, we need plans in settings with plan-codes:
|
|
||||||
// - 'v1_pro'
|
|
||||||
// - 'v1_pro_plus'
|
|
||||||
// - 'v1_student'
|
|
||||||
// - 'v1_free'
|
|
||||||
getPlanCodeFromV1(userId, callback) {
|
|
||||||
if (callback == null) {
|
|
||||||
callback = function () {}
|
|
||||||
}
|
|
||||||
return V1SubscriptionManager._v1Request(
|
|
||||||
userId,
|
|
||||||
{
|
|
||||||
method: 'GET',
|
|
||||||
url(v1Id) {
|
|
||||||
return `/api/v1/sharelatex/users/${v1Id}/plan_code`
|
|
||||||
},
|
|
||||||
},
|
|
||||||
function (error, body, v1Id) {
|
|
||||||
if (error != null) {
|
|
||||||
return callback(error)
|
|
||||||
}
|
|
||||||
let planName = body != null ? body.plan_name : undefined
|
|
||||||
if (['pro', 'pro_plus', 'student', 'free'].includes(planName)) {
|
|
||||||
planName = `v1_${planName}`
|
|
||||||
} else {
|
|
||||||
// Throw away 'anonymous', etc as being equivalent to null
|
|
||||||
planName = null
|
|
||||||
}
|
|
||||||
if (planName != null && planName !== 'v1_free') {
|
|
||||||
logger.warn(
|
|
||||||
{ v1Id, planName },
|
|
||||||
'got non expired personal subscription'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
return callback(null, planName, v1Id)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
},
|
|
||||||
|
|
||||||
getSubscriptionsFromV1(userId, callback) {
|
getSubscriptionsFromV1(userId, callback) {
|
||||||
if (callback == null) {
|
if (callback == null) {
|
||||||
callback = function () {}
|
callback = function () {}
|
||||||
|
@ -229,7 +188,4 @@ function __guard__(value, transform) {
|
||||||
|
|
||||||
module.exports.promises = promisifyAll(module.exports, {
|
module.exports.promises = promisifyAll(module.exports, {
|
||||||
without: ['getGrandfatheredFeaturesForV1User'],
|
without: ['getGrandfatheredFeaturesForV1User'],
|
||||||
multiResult: {
|
|
||||||
getPlanCodeFromV1: ['planCode', 'v1Id'],
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
|
|
@ -7,11 +7,12 @@ const MODULE_PATH = '../../../../app/src/Features/Subscription/FeaturesUpdater'
|
||||||
|
|
||||||
describe('FeaturesUpdater', function () {
|
describe('FeaturesUpdater', function () {
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
|
this.v1UserId = 12345
|
||||||
this.user = {
|
this.user = {
|
||||||
_id: new ObjectId(),
|
_id: new ObjectId(),
|
||||||
features: {},
|
features: {},
|
||||||
|
overleaf: { id: this.v1UserId },
|
||||||
}
|
}
|
||||||
this.v1UserId = 12345
|
|
||||||
this.subscriptions = {
|
this.subscriptions = {
|
||||||
individual: { planCode: 'individual-plan' },
|
individual: { planCode: 'individual-plan' },
|
||||||
group1: { planCode: 'group-plan-1' },
|
group1: { planCode: 'group-plan-1' },
|
||||||
|
@ -46,7 +47,6 @@ describe('FeaturesUpdater', function () {
|
||||||
{ planCode: 'individual-plan', features: { individual: 'features' } },
|
{ planCode: 'individual-plan', features: { individual: 'features' } },
|
||||||
{ planCode: 'group-plan-1', features: { group1: 'features' } },
|
{ planCode: 'group-plan-1', features: { group1: 'features' } },
|
||||||
{ planCode: 'group-plan-2', features: { group2: 'features' } },
|
{ planCode: 'group-plan-2', features: { group2: 'features' } },
|
||||||
{ planCode: 'v1-plan', features: { v1: 'features' } },
|
|
||||||
{ planCode: 'no-dropbox', features: { dropbox: false } },
|
{ planCode: 'no-dropbox', features: { dropbox: false } },
|
||||||
],
|
],
|
||||||
features: {
|
features: {
|
||||||
|
@ -56,7 +56,6 @@ describe('FeaturesUpdater', function () {
|
||||||
group1: 'features',
|
group1: 'features',
|
||||||
group2: 'features',
|
group2: 'features',
|
||||||
institutions: 'features',
|
institutions: 'features',
|
||||||
v1: 'features',
|
|
||||||
grandfathered: 'features',
|
grandfathered: 'features',
|
||||||
bonus: 'features',
|
bonus: 'features',
|
||||||
},
|
},
|
||||||
|
@ -70,13 +69,7 @@ describe('FeaturesUpdater', function () {
|
||||||
}
|
}
|
||||||
this.V1SubscriptionManager = {
|
this.V1SubscriptionManager = {
|
||||||
getGrandfatheredFeaturesForV1User: sinon.stub(),
|
getGrandfatheredFeaturesForV1User: sinon.stub(),
|
||||||
promises: {
|
|
||||||
getPlanCodeFromV1: sinon.stub(),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
this.V1SubscriptionManager.promises.getPlanCodeFromV1
|
|
||||||
.withArgs(this.user._id)
|
|
||||||
.resolves({ planCode: 'v1-plan', v1Id: this.v1UserId })
|
|
||||||
this.V1SubscriptionManager.getGrandfatheredFeaturesForV1User
|
this.V1SubscriptionManager.getGrandfatheredFeaturesForV1User
|
||||||
.withArgs(this.v1UserId)
|
.withArgs(this.v1UserId)
|
||||||
.returns({ grandfathered: 'features' })
|
.returns({ grandfathered: 'features' })
|
||||||
|
|
|
@ -54,62 +54,6 @@ describe('V1SubscriptionManager', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('getPlanCodeFromV1', function () {
|
|
||||||
beforeEach(function () {
|
|
||||||
this.responseBody = {
|
|
||||||
id: 32,
|
|
||||||
plan_name: 'pro',
|
|
||||||
}
|
|
||||||
this.V1SubscriptionManager._v1Request = sinon
|
|
||||||
.stub()
|
|
||||||
.yields(null, this.responseBody)
|
|
||||||
return (this.call = cb => {
|
|
||||||
return this.V1SubscriptionManager.getPlanCodeFromV1(this.userId, cb)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('when all goes well', function () {
|
|
||||||
it('should call _v1Request', function (done) {
|
|
||||||
return this.call((err, planCode) => {
|
|
||||||
expect(this.V1SubscriptionManager._v1Request.callCount).to.equal(1)
|
|
||||||
expect(
|
|
||||||
this.V1SubscriptionManager._v1Request.calledWith(this.userId)
|
|
||||||
).to.equal(true)
|
|
||||||
return done()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should return the v1 user id', function (done) {
|
|
||||||
return this.call(function (err, planCode, v1Id) {
|
|
||||||
expect(v1Id).to.equal(this.v1UserId)
|
|
||||||
return done()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should produce a plan-code without error', function (done) {
|
|
||||||
return this.call((err, planCode) => {
|
|
||||||
expect(err).to.not.exist
|
|
||||||
expect(planCode).to.equal('v1_pro')
|
|
||||||
return done()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('when the plan_name from v1 is null', function () {
|
|
||||||
beforeEach(function () {
|
|
||||||
return (this.responseBody.plan_name = null)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('should produce a null plan-code without error', function (done) {
|
|
||||||
return this.call((err, planCode) => {
|
|
||||||
expect(err).to.not.exist
|
|
||||||
expect(planCode).to.equal(null)
|
|
||||||
return done()
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
describe('getGrandfatheredFeaturesForV1User', function () {
|
describe('getGrandfatheredFeaturesForV1User', function () {
|
||||||
describe('when the user ID is greater than the cutoff', function () {
|
describe('when the user ID is greater than the cutoff', function () {
|
||||||
it('should return an empty feature set', function (done) {
|
it('should return an empty feature set', function (done) {
|
||||||
|
|
Loading…
Reference in a new issue