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:
Jakob Ackermann
2022-03-24 15:40:40 +00:00
committed by Copybot
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 institutionFeatures =
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 featuresOverrides = await _getFeaturesOverrides(userId)
const featuresOverrides = await _getFeaturesOverrides(user)
logger.log(
{
userId,
@@ -114,10 +118,7 @@ async function _getGroupFeatureSets(userId) {
return (subs || []).map(_subscriptionToFeatures)
}
async function _getFeaturesOverrides(userId) {
const user = await UserGetter.promises.getUser(userId, {
featuresOverrides: 1,
})
async function _getFeaturesOverrides(user) {
if (!user || !user.featuresOverrides || user.featuresOverrides.length === 0) {
return {}
}
@@ -138,22 +139,9 @@ async function _getFeaturesOverrides(userId) {
return features
}
async function _getV1Features(userId) {
let planCode, v1Id
try {
;({ 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)
)
async function _getV1Features(user) {
const v1Id = user?.overleaf?.id
return V1SubscriptionManager.getGrandfatheredFeaturesForV1User(v1Id) || {}
}
function _subscriptionToFeatures(subscription) {
@@ -12,7 +12,6 @@
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
let V1SubscriptionManager
const logger = require('@overleaf/logger')
const UserGetter = require('../User/UserGetter')
const request = require('requestretry')
const settings = require('@overleaf/settings')
@@ -20,46 +19,6 @@ const { V1ConnectionError, NotFoundError } = require('../Errors/Errors')
const { promisifyAll } = require('../../util/promises')
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) {
if (callback == null) {
callback = function () {}
@@ -229,7 +188,4 @@ function __guard__(value, transform) {
module.exports.promises = promisifyAll(module.exports, {
without: ['getGrandfatheredFeaturesForV1User'],
multiResult: {
getPlanCodeFromV1: ['planCode', 'v1Id'],
},
})