Revert "[web] Send email to support when skipping deleting pro group subscrip…" (#21780)

This reverts commit 8a4abe0742ab6a1c6b15bb17b5cc4863a11010b2.

GitOrigin-RevId: 2b91b8a127d195f4297fe99653fb69664b2a91a7
This commit is contained in:
Miguel Serrano 2024-11-11 12:16:55 +01:00 committed by Copybot
parent a6deee4961
commit 53d84efb3a
2 changed files with 20 additions and 126 deletions

View file

@ -11,8 +11,6 @@ const logger = require('@overleaf/logger')
const Features = require('../../infrastructure/Features') const Features = require('../../infrastructure/Features')
const UserAuditLogHandler = require('../User/UserAuditLogHandler') const UserAuditLogHandler = require('../User/UserAuditLogHandler')
const { SSOConfig } = require('../../models/SSOConfig') const { SSOConfig } = require('../../models/SSOConfig')
const Modules = require('../../infrastructure/Modules')
const Settings = require('@overleaf/settings')
/** /**
* Change the admin of the given subscription. * Change the admin of the given subscription.
@ -251,29 +249,6 @@ async function _deleteAndReplaceSubscriptionFromRecurly(
) )
} }
async function _notifySupportSubscriptionDeletionSkipped(
subscription,
recurlySubscription,
hasGroupSSOEnabled
) {
const adminUrl = `${Settings.adminUrl + '/admin/user/' + subscription.admin_id}`
const groupUrl = `${Settings.adminUrl + '/admin/group/' + subscription._id}`
let message = `\n**Recurly account:** <a href="${recurlySubscription?.account?.url}">${recurlySubscription?.account?.url}</a>`
message += `\n**Group admin:** <a href="${adminUrl}">${adminUrl}</a>`
message += `\n**Group:** <a href="${groupUrl}">${groupUrl}</a>`
message += `\n**Managed users enabled:** ${subscription?.managedUsersEnabled}`
message += `\n**SSO enabled:** ${hasGroupSSOEnabled}`
const data = {
subject: 'Skipped deleting pro group subscription',
inbox: 'support',
tags: 'Group subscription',
message,
}
await Modules.promises.hooks.fire('sendSupportRequest', data)
}
async function updateSubscriptionFromRecurly( async function updateSubscriptionFromRecurly(
recurlySubscription, recurlySubscription,
subscription, subscription,
@ -283,6 +258,14 @@ async function updateSubscriptionFromRecurly(
const hasManagedUsersFeature = const hasManagedUsersFeature =
Features.hasFeature('saas') && subscription?.managedUsersEnabled Features.hasFeature('saas') && subscription?.managedUsersEnabled
// If a payment lapses and if the group is managed or has group SSO, as a temporary measure we need to
// make sure that the group continues as-is and no destructive actions are taken.
if (hasManagedUsersFeature) {
logger.warn(
{ subscriptionId: subscription._id },
'expired subscription has managedUsers feature enabled, skipping deletion'
)
} else {
let hasGroupSSOEnabled = false let hasGroupSSOEnabled = false
if (subscription?.ssoConfig) { if (subscription?.ssoConfig) {
const ssoConfig = await SSOConfig.findOne({ const ssoConfig = await SSOConfig.findOne({
@ -295,46 +278,15 @@ async function updateSubscriptionFromRecurly(
} }
} }
// If a payment lapses and if the group is managed or has group SSO, as a temporary measure we need to if (hasGroupSSOEnabled) {
// make sure that the group continues as-is and no destructive actions are taken.
if (hasManagedUsersFeature) {
logger.warn(
{ subscriptionId: subscription._id },
'expired subscription has managedUsers feature enabled, skipping deletion'
)
try {
await _notifySupportSubscriptionDeletionSkipped(
subscription,
recurlySubscription,
hasGroupSSOEnabled
)
} catch (e) {
logger.warn(
{ subscriptionId: subscription._id },
'unable to send notification to support that subscription deletion was skipped'
)
}
} else if (hasGroupSSOEnabled) {
logger.warn( logger.warn(
{ subscriptionId: subscription._id }, { subscriptionId: subscription._id },
'expired subscription has groupSSO feature enabled, skipping deletion' 'expired subscription has groupSSO feature enabled, skipping deletion'
) )
try {
await _notifySupportSubscriptionDeletionSkipped(
subscription,
recurlySubscription,
hasGroupSSOEnabled
)
} catch (e) {
logger.warn(
{ subscriptionId: subscription._id },
'unable to send notification to support that subscription deletion was skipped'
)
}
} else { } else {
await deleteSubscription(subscription, requesterData) await deleteSubscription(subscription, requesterData)
} }
}
return return
} }
const updatedPlanCode = recurlySubscription.plan.plan_code const updatedPlanCode = recurlySubscription.plan.plan_code

View file

@ -13,9 +13,6 @@ describe('SubscriptionUpdater', function () {
plan: { plan: {
plan_code: this.recurlyPlan.planCode, plan_code: this.recurlyPlan.planCode,
}, },
account: {
url: 'test_url',
},
} }
this.adminUser = { _id: (this.adminuser_id = '5208dd34438843e2db000007') } this.adminUser = { _id: (this.adminuser_id = '5208dd34438843e2db000007') }
@ -29,7 +26,6 @@ describe('SubscriptionUpdater', function () {
save: sinon.stub().resolves(), save: sinon.stub().resolves(),
planCode: 'student_or_something', planCode: 'student_or_something',
recurlySubscription_id: 'abc123def456fab789', recurlySubscription_id: 'abc123def456fab789',
managedUsersEnabled: false,
} }
this.user_id = this.adminuser_id this.user_id = this.adminuser_id
@ -124,7 +120,6 @@ describe('SubscriptionUpdater', function () {
}, },
}, },
], ],
adminUrl: 'test_admin_url',
} }
this.UserFeaturesUpdater = { this.UserFeaturesUpdater = {
@ -182,13 +177,6 @@ describe('SubscriptionUpdater', function () {
'../Analytics/AnalyticsManager': this.AnalyticsManager, '../Analytics/AnalyticsManager': this.AnalyticsManager,
'../../infrastructure/Features': this.Features, '../../infrastructure/Features': this.Features,
'../User/UserAuditLogHandler': this.UserAuditLogHandler, '../User/UserAuditLogHandler': this.UserAuditLogHandler,
'../../infrastructure/Modules': (this.Modules = {
promises: {
hooks: {
fire: sinon.stub().resolves(),
},
},
}),
}, },
}) })
}) })
@ -328,52 +316,6 @@ describe('SubscriptionUpdater', function () {
{} {}
) )
this.SubscriptionModel.deleteOne.should.not.have.been.called this.SubscriptionModel.deleteOne.should.not.have.been.called
const adminUrl = `${this.Settings.adminUrl + '/admin/user/' + this.subscription.admin_id}`
const groupUrl = `${this.Settings.adminUrl + '/admin/group/' + this.subscription._id}`
let message = `\n**Recurly account:** <a href="${this.recurlySubscription?.account?.url}">${this.recurlySubscription.account?.url}</a>`
message += `\n**Group admin:** <a href="${adminUrl}">${adminUrl}</a>`
message += `\n**Group:** <a href="${groupUrl}">${groupUrl}</a>`
message += `\n**Managed users enabled:** false`
message += `\n**SSO enabled:** true`
expect(this.Modules.promises.hooks.fire).to.have.been.calledOnce
expect(this.Modules.promises.hooks.fire).to.have.been.calledWith(
'sendSupportRequest',
{
subject: 'Skipped deleting pro group subscription',
inbox: 'support',
tags: 'Group subscription',
message,
}
)
})
it('should not remove the subscription when expired if it has managed users is enabled', async function () {
this.Features.hasFeature.withArgs('saas').returns(true)
this.subscription.managedUsersEnabled = true
this.recurlySubscription.state = 'expired'
await this.SubscriptionUpdater.promises.updateSubscriptionFromRecurly(
this.recurlySubscription,
this.subscription,
{}
)
this.SubscriptionModel.deleteOne.should.not.have.been.called
const adminUrl = `${this.Settings.adminUrl + '/admin/user/' + this.subscription.admin_id}`
const groupUrl = `${this.Settings.adminUrl + '/admin/group/' + this.subscription._id}`
let message = `\n**Recurly account:** <a href="${this.recurlySubscription?.account?.url}">${this.recurlySubscription.account?.url}</a>`
message += `\n**Group admin:** <a href="${adminUrl}">${adminUrl}</a>`
message += `\n**Group:** <a href="${groupUrl}">${groupUrl}</a>`
message += `\n**Managed users enabled:** true`
message += `\n**SSO enabled:** false`
expect(this.Modules.promises.hooks.fire).to.have.been.calledWith(
'sendSupportRequest',
{
subject: 'Skipped deleting pro group subscription',
inbox: 'support',
tags: 'Group subscription',
message,
}
)
}) })
it('should update all the users features', async function () { it('should update all the users features', async function () {