mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #11432 from overleaf/revert-11154-tm-lg-subscription-recurly-cache-name
Revert "Change property name for recurly status cache to recurlyStatus" GitOrigin-RevId: 6870e421516fd705343f3e8651d8637f791063df
This commit is contained in:
parent
0b6c69dc55
commit
f6ffae02a9
4 changed files with 7 additions and 61 deletions
|
@ -249,7 +249,7 @@ async function updateSubscriptionFromRecurly(
|
||||||
|
|
||||||
subscription.recurlySubscription_id = recurlySubscription.uuid
|
subscription.recurlySubscription_id = recurlySubscription.uuid
|
||||||
subscription.planCode = updatedPlanCode
|
subscription.planCode = updatedPlanCode
|
||||||
subscription.recurlyStatus = {
|
subscription.recurly = {
|
||||||
state: recurlySubscription.state,
|
state: recurlySubscription.state,
|
||||||
trialStartedAt: recurlySubscription.trial_started_at,
|
trialStartedAt: recurlySubscription.trial_started_at,
|
||||||
trialEndsAt: recurlySubscription.trial_ends_at,
|
trialEndsAt: recurlySubscription.trial_ends_at,
|
||||||
|
|
|
@ -193,7 +193,6 @@ function buildUsersSubscriptionViewModel(user, callback) {
|
||||||
// Subscription DB object contains a recurly property, used to cache trial info
|
// Subscription DB object contains a recurly property, used to cache trial info
|
||||||
// on the project-list. However, this can cause the wrong template to render,
|
// on the project-list. However, this can cause the wrong template to render,
|
||||||
// if we do not have any subscription data from Recurly (recurlySubscription)
|
// if we do not have any subscription data from Recurly (recurlySubscription)
|
||||||
// TODO: Delete this workaround once recurly cache property name migration rolled out.
|
|
||||||
if (personalSubscription) {
|
if (personalSubscription) {
|
||||||
delete personalSubscription.recurly
|
delete personalSubscription.recurly
|
||||||
}
|
}
|
||||||
|
@ -355,7 +354,7 @@ async function getBestSubscription(user) {
|
||||||
individualSubscription &&
|
individualSubscription &&
|
||||||
!individualSubscription.customAccount &&
|
!individualSubscription.customAccount &&
|
||||||
individualSubscription.recurlySubscription_id &&
|
individualSubscription.recurlySubscription_id &&
|
||||||
!individualSubscription.recurlyStatus?.state
|
!individualSubscription.recurly?.state
|
||||||
) {
|
) {
|
||||||
const recurlySubscription = await RecurlyWrapper.promises.getSubscription(
|
const recurlySubscription = await RecurlyWrapper.promises.getSubscription(
|
||||||
individualSubscription.recurlySubscription_id,
|
individualSubscription.recurlySubscription_id,
|
||||||
|
@ -481,7 +480,7 @@ function _isPlanEqualOrBetter(planA, planB) {
|
||||||
|
|
||||||
function _getRemainingTrialDays(subscription) {
|
function _getRemainingTrialDays(subscription) {
|
||||||
const now = new Date()
|
const now = new Date()
|
||||||
const trialEndDate = subscription.recurlyStatus?.trialEndsAt
|
const trialEndDate = subscription.recurly?.trialEndsAt
|
||||||
return trialEndDate && trialEndDate > now
|
return trialEndDate && trialEndDate > now
|
||||||
? Math.ceil(
|
? Math.ceil(
|
||||||
(trialEndDate.getTime() - now.getTime()) / (24 * 60 * 60 * 1000)
|
(trialEndDate.getTime() - now.getTime()) / (24 * 60 * 60 * 1000)
|
||||||
|
|
|
@ -1,53 +0,0 @@
|
||||||
/* eslint-disable no-unused-vars */
|
|
||||||
|
|
||||||
const Helpers = require('./lib/helpers')
|
|
||||||
|
|
||||||
exports.tags = ['saas']
|
|
||||||
|
|
||||||
exports.migrate = async client => {
|
|
||||||
const { db } = client
|
|
||||||
// 'recurly' -> 'recurlyStatus'
|
|
||||||
await db.subscriptions.updateMany(
|
|
||||||
{
|
|
||||||
$and: [
|
|
||||||
{ recurlyStatus: { $exists: false } },
|
|
||||||
{ recurly: { $exists: true } },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{ $rename: { recurly: 'recurlyStatus' } }
|
|
||||||
)
|
|
||||||
// some records may have already recached the recurly status, discard old cache
|
|
||||||
await db.subscriptions.updateMany(
|
|
||||||
{
|
|
||||||
$and: [
|
|
||||||
{ recurlyStatus: { $exists: true } },
|
|
||||||
{ recurly: { $exists: true } },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{ $unset: { recurly: 1 } }
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.rollback = async client => {
|
|
||||||
const { db } = client
|
|
||||||
// 'recurlyStatus' -> 'recurly'
|
|
||||||
await db.subscriptions.updateMany(
|
|
||||||
{
|
|
||||||
$and: [
|
|
||||||
{ recurly: { $exists: false } },
|
|
||||||
{ recurlyStatus: { $exists: true } },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{ $rename: { recurlyStatus: 'recurly' } }
|
|
||||||
)
|
|
||||||
// some records may have already recached the recurly status, discard old cache
|
|
||||||
await db.subscriptions.updateMany(
|
|
||||||
{
|
|
||||||
$and: [
|
|
||||||
{ recurlyStatus: { $exists: true } },
|
|
||||||
{ recurly: { $exists: true } },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{ $unset: { recurlyStatus: 1 } }
|
|
||||||
)
|
|
||||||
}
|
|
|
@ -22,7 +22,7 @@ describe('SubscriptionViewModelBuilder', function () {
|
||||||
planCode: this.planCode,
|
planCode: this.planCode,
|
||||||
plan: this.plan,
|
plan: this.plan,
|
||||||
recurlySubscription_id: this.recurlySubscription_id,
|
recurlySubscription_id: this.recurlySubscription_id,
|
||||||
recurlyStatus: {
|
recurly: {
|
||||||
state: 'active',
|
state: 'active',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ describe('SubscriptionViewModelBuilder', function () {
|
||||||
this.groupSubscription = {
|
this.groupSubscription = {
|
||||||
planCode: this.groupPlanCode,
|
planCode: this.groupPlanCode,
|
||||||
plan: this.plan,
|
plan: this.plan,
|
||||||
recurlyStatus: {
|
recurly: {
|
||||||
state: 'active',
|
state: 'active',
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -168,7 +168,7 @@ describe('SubscriptionViewModelBuilder', function () {
|
||||||
it('should return a individual subscription with remaining free trial days', async function () {
|
it('should return a individual subscription with remaining free trial days', async function () {
|
||||||
const threeDaysLater = new Date()
|
const threeDaysLater = new Date()
|
||||||
threeDaysLater.setDate(threeDaysLater.getDate() + 3)
|
threeDaysLater.setDate(threeDaysLater.getDate() + 3)
|
||||||
this.individualSubscription.recurlyStatus.trialEndsAt = threeDaysLater
|
this.individualSubscription.recurly.trialEndsAt = threeDaysLater
|
||||||
this.SubscriptionLocator.promises.getUsersSubscription
|
this.SubscriptionLocator.promises.getUsersSubscription
|
||||||
.withArgs(this.user)
|
.withArgs(this.user)
|
||||||
.resolves(this.individualSubscription)
|
.resolves(this.individualSubscription)
|
||||||
|
@ -189,7 +189,7 @@ describe('SubscriptionViewModelBuilder', function () {
|
||||||
it('should return a individual subscription with free trial on last day', async function () {
|
it('should return a individual subscription with free trial on last day', async function () {
|
||||||
const threeHoursLater = new Date()
|
const threeHoursLater = new Date()
|
||||||
threeHoursLater.setTime(threeHoursLater.getTime() + 3 * 60 * 60 * 1000)
|
threeHoursLater.setTime(threeHoursLater.getTime() + 3 * 60 * 60 * 1000)
|
||||||
this.individualSubscription.recurlyStatus.trialEndsAt = threeHoursLater
|
this.individualSubscription.recurly.trialEndsAt = threeHoursLater
|
||||||
this.SubscriptionLocator.promises.getUsersSubscription
|
this.SubscriptionLocator.promises.getUsersSubscription
|
||||||
.withArgs(this.user)
|
.withArgs(this.user)
|
||||||
.resolves(this.individualSubscription)
|
.resolves(this.individualSubscription)
|
||||||
|
|
Loading…
Reference in a new issue