From c08a3c6ad00d7445804b456356515a6edf906195 Mon Sep 17 00:00:00 2001 From: Dev Aggarwal Date: Tue, 20 Aug 2024 00:34:41 +0530 Subject: [PATCH] avoid deleting facebook integrations that get removed from facebook --- bots/models.py | 16 ++++++++-------- routers/facebook_api.py | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/bots/models.py b/bots/models.py index 3b7258e3b..122362307 100644 --- a/bots/models.py +++ b/bots/models.py @@ -421,7 +421,7 @@ def _parse_dt(dt) -> datetime.datetime | None: class BotIntegrationQuerySet(models.QuerySet): @transaction.atomic() - def reset_fb_pages_for_user( + def add_fb_pages_for_user( self, uid: str, fb_pages: list[dict] ) -> list["BotIntegration"]: saved = [] @@ -454,13 +454,13 @@ def reset_fb_pages_for_user( bi.name = bi.fb_page_name bi.save() saved.append(bi) - # delete pages that are no longer connected for this user - self.filter( - Q(platform=Platform.FACEBOOK) | Q(platform=Platform.INSTAGRAM), - billing_account_uid=uid, - ).exclude( - id__in=[bi.id for bi in saved], - ).delete() + # # delete pages that are no longer connected for this user + # self.filter( + # Q(platform=Platform.FACEBOOK) | Q(platform=Platform.INSTAGRAM), + # billing_account_uid=uid, + # ).exclude( + # id__in=[bi.id for bi in saved], + # ).delete() return saved diff --git a/routers/facebook_api.py b/routers/facebook_api.py index 6b8f0a6f5..5af52b9a4 100644 --- a/routers/facebook_api.py +++ b/routers/facebook_api.py @@ -154,7 +154,7 @@ def fb_connect_redirect(request: Request): ) map_parallel(_subscribe_to_page, fb_pages) - integrations = BotIntegration.objects.reset_fb_pages_for_user( + integrations = BotIntegration.objects.add_fb_pages_for_user( request.user.uid, fb_pages )