mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-26 12:21:36 +03:00
Required no active subscriptions when modifying products
refs https://github.com/TryGhost/Team/issues/748 This ensures that a member cannot be attached to a product directly if they have active subscriptions.
This commit is contained in:
parent
9079a9b9e0
commit
5ad0c624e3
@ -129,28 +129,7 @@ module.exports = class MemberRepository {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (existingActiveSubscriptions.length) {
|
if (existingActiveSubscriptions.length) {
|
||||||
const memberWithSubscriptions = await this._Member.findOne({
|
throw new Error('Cannot edit products for a Member who has a subscription');
|
||||||
id: options.id
|
|
||||||
}, {
|
|
||||||
...sharedOptions,
|
|
||||||
withRelated: ['stripeSubscriptions', 'stripeSubscriptions.stripePrice', 'stripeSubscriptions.stripePrice.stripeProduct']
|
|
||||||
});
|
|
||||||
|
|
||||||
const productsDueToSubscriptions = memberWithSubscriptions.related('stripeSubscriptions').reduce((products, subscription) => {
|
|
||||||
if (!this.isActiveSubscriptionStatus(subscription.get('status'))) {
|
|
||||||
return products;
|
|
||||||
}
|
|
||||||
|
|
||||||
return products.concat(subscription.related('stripePrice').related('stripeProduct').get('product_id'));
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const productsToModify = productsToAdd.concat(productsToRemove);
|
|
||||||
|
|
||||||
const attemptingToModifyASubscriptionsProduct = productsDueToSubscriptions.some((id) => productsToModify.includes(id));
|
|
||||||
|
|
||||||
if (attemptingToModifyASubscriptionsProduct) {
|
|
||||||
throw new Error('Cannot edit products for which a Member has a subscription');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user