|
@@ -318,38 +318,7 @@ async function updateSubscriptionFromRecurly(
|
|
|
requesterData
|
|
requesterData
|
|
|
) {
|
|
) {
|
|
|
if (recurlySubscription.state === 'expired') {
|
|
if (recurlySubscription.state === 'expired') {
|
|
|
- const hasManagedUsersFeature =
|
|
|
|
|
- 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
|
|
|
|
|
- if (subscription?.ssoConfig) {
|
|
|
|
|
- const ssoConfig = await SSOConfig.findOne({
|
|
|
|
|
- _id: subscription.ssoConfig._id || subscription.ssoConfig,
|
|
|
|
|
- })
|
|
|
|
|
- .lean()
|
|
|
|
|
- .exec()
|
|
|
|
|
- if (ssoConfig.enabled) {
|
|
|
|
|
- hasGroupSSOEnabled = true
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (hasGroupSSOEnabled) {
|
|
|
|
|
- logger.warn(
|
|
|
|
|
- { subscriptionId: subscription._id },
|
|
|
|
|
- 'expired subscription has groupSSO feature enabled, skipping deletion'
|
|
|
|
|
- )
|
|
|
|
|
- } else {
|
|
|
|
|
- await deleteSubscription(subscription, requesterData)
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ await handleExpiredSubscription(subscription, requesterData)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
const updatedPlanCode = recurlySubscription.plan.plan_code
|
|
const updatedPlanCode = recurlySubscription.plan.plan_code
|
|
@@ -450,6 +419,41 @@ async function _sendUserGroupPlanCodeUserProperty(userId) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+async function handleExpiredSubscription(subscription, requesterData) {
|
|
|
|
|
+ const hasManagedUsersFeature =
|
|
|
|
|
+ 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
|
|
|
|
|
+ if (subscription?.ssoConfig) {
|
|
|
|
|
+ const ssoConfig = await SSOConfig.findOne({
|
|
|
|
|
+ _id: subscription.ssoConfig._id || subscription.ssoConfig,
|
|
|
|
|
+ })
|
|
|
|
|
+ .lean()
|
|
|
|
|
+ .exec()
|
|
|
|
|
+ if (ssoConfig.enabled) {
|
|
|
|
|
+ hasGroupSSOEnabled = true
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (hasGroupSSOEnabled) {
|
|
|
|
|
+ logger.warn(
|
|
|
|
|
+ { subscriptionId: subscription._id },
|
|
|
|
|
+ 'expired subscription has groupSSO feature enabled, skipping deletion'
|
|
|
|
|
+ )
|
|
|
|
|
+ } else {
|
|
|
|
|
+ await deleteSubscription(subscription, requesterData)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
async function _sendSubscriptionEvent(userId, subscriptionId, event) {
|
|
async function _sendSubscriptionEvent(userId, subscriptionId, event) {
|
|
|
const subscription = await Subscription.findOne(
|
|
const subscription = await Subscription.findOne(
|
|
|
{ _id: subscriptionId },
|
|
{ _id: subscriptionId },
|
|
@@ -568,5 +572,6 @@ module.exports = {
|
|
|
setRestorePoint,
|
|
setRestorePoint,
|
|
|
setSubscriptionWasReverted,
|
|
setSubscriptionWasReverted,
|
|
|
voidRestorePoint,
|
|
voidRestorePoint,
|
|
|
|
|
+ handleExpiredSubscription,
|
|
|
},
|
|
},
|
|
|
}
|
|
}
|