Skip to content

Commit

Permalink
unsubscribes deleted profile, and de-activates all plans
Browse files Browse the repository at this point in the history
  • Loading branch information
smirolo committed Oct 7, 2024
1 parent 543dcca commit 44fedb2
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions saas/api/organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,22 @@ def destroy(self, request, *args, **kwargs): #pylint:disable=unused-argument
# Removes all roles on the organization such that the organization
# is not picked up inadvertently.
get_role_model().objects.filter(organization=obj).delete()
# Two queries instead of one because there might be subscriptions
# that auto-renew with an ends_at date in the past (might be an
# error, but still better to auto-correct when we can).
Subscription.objects.filter(
organization=obj, ends_at__gt=at_time).update(ends_at=at_time)
Subscription.objects.filter(
organization=obj, auto_renew=True).update(auto_renew=False)

# If we are deleting a provider, freeze all its plans as well
# subscriptions to these plans.
obj.plans.subscriptions.filter(
ends_at__gt=at_time).update(ends_at=at_time)
obj.plans.subscriptions.filter(
auto_renew=True).update(auto_renew=False)
obj.plans.update(is_active=False)

obj.slug = slug
obj.email = email
obj.is_active = False
Expand Down

0 comments on commit 44fedb2

Please sign in to comment.